FFMPEG: Creating video using drawtext along with w

2019-02-15 23:35发布

问题:

I'm working to create a video from text with drawtext filter. Output video i can see the text is overflowing instead of coming in new line.

Is there any way i can archive word wrapping and also set the internal padding to video?

Below is the snippet I'm using to generate video from text

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

Output looks like this

回答1:

Use the subtitles filter instead.

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

You can generate ASS or SRT subtitles manually or via Aegisub.

Example 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 files are more complicated structurally, but they allow more formatting options. Otherwise, you can use the force_style option in the subtitles filter. Search this site for several examples.



标签: video ffmpeg