[英]FFmpeg - How to scale a video then apply a watermark?
Im trying to scale a video so that it is always 512 wide where the height changes in proportion to the original video. 我试图缩放视频,使其总是512宽,其高度与原始视频成比例变化。 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;
简单的filtergraph'scale = 512:-1; movie=watermark.png [watermark];
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.
[in] [watermark] overlay =(main_w-overlay_w)/ 2:(main_h-overlay_h)/ 2 [out]'没有一个输入和输出。
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. 提前谢谢了。
You can use the -filter_complex
option with the scale and overlay filters: 您可以将
-filter_complex
选项与比例和叠加过滤器一起使用:
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. -c:a copy
。 This is useful if your input and output container formats are the same. overlay=10:10
overlay=10:10
10:10 overlay=Ww-10:10
overlay=Ww-10:10
overlay=Ww-10:Hh-10
overlay=Ww-10:Hh-10
overlay=Hh-10:10
overlay=Hh-10:10
Thank you to both @DiJuMx and @LordNeckbeard, you both got me closer to my solution. 感谢@DiJuMx和@LordNeckbeard,你们都让我更接近我的解决方案。 Ive not tried the filter_complex option yet but it certainly looks simpler.
我还没有尝试过filter_complex选项,但它看起来肯定更简单。
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. 请注意,我已经在比例尺中替换了-1,因为在缩放时可能会导致视频高度不均匀的像素数,从而导致编码错误。
From what I understand, this might work: 根据我的理解,这可能有效:
-vf "movie=watermark.png [watermark]; [in] scale=512:-1,[watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"
You apply the scale filter to the input "[in]". 您将缩放过滤器应用于输入“[in]”。
Unfortunately I don't have much experience with the filters on ffmpeg so I can't help further. 不幸的是我对ffmpeg上的过滤器没有多少经验,所以我无法继续帮助。 Sorry
抱歉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.