How to Add a Watermark to Video Using FFmpeg
Learn how to add a watermark to any video using FFmpeg — completely free and no third-party tools required. Whether you're building a video platform or editing tool, this tutorial covers everything you need to implement a professional watermarking feature.
What you'll learn:
• The basic FFmpeg overlay command
• How to scale your watermark relative to the video using scale2ref
• How to position the watermark in any corner (top-left, top-right, bottom-left, bottom-right)
• How to add padding so the watermark isn't flush against the edge
• How to control watermark transparency with the colorchannelmixer filter
FFmpeg runs on Linux, macOS, and Windows — making it the perfect cross-platform solution for developers adding watermarking functionality to their projects.
🔔 Subscribe for more practical developer tool tutorials 💬 Have a tutorial request? Drop it in the comments!
Video Transcription
Hey everyone, welcome back. If you're a developer building a video editing tool or video platform, you should consider adding a watermark feature to it. It protects content from piracy, reinforces brand identity, and makes videos look professionally produced. Today, we're gonna do that with one of the most powerful free tools out there, which is FFmpeg.
It's completely free, runs on Linux, Mac OS, and Windows, and gives you complete control over how you process your video. We'll cover everything you need to know, from basic overlay command to scaling, positioning, adding padding, and controlling transparency. Let's start with the basics. The way FFmpeg adds a watermark is technically by overlaying an image on top of your
[00:01:00] video using a filter called overlay.
Before we do anything fancy, let's get the basic command working first. I've got two files here, input.mp4, which is my source video, and watermark.png, which is the logo I want to overlay. For the basic command, we pass both files as inputs using -i, then apply the overlay filter via -filter complex. The result is exported as output.mp4
So here's what's happened. The watermark is placed at the top left corner by default, which is position zero zero, because we didn't specify any coordinates. But the watermark image is
[00:02:00] actually larger than the video itself, so it's covering everything. The overlay filter doesn't auto-scale the image, so we need to handle that ourselves.
Before you can properly position a watermark, you need to make sure that it's the right size relative to the video. FFmpeg has a filter called scale to ref that does exactly this. It scales your watermark using the video's own dimensions as a reference. Let's see how. Here's the scale to ref filter value we'll be adding.
IH times zero point two scales the watermark to twenty percent of the video's height. OH times MDAR then calculates the width to preserve the watermark's original aspect ratio. Together, they produce a properly scaled watermark. Now, combine scale to ref and overlay in a
[00:03:00] single command. Bracket one, bracket zero at the start means take input one, the watermark, and input zero, the video, and pass them to scale to ref.
The outputs are labeled bracket logo and bracket video. And then overlay places the scaled logo on top of the video. Let's run the command. And here's the result. Now, the watermark is a small proportionate overlay in the top left corner. This is the base we'll build on for all the positioning options coming up next.
Now that the watermark is properly scaled, let's place it in an exact location. FFmpeg's overlay filter accepts X and Y coordinates, and you can use built-in variables to calculate positions dynamically
[00:04:00] based on the video and watermark dimensions. Here are the key variables you can use inside the overlay filter.
For the center, we divide the difference between the video width and watermark width by two for the X coordinate, and do the same with the height for Y. That gives us the exact midpoint of the video on both axes. For the top right, X is set to main width minus overlay width. That pushes the watermark all the way to the right edge, and Y is simply zero, which keeps it pinned to the top.
For the bottom left, X is to keep on the left, and Y is set to main height minus overlay height. That pushes the watermark down to the bottom edge of the video. And for the bottom
[00:05:00] right, we combine both. X is main width minus overlay width to push it to the right, and Y is main height minus overlay height to push it to the bottom.
Simply by changing the coordinate expressions, you can place the watermark in four different positions. However, placing the watermark right at the edge of the video looks a bit too tight. In practice, you want some breathing room between the watermark and the edge of the frame. To add paddings, simply add or subtract a pixel value from the X and Y coordinates to create an offset.
For example, setting both to 10 gives us 10 pixels of padding from the top left. Here's the result. For the other corners, adjust accordingly. Here's a quick
[00:06:00] reference. If you want to adjust the padding size, replace ten with whatever padding size works for your design. The last technique we'll cover is transparency.
This is what you often see on stock video platforms, a semi-transparent watermark sitting right over the content, making it hard to use without purchasing. This can be done with FFmpeg's color channel mixer filter. Let's see how. For the best result, use a watermark PNG that already has a transparent background.
Then we apply this filter before scaling and overlaying. AA equals zero point three sets the opacity to thirty percent. Lower values mean more transparent. And here's the full command. See the filter chain here. First, we apply color
[00:07:00] channel mixer to adjust the opacity, then scale to ref to size it to match the video.
And finally, overlay to place it at the center. Let's run it. And here's the result. If you want to adjust the transparency, simply adjust the AA value. And that's everything from our FFmpeg watermarking guide. Now, you know how to overlay a watermark, scale it to fit any video, position it in any corner, and control its transparency.
These are all you need if you're adding watermarking functionality to a video platform or editing tool. If this was helpful, hit like and subscribe. We cover practical developer tools regularly. Got any tutorials that you want to see next? Drop it in the comments. I'll see you in the next video.
https://youtu.be/PTMFH729sEw?si=HsBto3s34nSfsFKX
Need to edit a video now?
Bannerbear has a suite of free online video tools that run FFmpeg right in your browser, no install, no upload, no watermark. Trim, resize, convert, subtitle, watermark and merge your videos in a few clicks.
Browse the Free Video Tools