(FFMPEG)在使用透视图覆盖视频之前,使区域透明 [英] (FFMPEG) Make areas transparent before overlaying a vid with perspective

查看:605
本文介绍了(FFMPEG)在使用透视图覆盖视频之前,使区域透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



到目前为止,我可以让视频很小,添加视角它并重叠到另一个视频。但是在应用透视过滤器之后,多余的区域不会变得透明,它们只是伸出像素。



透视过滤器没有太多的文档,但是到目前为止因为我可以发现,没有办法将额外的像素设置为透明。



所以我猜测不好需要应用某种alpha面具,区域?



这是我用于透视图的命令:

  ffmpeg -i /synced_folder/testvid.mp4 -vf perspective = 0:0:W:H / 4:0:H:W:3 * H / 4:0:1:0 /synced_folder/output5.mp4 

不要以为重要,但是我在带有centOS的VM上运行ffmpeg。



这是一个SS,结果如何: a>

这需要非常规的方法。透视过滤器旨在纠正记录过程中的某些类型的失真,而不是用于DVE型叠加。边缘上的像素将被扩展以填充画布。



这里的诀窍是为视频添加透明填充,然后添加透视图。扩展的像素将是透明像素,它们在重叠时变得不可见。

  ffmpeg -i base.mp4 -i overlay .mp4 
filter_complex[1] pad = iw + 4:ih + 4:2:2:black @ 0,perspective = 0:0:W:H / 4:0:H:W:3 * H / 4:0:1:0 [p];
[0] [p] overlay = -2:-2output.mp4

我填充了2个像素的边框,因为通常的像素格式是4:2:0。边框颜色为黑色,但α为 0



严格来说,透视值应更正为占了边界,但这是一个小的变化。覆盖也被偏移以将可见视频与预期目的地对齐。


I'm trying to add perspective to a small video then overlay it on top of an other.

So far I can make the video small, add perspective to it and overlay it to an other video. but after applying the perspective filter, the excess areas don't turn transparent, they just stretch out the pixels.

the perspective filter doesn't have much documentation but as far as i could find out there was no way of setting the extra pixels to transparent.

So I'm guessing ill need to apply some kind of alpha mask, to the desired area?

this is the command I'm using for perspective:

ffmpeg -i /synced_folder/testvid.mp4 -vf perspective=0:0:W:H/4:0:H:W:3*H/4:0:1:0 /synced_folder/output5.mp4

Don't think it matters but I'm running ffmpeg on a VM with centOS.

This is a SS of how the result looks like:

解决方案

This requires an unconventional approach. The perspective filter was meant to correct certain types of distortion during recording, and not for DVE-type overlays. The pixels at the edges will be extended to fill the canvas.

The trick here is to add a transparent padding to the video, and then add perspective. The pixels which get extended will be the transparent pixels, which become invisible upon overlay.

ffmpeg -i base.mp4 -i overlay.mp4
filter_complex" [1]pad=iw+4:ih+4:2:2:black@0,perspective=0:0:W:H/4:0:H:W:3*H/4:0:1:0[p];
                [0][p]overlay=-2:-2"    output.mp4

I have padded with a border of 2 pixels, chosen because the usual pixel format is 4:2:0. The border color is black, but with alpha of 0.

Strictly speaking, the perspective values should be corrected to account for the border, but it's a small change. The overlay is also offset to align the visible video to the intended destination.

这篇关于(FFMPEG)在使用透视图覆盖视频之前,使区域透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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