Categories: Development

Creating a shifting watermark overlay with FFmpeg

Create a dynamic, shifting watermark that moves around a video using FFmpeg.

This is similar to what TikTok uses and helps prevent the watermark from easily being blurred out or overlaid.

The moving aspect is adapted from here.

The command

The full command with the breakdown below:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1]colorchannelmixer=aa=0.8,scale=iw*0.8:-1[a];[0][a]overlay=x='if(lt(mod(t\,16)\,8)\,W-w-W*10/100\,W*10/100)':y='if(lt(mod(t+4\,16)\,8)\,H-h-H*5/100\,H*5/100)'" -c:v libx264 -an output.mp4

Breaking it down

Call FFmpeg and define the input video and the watermark image to use:

ffmpeg -i input.mp4 -i watermark.png

Set the watermark image opacity to 0.8 and scale down 80%

-filter_complex "[1]colorchannelmixer=aa=0.8,scale=iw*0.8:-1[a];

The watermark movement, every 2 seconds move corner to corner (anti-clockwise):

[0][a]overlay=x='if(lt(mod(t\,8)\,4)\,W-w-W*10/100\,W*10/100)':y='if(lt(mod(t+2\,8)\,4)\,H-h-H*10/100\,H*10/100)'"

This is a position change of 2 seconds because it has 8 seconds for a full rotation cycle (corner to corner). 4 corners means 8/4 = 2. So 2 seconds per position change.

This is the example for 6 second changes:

overlay=x='if(lt(mod(t\,24)\,12)\,W-w-W*10/100\,W*10/100)':y='if(lt(mod(t+6\,24)\,12)\,H-h-H*5/100\,H*5/100)'

24/4 = 6 and 12/2 = 6.

This part defines the position from the edge on the width and height axis which is the width * 10 / 100 or height * 5 / 100.

W-w-W*10/100\,W*10/100 .... H-h-H*5/100\,H*5/100

Finally saving the watermarked video:

-c:v libx264 -an output.mp4

output.mp4 will have the dynamic watermark.

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