FFmpeg scripting for beginners: How to easily add text and logo watermarks to videos

How to easily add text and logo watermarks to videos using FFMPEG

If you’re a video content producer, online educator, or business owner, then you know how crucial it is to protect your visual content online. Videos are rapidly being copied and shared illegally, and this is where video watermarking is heavily needed. But most graphics software is either costly or slow.

Common tools: A brief review of video watermarking software

When it comes to video watermarking, users have numerous options. On the one hand, there are traditional video editing software with a graphical user interface (GUI) like Premiere Pro, MetaLogic Bulk Video Watermark, or Camtasia, which make the watermarking process somewhat intuitive and easy. These tools are suitable for single projects and users who are not interested in a coding environment. But if you need to process hundreds of videos at once, the software in question will be time-consuming and costly.

For users looking for faster, more concentrated solutions, there are a number of dedicated video watermark software specifically designed for applying bulk and scheduled watermarks, which usually offer higher speed compared to general video editing software.

But still, it is not even close to FFmpeg in terms of flexibility, freedom, and automation power.

This is where FFmpeg — an open-source and super powerful command-line tool — comes in. FFmpeg can seem complicated and horrific to many new users, but the truth is that by learning a few key commands, you can have the fastest, most flexible, and most efficient way to add text watermarks and logos to video.

In this comprehensive article, we will introduce you step by step to FFmpeg scripting for beginners. You will learn how to use two key filters, meaning “drawtext” and “overlay”, to add your brand to any video like a pro.

Why is FFmpeg the best choice for professional watermarking?

Although there are many video watermarking software with graphical user interfaces (GUI) in the market that make the job easier, none of them can compete with FFmpeg in terms of flexibility.

  1. High speed and efficiency: FFmpeg is designed for bulk and fast video processing on both server and personal systems.
  2. Precise pixel-level control: Using precise coordinates, you can place your watermark in any corner, center, or anywhere you want in the video.
  3. Free and open-source: This tool is completely free, and you don’t need to pay hefty subscription fees.
  4. Dynamic watermark: You can create animated or scheduled watermarks, which simple software is not able to do.

Installation and preparation

Before you start scripting with FFmpeg, make sure you have installed it on your system.

  • Go to the FFmpeg official website and download and install the appropriate version for your operating system (Windows, Mac, Linux).
  • Installation test: Open a terminal (or Command Prompt) and type the following command:

$ ffmpeg -version

You are good to go if the FFmpeg version information is displayed.

Part I: Adding a Text Watermark (drawtext filter)

We use the drawtext filter to add a text watermark such as a brand name, copyright, or website address. This filter allows you to add any text with precise settings to video frames.

Basic text watermark command

The following command is the simplest way to add a text watermark to a video:

ffmpeg -i input.mp4 -vf "drawtext=text='© MyBrand':fontsize=30:[email protected]:x=50:y=H-th-50" output_text_wm.mp4

Explanation of key components:

ComponentFunctionExample / Importance
-i input.mp4Input video fileThe video you want to watermark.
-vfEnabling video filterStands for “video filter graph” and is used for simple filters.
text=’© MyBrand’Watermark contentThe text that is displayed.
fontsize=30Font sizeText and watermark size
[email protected]Color and opacityYellow is the text color and @0.6 indicates 60% Opacity (from 0.0 to 1.0).
x=50:y=H-th-50PositionWatermark position in the video frame.

Text watermark placement

One of the main advantages of FFmpeg is the ability to define precise positions using automatic variables:

Custom positionFFmpeg expression (x:y)
Bottom-right corner (common)x=W-tw-20:y=H-th-20
Top-left cornerx=20:y=20
Center of the framex=(W-tw)/2:y=(H-th)/2

Explanation: W and H are the width and height of the entire video, and tw and th are respectively the width and height of the text watermark. These formulas ensure that your watermark is placed in the right place at any video size.

Part II: Adding logo watermark (overlay filter)

To use an image (like a company logo) as a watermark, we use the overlay filter. This filter combines two input streams: video and logo.

Basic logo watermark command

We need two inputs to add a logo to a video with FFmpeg:

overlay=W-w-10:H-h-10ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=W-w-10:H-h-10" output_logo_wm.mp4

Explanation of key components:

ComponentFunctionKey point
-i logo.pngWatermark image fileIt is recommended to use a PNG file with a transparent background.
-filter_complexEnabling an advanced filterUsed for filters that have more than one input (such as incorporating video and logo).
overlay=W-w-10:H-h-10Combination and positioningPlaces the logo in the bottom-right corner. (w and h are the logo width and height)

Adjusting logo opacity

For a more professional result, make sure to adjust the logo watermark opacity. This is done using the colorchannelmixer filter combined with overlay:

ffmpeg -i input.mp4 -i logo.png -filter_complex "[1:v] format=rgba,colorchannelmixer=aa=0.3 [wm]; [0:v][wm] overlay=10:10" output_transparent_logo.mp4
  • [1:v] Selects the second video stream (logo).
  • colorchannelmixer=aa=0.3 sets the alpha channel (opacity) to 30%. (lower value = higher transparency)

Part III: Combining text and logo watermarks simultaneously

To achieve the highest level of professionalism, it is usually necessary to combine text watermarks and logos simultaneously. Here we use a complex filter graph, where the output of one filter becomes the input of the next filter.

Final and comprehensive command (logo + text)

Assume you want the logo in the top-left corner and the copyright text in the bottom-right corner:

ffmpeg -i input.mp4 -i logo.png -filter_complex\
"[0:v][1:v] overlay=10:10 [logo_done];\
[logo_done] drawtext=text='MyBrand.com':fontsize=25:[email protected]:x=W-tw-20:y=H-th-20"\
output_combined_wm.mp4

Filtering process breakdown:

  1. Inputs: Main video ([0:v]) and logo ([1:v])
  2. First step (overlay): The logo is placed on the video and the output will be labeled as [logo_done].
  3. Step two (drawtext): Copyright text is added to the output watermarked with the logo ([logo done]).

This powerful structure allows you to execute an infinite combination of FFmpeg filters.


Part IV: Pro tips for increasing content efficiency and security

Using FFmpeg allows you to go beyond simple watermarks:

a) Determining the start and end time of the watermark (Time-Based)

If you don’t want the watermark to appear on the entire video, you can use the enable parameter in the drawtext or overlay filter.

Display the text watermark only between seconds 10 and 30.

ffmpeg -i input.mp4 -vf “drawtext=text=’Limited Offer’:enable=’between(t,10,30)’:fontsize=40:fontcolor=red:x=50:y=50” output_timed_wm.mp4

b) Content protection and the importance of watermarking

Video watermarking is a key layer of protection. Although watermark removal software is constantly thriving, a professional semi-transparent watermark that appears intermittently in key parts of a video makes the removal process very expensive and difficult.

Although FFmpeg is a great technical tool, many content creators are looking for faster solutions with a simple UI. If you are not fast at scripting, it is recommended to go for video watermarking software with a graphical environment that simplifies the manual watermarking process and does not require command-line knowledge.

c) Video output optimization

Upon applying the watermark, use the codec settings to ensure proper quality and file size:

  • Compatible codec: Use the libx264 codec, which is the industry standard for high-quality, reasonably-sized videos.
  • Quality (CRF): Set the -crf (Constant Rate Factor) parameter between 18 and 28. Lower values ​​(e.g,. -crf 18) have better quality and larger volume.

-c:v libx264 -crf 23 -preset medium

Conclusion:

You are now familiar with the basics of FFmpeg scripting for beginners and can use the drawtext and overlay filters to add text and logo watermarks to videos with pixel-level precision. FFmpeg is a one-time installation tool that opens the door to automation and unparalleled control over your video content.

Remember, the best way to learn FFmpeg is through practice and experimentation. Take the codes above and tweak the position and opacity variables to add your brand watermark to your videos professionally.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top