FFmpeg Drawtext: How to Display Frame Number

This article explains how to use the FFmpeg drawtext filter to overlay the real-time frame number onto a video. You will learn the exact command syntax required, see practical examples, and understand how to customize the appearance and positioning of the frame counter on your output video.

To display the current frame number on a video, you must use FFmpeg’s drawtext video filter and leverage the evaluate-able variable n (which represents the frame number, starting at 0).

The Basic Command

Here is the fundamental command to overlay the frame number in the top-left corner of your video:

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

Parameter Breakdown

Adding a Text Label

If you want to display a label like “Frame: 124” instead of just a raw number, you must escape the colon character (:) with a backslash because colons are used to separate filter arguments in FFmpeg.

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

Improving Readability with a Background Box

If the background of your video makes the white text hard to read, you can add a semi-transparent black background box behind the frame counter:

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