我有可用的代码,可以通过图像创建带有淡入淡出效果的视频幻灯片:
ffmpeg -video_size 1280x720 \
-loop 1 -t 2.5 -i ok/image-1.jpg \
-loop 1 -t 2.5 -i ok/image-2.jpg \
-loop 1 -t 2.5 -i ok/image-3.jpg \
-loop 1 -t 2.5 -i ok/image-4.jpg \
-loop 1 -t 2.5 -i ok/image-5.jpg \
-filter_complex \
"[0:v]fade=t=in:st=0:d=1,fade=t=out:st=4:d=1[pre]; \
[0:v]drawtext=enable='between(t,0,5)':fontfile=/Library/Fonts/Arial.ttf:text='FIRST TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th[top0]; \
[1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v]; \
[1:v]drawtext='between(t,5,10)':fontfile=/Library/Fonts/Arial.ttf:text='SECOND TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th[top1]; \
[2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v]; \
[2:v]drawtext='between(t,10,15)':fontfile=/Library/Fonts/Arial.ttf:text='THIRD TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th[top2]; \
[3:v][2:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b3v]; \
[3:v]drawtext='between(t,15,20)':fontfile=/Library/Fonts/Arial.ttf:text='FOURTH TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th[top3]; \
[4:v][3:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b4v]; \
[4:v]drawtext='between(t,20,25)':fontfile=/Library/Fonts/Arial.ttf:text='FIFTH TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th[top4]; \
[pre][top0][0:v][b1v][top1][1:v][b2v][top2][2:v][b3v][top3][3:v][b4v][top4][4:v]concat=n=15:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4
我如何才能让“第一段文字”与第一张幻灯片“ok/image-1.jpg”一起显示整整 5 秒?现在它只显示了大约 2 秒然后就隐藏了。此外,是否可以为第一张幻灯片“ok/image-1.jpg”显示多个文本?
enable='between(t,0,5)
5 秒内无法正常工作。
答案1
尝试
ffmpeg \
-loop 1 -t 6 -i ok/image-1.jpg \
-loop 1 -t 5 -i ok/image-2.jpg \
-loop 1 -t 5 -i ok/image-3.jpg \
-loop 1 -t 5 -i ok/image-4.jpg \
-loop 1 -t 5 -i ok/image-5.jpg \
-filter_complex \
"[0:v]drawtext=fontfile=/Library/Fonts/Arial.ttf:text='FIRST TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,drawtext=fontfile=/Library/Fonts/Arial.ttf:text='AFTER FIRST TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th+100,split[pre][pbv0];[pbv0]fifo[bv0]; \
[pre]fade=t=in:st=0:d=1[v0]; \
[1:v]drawtext=fontfile=/Library/Fonts/Arial.ttf:text='SECOND TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,split=3[pbv1a][pbv1b][v1];[pbv1a]fifo[bv1a];[pbv1b]fifo[bv1b]; \
[2:v]drawtext=fontfile=/Library/Fonts/Arial.ttf:text='THIRD TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,split=3[pbv2a][pbv2b][v2];[pbv2a]fifo[bv2a];[pbv2b]fifo[bv2b];\
[3:v]drawtext=fontfile=/Library/Fonts/Arial.ttf:text='FOURTH TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,split=3[pbv3a][pbv3b][v3];[pbv3a]fifo[bv3a];[pbv3b]fifo[bv3b]; \
[4:v]drawtext=fontfile=/Library/Fonts/Arial.ttf:text='FIFTH TEXT':fontcolor=white:fontsize=24:x=(w-tw)/2:y=(h/PHI)+th,split[pbv4][v4];[pbv4]fifo[bv4]; \
[bv1a][bv0]blend=all_expr='A*T/0.5+B*(0.5-T)/0.5',trim=0:0.5[01v]; \
[bv2a][bv1b]blend=all_expr='A*T/0.5+B*(0.5-T)/0.5',trim=0:0.5[12v]; \
[bv3a][bv2b]blend=all_expr='A*T/0.5+B*(0.5-T)/0.5',trim=0:0.5[23v]; \
[bv4][bv3b]blend=all_expr='A*T/0.5+B*(0.5-T)/0.5',trim=0:0.5[34v]; \
[v0][01v][v1][12v][v2][23v][v3][34v][v4]concat=n=9,format=yuv420p[v]" -map "[v]" out.mp4
我假设您希望文本在淡入淡出期间显示。因此,我重新调整了您的命令。应首先应用所有绘制文本,然后混合这些输出。