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

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

3 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

3 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

3 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

3 years ago