Categories: Development

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.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago