Can FFmpeg concat and drawtext at the same time?

I can successfully use FFmpeg's concat filter and the drawtext filter in separate commands.

But this requires two encoding runs.

Is it possible to get both of these filters to work in a chain, so that only one encoding takes place? How?

I have three video clips I am trying to concatenate and I want one common text to appear over the resulting video.


Solution 1:

Try this:

ffmpeg -i inputfile1 -i inputfile2 -y \
-filter_complex '[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a];\
[v]drawtext=fontsize=72:fontcolor=White:fontfile=/usr/share/fonts/truetype/DejaVuSans.ttf:text=Text Line To Render:x=(w)/2:y=(h)/2[o]'\
-map '[o]' -map '[a]' ...other encoding parameters... outputfile

Note that [v] and [a] are just labels – you could very well use [p] and [q] and that would be fine too. Only stream 0 goes to first label and stream 1 to second label. So I'm assuming stream 0 is video.

You have to ensure that the streams in inputfile1 and inputfile2 have the same order. Then we pass the output of video stream as input to the drawtext filter by saying [v]drawtext=....

The output of this is now labeled as [o] at the end of the drawtext parameters. By saying -map [o], we use the output from drawtext to pass on forward to your other encoding parameters.

The font path I'm using is from OpenSUSE. Yours could be different.