使用ffmpeg更新视频上的PNG覆盖 [英] Update PNG overlay on video with ffmpeg

查看:591
本文介绍了使用ffmpeg更新视频上的PNG覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作视频的RTMP流,并在其上放置一些图形数据。我有一个命令来创建我需要的输出。唯一的问题是,尽管在渲染过程中PNG图像正在更新磁盘上,但在输出视频中,覆盖层总是保持不变。我希望ffmpeg每次更改(或一分钟左右)从磁盘获取一个PNG图像,并将其用作叠加层。
这是可能的吗?

I'm trying to make an RTMP stream of a video and put some graphical data on it. I have a command which creates the output I need. The only problem is that despite of the fact the PNG image is being updated on disk during the render process, in output video the overlay stays always the same. I would like ffmpeg to take a PNG image from disk every time it has been changed (or once a minute or so) and use it as an overlay. Is that possible?

这是我用来呈现输出的命令:

Here is the command I use to render the output:

ffmpeg \
-re -y \
-f lavfi \
-i "movie=filename=video/videobg.mp4:loop=0, setpts=N/(FRAME_RATE*TB)" \
-loop 1 \
-i images/forecast.png \
-filter_complex "[1:v]format=argb,geq=r='r(X,Y)':a='0.9*alpha(X,Y)'[overlay]; [0:v][overlay]overlay" \
-i data/musicbg.mp3 \
-ac 1 \
-ar 44100 \
-b:a 128k \
-vcodec libx264 \
-pix_fmt yuv420p \
-r 30 \
-g 60 \
output.mp4


推荐答案

嗯,我终于弄清楚如何做出我想要的。希望,这可能对别人有用。

Well, I have finally figured out how to make what I want. Hope, this could be useful for someone else.

我唯一需要做的是添加一个 -f image2 图像输入选项。该命令与上面发布的命令有所不同,因为我更改了输入源的顺序,但实际上它是一样的。
这是解决方案:

The only thing I had to do is to add a -f image2 option for the image input. The command differs a bit from the one I posted above, because I changed the order of input sources, but in fact it is the same. Here is the solution:

ffmpeg \
-re -y \
-loop 1 \
-f image2 \
-i images/forecast.png \
-f lavfi \
-i "movie=filename=video/videobg.mp4:loop=0, setpts=N/(FRAME_RATE*TB)" \
-filter_complex "[0:v]format=argb,geq=r='r(X,Y)':a='0.9*alpha(X,Y)'[overlay]; [1:v][overlay]overlay" \
-i data/musicbg.mp3 \
-ac 1 \
-ar 44100 \
-b:a 128k \
-vcodec libx264 \
-pix_fmt yuv420p \
-r 30 \
-g 60 \
output.mp4

这篇关于使用ffmpeg更新视频上的PNG覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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