How to Scroll Text Horizontally in FFmpeg

This article provides a quick, step-by-step guide on how to use FFmpeg’s drawtext video filter to create a horizontal scrolling text effect, commonly known as a marquee or ticker. You will learn the specific mathematical formulas and FFmpeg commands required to scroll text from right to left across your video, adjust the scrolling speed, and make the text loop infinitely.

To scroll text horizontally in FFmpeg, you must dynamically change the horizontal coordinate (x) of the drawtext filter over time. This is achieved by using the t variable (current time in seconds) alongside the video width (w) and the text width (tw).

The Basic Command for Right-to-Left Scrolling

The most common scrolling effect is a marquee that moves from the right edge of the screen to the left. The following command demonstrates how to apply this effect:

ffmpeg -i input.mp4 -vf "drawtext=text='This is your scrolling marquee text':x='w-t*150':y='h-th-20':fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -codec:a copy output.mp4

Explaining the Variables and Logic

How to Loop the Scrolling Text Infinitely

If your video is long, the text in the command above will eventually scroll off the screen and never return. To make the text loop continuously back to the right side of the screen once it has fully exited on the left, use the modulo (mod) function:

ffmpeg -i input.mp4 -vf "drawtext=text='This text loops infinitely':x='w-mod(t*150\,w+tw)':y='h-th-20':fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -codec:a copy output.mp4

Breakdown of the Loop Formula:

By adjusting the multiplier (e.g., changing 150 to 200 for faster speed, or 100 for slower speed), you can easily customize the pace of your scrolling text.