Overlay frame number on video with FFmpeg

Watermarking a video with the current frame number using FFmpeg. This method involves using the video filter option with the frame_num.

For this, I had Arial.ttf sitting in the root folder alongside FFmpeg and the fontfile path simply states this.

The FFmpeg command is:

ffmpeg -i input.mp4 -vf "drawtext=fontfile=Arial.ttf:text='%{frame_num}':start_number=1:x=(w-tw)/2:y=h-(2*lh):fontcolor=white:fontsize=50:" -c:a copy output.mp4

This will start at frame number 1 and overlay the frame number onto the video at position x=(w-tw)/2:y=h-(2*lh) which is centred left to right and about an eighth up from the bottom of the screen.

The video and audio settings are copied, there is no compressing.

Remember to ensure that the font file exists at the path.

This command depending on the length of your video could take some time as it cannot be executed with a re-encode.