FFMPEG:使用drawtext创建视频以及自动换行和填充

时间:2018-05-31 15:51:49

标签: video ffmpeg

我正在尝试使用drawtext过滤器从文本创建视频。输出视频我可以看到文本溢出而不是进入新行。

有什么办法可以归档自动换行并将内部填充设置为视频吗?

以下是我用于从文字

生成视频的片段
ffmpeg.exe -f lavfi -i color=c=white:s=640x480:d=5.396 -vf "[in] drawtext=fontfile=font.ttf:fontsize=20:fontcolor=black:x=0+0*print(tw):y=0+0*print(th):text='this is new whiteboard te':enable='between(t,6.634,6.818)',drawtext=fontfile=font.ttf:fontsize=20:fontcolor=black:x=0+0*print(tw):y=0+0*print(th):text='this is new whiteboard testing':enable='between(t,0.0,2.032)',drawtext=fontfile=font.ttf:fontsize=20:fontcolor=black:x=0+0*print(tw):y=0+0*print(th):text='this is new whiteboard testing no padding and the text is overflowing from the video frame check this  need to acheve word wrapping':enable='between(t,2.032,5.396)'"[out] -c:v libx264 -t 30 -crf 30 ../output.mp4

输出看起来像这样 enter image description here

1 个答案:

答案 0 :(得分:3)

改为使用subtitles filter

enter image description here

ffmpeg -y -f lavfi -i color=c=white:s=640x480:d=5 -vf "subtitles=subs.srt" output.mp4

您可以手动或通过Aegisub生成ASS或SRT字幕。

示例SRT:

1
00:00:00,000 --> 00:00:05,000
This is new whiteboard testing no padding and the text is overflowing from the video frame check this  need to acheve word wrapping.

ASS文件在结构上更复杂,但它们允许更多格式化选项。否则,您可以使用字幕过滤器中的force_style选项。在这个网站上搜索几个例子。