[FFmpeg-user] Live streaming with dynamic overlay
dopelabs at dubstep.fm
Sun Apr 22 16:10:31 EEST 2018
there is a method but its a bit hacky..
here is a demonstration file i just created using the below details
i created 2 image files the same frame size as my output video, one thats completely transparent, and one that has the graphic i want to display with a transparent background
here are the 2 image files i used
i am screen capturing one of my displays...
ffmpeg -loglevel 0 -f avfoundation -r 30 -i "3:"
i used globbing and the loop option to have ffmpeg read an image sequence (of 1 image) and loop.
-pattern_type glob -loop 1 -i 'alpha00*.png'
i then overlaid the transparent image on top.
-filter_complex '[0:v][1:v] overlay'
what i end up with is something like this
ffmpeg -loglevel 0 -f avfoundation -r 30 -i "3:" -pattern_type glob -loop 1 -r 30 -i 'alpha00*.png' -filter_complex '[0:v][1:v] overlay' -c:v h264 -b:v 10000k -preset ultrafast -pix_fmt yuv420p -movflags +faststart -y -r 30 dynamic_overlay.mp4
now here comes the tricky bit.. since ffmpeg is reading the image file for every frame, we can swap out the image with a new one, but only if done atomically.
first i made copies of both files
$ cp alpha001.png alpha1.png
$ cp ffmpeg.png ffmpeg1.png
then i atomically replaced the file ffmpeg is reading with the new copy containing the graphic i want to display
$ mv ffmpeg1.png alpha001.png
when i am ready to remove the graphic i atomically replace the with the transparent copy
$ mv alpha1.png alpha001.png
if you try to replace the file non atomically such as cp or simply overwriting, ffmpeg may (and usually does) fail and shuts down.
for sound effects you might want to look into something like jack or some other utility that has the ability to create virtual audio interfaces.
you can then specify said interface as input in ffmpeg and have the sound effects player output to the virtual interface, then use something like amix or amerge if theres already an audio track
i hope this may help a little.. as i said its a bit hacky, but easily scriptable if you wanted to automate.
> On Apr 19, 2018, at 8:38 40AM, Nam Giang <kyng at ece.ubc.ca> wrote:
> Thanks for your comment. Do you mean we need to tap into the code of ffmpeg
> in order to do that?
> Otherwise what I see is just a bunch of command lines.
> Part of my streaming agenda comes from a Raspberry Pi that does not have a
> gui so obs won’t be an option I’m afraid.
> On Thu, Apr 19, 2018 at 2:41 AM DopeLabs <dopelabs at dubstep.fm> wrote:
>> it can sort of be done, but not practical or easy to accomplish at all..
>> youd be better off using something like OBS, which makes the things you
>> want to do very easy.
>> OBS already uses or can use ffmpeg behind the scenes anyways =]
>> cheers =]
>>> On Apr 18, 2018, at 10:16 55PM, Nam Giang <kyng at ece.ubc.ca> wrote:
>>> Hi there,
>>> I'm using ffmpeg to live stream to Youtube. I'm wondering if I can do
>>> dynamic overlay.
>>> For example, when my stream is live and the world is watching, at some
>>> points I want to pop up some pictures or add some sound effects to my
>>> I wonder if there is any command that I can use to add those things into
>>> live stream?
>>> ffmpeg-user mailing list
>>> ffmpeg-user at ffmpeg.org
>>> To unsubscribe, visit link above, or email
>>> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>> ffmpeg-user mailing list
>> ffmpeg-user at ffmpeg.org
>> To unsubscribe, visit link above, or email
>> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-user