Im trying to scale a video so that it is always 512 wide where the height changes in proportion to the original video. Once scaled, I then want to apply a watermark/overlay to the video, therefore the video will scale but the watermark wont.
I am able to achieve each of these separately using the following filters:
Scale
-vf "scale=512:-1"
Watermark
-vf "movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
They work successfully on their own.
However when trying to combine the two, Im having a bit of trouble.
Having both as parameters of course does not work as one will override the other.
Ive tried:
-vf "scale=512:-1,movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
my thinking was that the scale would be applied first then the watermark but all I get is an error
Too many inputs specified for the "movie" filter.
Error opening filters!
Then changing the , to a ; resulted in:
Simple filtergraph 'scale=512:-1; movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]' does not have exactly one input and output.
Error opening filters!
I presume I need to do something more with filterchains but Im struggling to figure it out.
Any ideas anyone?
Many thanks in advance.
FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform.
FFmpeg offers the overlay filter as a way to overlay images (or even other videos) onto video streams. To centre overlay/watermark on a video, use this command: ffmpeg -i inputvideo.avi -i watermarklogo.png -filter_complex \ "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.flv.
You can use the -filter_complex
option with the scale and overlay filters:
ffmpeg -i input.mp4 -i logo.png -filter_complex "[0:v]scale=512:-1[bg];[bg][1:v]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" output
-c:a copy
if you want to stream copy (re-mux) the original audio instead of re-encoding it. This is useful if your input and output container formats are the same.overlay=10:10
overlay=W-w-10:10
overlay=W-w-10:H-h-10
overlay=H-h-10:10
Thank you to both @DiJuMx and @LordNeckbeard, you both got me closer to my solution. Ive not tried the filter_complex option yet but it certainly looks simpler.
The solution I found to work is:
-vf "movie=watermark.png [watermark]; [in]scale=512:trunc(ow/a/2)*2 [scale]; [scale][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
Note that Ive replaced the -1 in the scale as that had the potential to cause an uneven number of pixels in the height of the video when scaling which would then cause encoding errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With