Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update PNG overlay on video with ffmpeg

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
like image 999
Rodion Baskakov Avatar asked Dec 13 '16 23:12

Rodion Baskakov


1 Answers

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

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
like image 52
Rodion Baskakov Avatar answered Sep 23 '22 06:09

Rodion Baskakov