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

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

问题描述

我试图缩放视频,使其总是512宽,其中高度与原始视频成比例的变化。
一旦缩放,我想要对视频应用水印/叠加层,因此视频将缩放,但水印不会。



我能够实现每个这些分别使用以下过滤器:



比例

  -vfscale = 512:-1

水印

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

自己。



然而,当尝试组合这两个时,我有点麻烦。



参数当然不起作用,因为它将覆盖另一个。



Ive尝试:

 code> -vfscale = 512:-1,movie = watermark.png [watermark]; [in] [watermark] overlay =(main_w-overlay_w)/ 2:(main_h-overlay_h)/ 2 [ 

我的想法是他的比例将首先被应用于水印,但是我所得到的只是一个错误


为电影过滤器指定的输入太多。 / p>

打开过滤器错误


然后更改,导致:


简单过滤器'scale = 512:-1;
movie = watermark.png
[水印];



打开过滤器时出错!


我想我需要做更多的一些过滤器,但是我努力



任何想法任何人?



非常感谢提前。

解决方案

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



我发现工作的解决方案是:

  -vfmovie = watermark.png [watermark]; [in] scale = 512:trunc(ow / a / 2)* 2 [scale]; [scale] [watermark] =(main_w-overlay_w)/ 2:(main_h-overlay_h)/ 2 [out]

Ive在尺度上替换了-1,因为在缩放时可能会导致视频高度不均匀的像素数量,从而导致编码错误。


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.

解决方案

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.

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

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