Learn
FFmpeg
Recipes
Watermark Video

How to Watermark a Video in FFmpeg

Watermarking is an essential tool for protecting and branding your videos. It helps to prevent unauthorized use and strengthens your brand's presence in the video. In this guide, we will delve deep into how to watermark a video in FFmpeg using the complex filters command, discuss some alternatives, and touch on the placement options.

Understanding FFmpeg and Watermarks

FFmpeg is a powerful open-source software that can handle a wide range of multimedia operations, including adding watermarks to videos. A watermark is typically an image or text that is overlaid onto a video. It can be your logo, brand name, or any other element that represents your brand.

Adding a Watermark using the Complex Filters Command

The complex filters command in FFmpeg provides a complete solution for watermarking your videos. Here's a basic command to add a watermark to a video:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:10" output.mp4

In this command, input.mp4 is the source video file, watermark.png is the watermark image, and output.mp4 is the output video file. The overlay=10:10 option positions the watermark 10 pixels from the left and 10 pixels from the top of the video.

Understanding Placement Options

The placement of the watermark is crucial as it can affect the visibility of your video content. FFmpeg provides several options to control the placement of the watermark. You can use the overlay filter with different parameters to position the watermark.

Here are some common placement options:

  1. Top-left corner: overlay=10:10
  2. Top-right corner: overlay=main_w-overlay_w-10:10
  3. Bottom-left corner: overlay=10:main_h-overlay_h-10
  4. Bottom-right corner: overlay=main_w-overlay_w-10:main_h-overlay_h-10
  5. Center: overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2

In these commands, main_w and main_h are the width and height of the video, and overlay_w and overlay_h are the width and height of the watermark.

Advanced Watermarking Techniques

FFmpeg also allows for more advanced watermarking techniques, such as animating your watermark or adding padding to your video before overlaying the watermark.

Animating Your Watermark

You can animate your watermark to move across the screen over time. Here's an example command:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay='if(gte(t,1), -w+(t-1)*200, NAN)':(main_h-overlay_h)/2" output.mp4

In this command, the watermark starts moving from the left side of the screen after 1 second (t,1) at a speed of 200 pixels per second (-w+(t-1)*200).

Adding Padding

You can add padding to your video before overlaying the watermark to avoid covering the existing video content. Here's an example command:

ffmpeg -i input.mp4 -i watermark.png -filter_complex "pad=height=ih+40:color=#71cbf4,overlay=(main_w-overlay_w)/2:main_h-overlay_h" output.mp4

In this command, the pad filter adds 40 pixels of padding to the height of the video (height=ih+40) with a color of light blue (color=#71cbf4).

FFmpeg's flexibility and powerful features make it an excellent tool for watermarking your videos. With a bit of practice, you can master these commands and effectively protect and brand your video content.