FFMPEG: how to add watermark to video?
Solution 1:
The correct way to do this with recent ffmpeg is to use the overlay filter. The following command will place watermark.png
on top of input.mp4
, with the upper-left corner of the watermark fifteen pixels to the right and ten pixels down from the upper-left corner of the main video:
ffmpeg -i input.mp4 -i watermark.png -filter_complex \
'[0:v][1:v]overlay=15:10[outv]' -map [outv] -map [0:a] \
-c:a copy -c:v libx264 -crf 22 -preset veryfast output.mp4
Obviously, change 15 or 10 to whatever values you want.
There are also a few constants you may find useful, if you're putting watermarks on multiple videos with separate resolutions:
- W and H are the width and height of the main video (
input.mp4
) - w and h are the width and height of the overlay video (
watermark.png
)
These can come in handy many times. For example, to place the watermark over the centre of the video, you could use:
'[0:v][1:v]overlay=(W-w)/2:(H-h)/2[outv]'
Similarly, to centre the watermark over the upper-left sixth of the video:
'[0:v][1:v]overlay=(W-w)/6:(H-h)/6[outv]'
For the lower-left sixth of the video:
'[0:v][1:v]overlay=(W-w)/6:(H-h)/(6/5)[outv]'
You can pretty much do whatever you need to.
See the overlay filter documentation for more information.