FFmpeg - 如何缩放视频然后应用水印? [英] FFmpeg - How to scale a video then apply a watermark?

查看:19
本文介绍了FFmpeg - 如何缩放视频然后应用水印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缩放视频,使其始终为 512 宽,其中高度与原始视频成比例变化.缩放后,我想对视频应用水印/叠加层,因此视频会缩放但水印不会.

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:

规模

-vf "scale=512:-1"

水印

-vf "movie=watermark.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]"

他们自己成功地工作.

然而,当试图将两者结合起来时,我遇到了一些麻烦.

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.

我试过了:

-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.

打开过滤器时出错!

然后将 , 更改为 ;导致:

Then changing the , to a ; resulted in:

简单的filtergraph 'scale=512:-1;电影=水印.png【水印】;[在][水印]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2 [out]' 没有一个输入和一个输出.

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.

打开过滤器时出错!

我想我需要对过滤器链做更多的事情,但我正在努力弄清楚.

I presume I need to do something more with filterchains but Im struggling to figure it out.

大家有什么想法吗?

非常感谢.

推荐答案

感谢@DiJuMx 和@LordNeckbeard,你们让我更接近我的解决方案.我还没有尝试过 filter_complex 选项,但它看起来确实更简单.

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]"

请注意,我替换了比例中的 -1,因为这有可能在缩放时导致视频高度的像素数量不均匀,从而导致编码错误.

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.

这篇关于FFmpeg - 如何缩放视频然后应用水印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆