How to Burn Frame Numbers onto Video with FFmpeg

This article provides a straightforward guide on how to overlay sequential frame numbers onto every frame of a video using the FFmpeg command-line tool. You will learn the exact command syntax, how the drawtext filter works, and how to customize the position, size, and background of the printed numbers.

To print frame numbers onto a video, you must use FFmpeg’s drawtext video filter. The key to displaying the frame number is using the %{n} evaluation variable inside the text parameter.

Here is the basic command to overlay frame numbers:

ffmpeg -i input.mp4 -vf "drawtext=text='%{n}':x=10:y=10:fontsize=24:fontcolor=white:box=1:boxcolor=black@0.5" -c:a copy output.mp4

Command Breakdown

By default, FFmpeg will attempt to use a system font. However, to avoid errors or default-font fallback issues, it is best to define a specific font file using the fontfile parameter:

On Windows:

ffmpeg -i input.mp4 -vf "drawtext=fontfile='C\:/Windows/Fonts/arial.ttf':text='%{n}':x=10:y=10:fontsize=24:fontcolor=white" -c:a copy output.mp4

On macOS:

ffmpeg -i input.mp4 -vf "drawtext=fontfile='/Library/Fonts/Arial.ttf':text='%{n}':x=10:y=10:fontsize=24:fontcolor=white" -c:a copy output.mp4

On Linux:

ffmpeg -i input.mp4 -vf "drawtext=fontfile='/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf':text='%{n}':x=10:y=10:fontsize=24:fontcolor=white" -c:a copy output.mp4

Advanced Modifications

Start the Frame Count from 1 (Instead of 0)

FFmpeg starts counting frames at 0 by default. To start the visible counter at 1, use an expression:

text='%{expr\:n+1}'

Change the Position of the Text

You can dynamically position the text using variables like w (video width), h (video height), tw (text width), and th (text height).