Two common methods how to include some text to the video output is to use subtitles or the overlay technique from the previous chapter. The most advanced option with many possibilities is to use a drawtext filter
FFmpeg Video filter: drawtext
For example, to draw a Welcome message (located in the top-left corner by default) with an Arial font in a black color on a white background, we can use the command (characters are typed on 1 line)
ffmpeg -i input -vf drawtext=fontfile=arial.ttf:text=Welcome output
FFmpeg Dynamic text
The t (time) variable representing the time in seconds enables to change x and y values according to the current time
Horizontal text movement
To move the text horizontally across the video frame, we include the t variable to the expression for the x parameter, for instance to move provided text every second by n pixels in a right-to-left direction, we use an expression x=w-tn. To change the movement to the left-to-right direction, x=w+tn expression is used. For example, to show “Dynamic RTL text” string moving at the top, we use the command
ffmpeg -f lavfi -i color=c=#abcdef -vf drawtext=^ “fontfile=arial.ttf:text=’Dynamic RTL text’:x=w-t*50:^ fontcolor=darkorange:fontsize=30” output
More common use is to scroll a line of text near the bottom, where the text is located in a text file that contains only one very long line. The next example uses the textfile parameter with a value info.txt
ffmpeg -f lavfi -i color=c=orange -vf drawtext=”fontfile=arial.ttf:^ textfile=info.txt:x=w-t*50:y=h-th:fontcolor=blue:fontsize=30″ output