FFMPEG Streaming updated image in loop to FB Live Video

1.4k views Asked by At

I am trying to stream image to fb live video using this command :

ffmpeg -loop 1 -re -i "input.jpg" -pix_fmt yuv420p -profile:v baseline -s 720x480 -bufsize 6000k -vb 400k -maxrate 1500k -deinterlace -t 60 -vcodec libx264 -preset veryfast -g 30 -r 30 -f flv "rtmp_link"

This command works perfectly for one single input file. But the problem is that I want ffmpeg to stream the latest and updated version of "input.jpg" file because my app is updating this "input.jpg" after every 2-3 seconds but the image that is streamed is the older version, not the updated one.

If I try to restart this loop, then streaming stops for approx. 4-5 seconds which is sufficient enough for FB live video to consider that streaming has been stopped and it then ends the live video.

So, is it possible to use the latest available version of input file for streaming in this loop? I don't know much about FFMPEG and I tried to search this issue but all in vain.

1

There are 1 answers

3
Aakash Gupta On BEST ANSWER

I have finally figured out a solution for this. When I was directly overwriting ‘input.jpg’ file using my rails app, this process was taking a few miliseconds but during this time too, ffmpeg was streaming this file which was incomplete for few miliseconds.

So, the solution for this issue is that first write the updated image to a temp file like ‘input.tmp.img’ and then move this file to the original file using script or using terminal like mv input.tmp.img input.jpg As moving process hardly takes any time, this solved the problem for me.