如何使用ffmpeg按时间向视频添加文本

Tha*_*Dao 4 ffmpeg

我用命令创建我的幻灯片:

"ffmpeg" -f concat -safe 0 -i /path/to/text.txt -i /path/to/audio.mp3 -vsync vfr -pix_fmt yuv420p /path/to/output.mp4
Run Code Online (Sandbox Code Playgroud)

text.txt 的内容

file '/path/to/img1.jpg'
duration 6
file '/path/to/img2.jpg'
duration 6
file '/path/to/img3.jpg'
duration 6
file '/path/to/img4.jpg'
duration 6
file '/path/to/img5.jpg'
duration 6
file '/path/to/img6.jpg'
duration 6
Run Code Online (Sandbox Code Playgroud)

该视频已完美创建。现在我想为显示的每个图像添加标题。例子:

  • img1.jpg 显示,显示标题 Title 1
  • img2.jpg 显示,显示标题 Title 2
  • img3.jpg 显示,显示标题 Title 3

我搜索了很多,但得到了任何解决方案。任何人都可以帮助我。我被卡住了

Gya*_*yan 5

您需要添加菊花链式绘图文本过滤器。

-vf "drawtext=text='Title1':enable='between(t,0,6)',
     drawtext=text='Title2':enable='between(t,6,12)',
     drawtext=text='Title3':enable='between(t,12,18)'"
Run Code Online (Sandbox Code Playgroud)

请查阅drawtext的文档以查看所有选项。您需要指定字体文件、字体颜色、字体大小和 x,y。