FFMPEG : Add a fixed size image on a video, regardless of the video width amp; height (resolution)(FFMPEG :在视频上添加固定大小的图像,而不管视频宽度amp;高度(分辨率))
问题描述
这是我通过 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 :在视频上添加固定大小的图像,而不管视频宽度&高度(分辨率)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FFMPEG :在视频上添加固定大小的图像,而不管视频宽度&高度(分辨率)
基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
