FFMPEG:在视频上添加固定大小的图像,不管视频宽度&高度(分辨率) [英] FFMPEG : Add a fixed size image on a video, regardless of the video width & height (resolution)

查看:529
本文介绍了FFMPEG:在视频上添加固定大小的图像,不管视频宽度&高度(分辨率)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,可以通过PHP运行视频:

  exec('ffmpeg -i input mp4 -i logo.png -filter_complex 
[0:v] [1:v] overlay = 10:10-pix_fmt yuv420p -c:a copy output.mp4');

它的效果很好,但问题是,图像缩小或缩小,视频分辨率。例如,在以下图像中,徽标宽度为 50px ,但视频分辨率不同:





而这一个





如何防止图像缩小/缩小?






更新



感谢



这一个





有可能改进此解决方案吗?

解决方案

您可以使用scale2ref过滤器。

  ffmpeg -i input .mp4 -i logo.png -filter_complex 
[1:v] [0:v] scale2ref =(W / H)* ih / 8 / sar:ih / 8 [wm] [base]; [base ] [wm] overlay = 10:10
-pix_fmt yuv420p -c:a copy output.mp4

这将把标志的高度调整到视频高度的1/8。



您必须用图像的值替换 W / H ,例如如果PNG为320x270,则应为 scale2ref =(320/270)* ih / 8:ih / 8


This is my code that adds an image to videos, running via PHP:

exec('ffmpeg -i input.mp4 -i logo.png -filter_complex 
"[0:v][1:v] overlay=10:10"  -pix_fmt yuv420p -c:a copy output.mp4');

It works well but the problem is, the image is scaled down or up, up on the video resolution. For example in the following images the logo width is 50px but videos resolution are different:

and this one

How can I prevent the image from scaling down/up ?


Update

Thanks to Mulvya, he proposed these codes

ffmpeg -i input.mp4 -i logo.png -filter_complex 
"[1:v][0:v]scale2ref=(W/H)*ih/8:ih/8[wm][base];[base][wm]overlay=10:10"
-pix_fmt yuv420p -c:a copy output.mp4

and

ffmpeg -i input.mp4 -i logo.png -filter_complex 
"[1:v][0:v]scale2ref=(W/H)*ih/8:ih/8[wm][base];[wm]setsar=1[wmsar];
[base][wmsar]overlay=10:10"
-pix_fmt yuv420p -c:a copy output.mp4

that works very well, but it doesn't keep the logo aspect ratio. I tried this code on two videos with different resolution and this is the result

and this one

Is it possible to improve this solution?

解决方案

You can use the scale2ref filter.

ffmpeg -i input.mp4 -i logo.png -filter_complex 
"[1:v][0:v]scale2ref=(W/H)*ih/8/sar:ih/8[wm][base];[base][wm]overlay=10:10"
-pix_fmt yuv420p -c:a copy output.mp4

This will resize the logo's height to 1/8th of the height of the video.

You have to replace W/H with the values for the image e.g. if the PNG is 320x270, then it should be scale2ref=(320/270)*ih/8:ih/8

这篇关于FFMPEG:在视频上添加固定大小的图像,不管视频宽度&高度(分辨率)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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