Specializing in Windows applications, website services, and automation solutions to enhance your business

December 19, 2024

FFmpeg: Add Watermark To Video

December 19, 2024

Watermarking is essential for protecting your videos and boosting your brand identity. Whether it is a logo, text, or a unique animation, watermarks help safeguard your content while adding a professional touch. FFmpeg makes this process simple but flexible enough for advanced customizations. In this chapter, you will learn how to add watermarks to your videos, with clear examples and advanced techniques to make your videos stand out.

    Adding a Watermark with FFmpeg

    With FFmpeg, you can apply both image and text watermarks effortlessly. Here’s how:

    Adding a Text Watermark

    If you prefer text, FFmpeg allows you to overlay clean, professional-looking text:

    ffmpeg -i input.mp4 -vf "drawtext=text='YourBrand':fontcolor=white@0.5:fontsize=40:x=80:y=80" output.mp4
    • Replace input.mp4 with the name of the input video file.
    • text='YourBrand': Replace "YourBrand" with the text of your choice.
    • fontcolor: Adjust the text color (e.g. white, black, red).
    • @0.5 adjusts the opacity to 50%, giving it a semi-transparent look.
    • fontsize: Customize the size to fit your video.
    • x and y: Define the position of the text.
      • x=0:y=0 places it in the top-left corner.
      • x=(W-tw):y=(H-th) positions it in the bottom-right corner.
      • x=(W-tw)/2:y=(H-th)/2 puts it in the center of the video
    • Replace output.mp4 with the name of the desired output file.
    To run the code, place it in a .bat file, such as watermarking.bat. Place watermarking.bat, the input video file, and ffmpeg.exe in the same folder. Then double-click watermarking.bat.

    Adding an Image Watermark

    An image watermark, such as a logo, ensures your content is always recognizable. The following command overlays your logo onto the video:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x:y" output.mp4
    • Replace input.mp4 and logo.png with your video file and logo image
    • aa=0.5 adjusts the opacity to 50%, giving it a semi-transparent look.
    • overlay=x:y: Defines the position of the logo. For example:
      • 0:0 places it in the top-left corner.
      • (W-w):(H-h) positions it in the bottom-right corner
      • (W-w)/2:(H-h)/2 positions it in the center of the video.

    This method ensures your logo is embedded cleanly without interfering with the video’s core content.

    Dynamic Positioning Watermark

    Dynamic watermarks in FFmpeg are a powerful way to make your branding stand out by introducing motion. Instead of placing a static logo on your video, you can use the overlay=x: y filter to adjust the watermark’s position based on time. You can create engaging effects that evolve throughout the video by utilizing functions that vary with t (time).

    For instance, you can make your watermark bounce around the screen with smooth motion using:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x='120+sin(2*PI*t)*200':y='80+cos(2*PI*t)*50'" output.mp4

    This creates a lively animation where the logo moves in an elliptical path, giving your video a professional and dynamic look.

    You can alternate the position of your watermark every few seconds:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x='if(gte(mod(t,5),2.5),60,W-overlay_w-60)':y=70" output.mp4

    This effect makes the watermark "flop" between two locations on the screen.

    For an upward motion that follows a diagonal path, try:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x='mod(t*50, W-overlay_w)':y='H-overlay_h-mod(t*50, H-overlay_h)'" output.mp4

    If you prefer randomness, use this to scatter the watermark unpredictably across the screen:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x='random(mod(t\,3))*(W-overlay_w)':y='random(mod(t\,3))*(H-overlay_h)'" output.mp4

    For smooth sliding motion across the screen, this command moves the watermark horizontally:

    ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[wm];[0:v][wm]overlay=x='mod(t*100, W+overlay_w)-overlay_w':y=70" output.mp4

    These effects not only enhance the visual appeal of your videos but also make it harder for others to crop or remove your branding. Dynamic watermarks are a creative solution to keep your content secure and professional.

    Want to See the Results?

    Are you curious how these commands can transform your video branding? Watch side-by-side comparisons of plain footage versus videos with advanced watermarking. These techniques highlight the flexibility of FFmpeg and show how even subtle tweaks can elevate your content.

    Welcome to our video showcasing creative watermarking techniques using FFmpeg. These tricks will elevate your branding while keeping it professional. Let’s dive right in!