Frame Number Overlay With FFmpeg


I need to overlay the frame number to each frame of a video file using ffmpeg for windows.

I succeeded in overlaying a timecode stamp with the drawtext filter using this code:

ffmpeg -i -vcodec r210 -vf "drawtext=fontfile=Arial.ttf: timecode='01\:00\:00\:00': r=25: x=(w-tw)/2: y=h-(2*lh): fontcolor=white: box=1: boxcolor=0x00000099" -y

However, I need a frame number overlay and not a timecode one. Any help would be appreciated.

asked on Stack Overflow Mar 12, 2013 by Kobi Versano • edited Mar 12, 2013 by llogan

1 Answer


You can use the drawtext filter with the n or frame_num function:

enter image description here
Looping 5 fps example

Example command:

ffmpeg -i input -vf "drawtext=fontfile=Arial.ttf: text='%{frame_num}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=black: fontsize=20: box=1: boxcolor=white: boxborderw=5" -c:a copy output
  • You may have to provide the full path to the font file, such as fontfile=/usr/share/fonts/TTF/Vera.ttf.
  • n/frame_num starts at 0, but you can make the frame count start from 1 with the start_number option as shown in the example.

You could add additional text if desired, but be aware that you have to escape some special characters:

text='Frame\: %{frame_num}'

enter image description here

See the drawtext filter documentation for more info.

answered on Stack Overflow Mar 12, 2013 by llogan • edited Oct 30, 2018 by llogan

User contributions licensed under CC BY-SA 3.0