FFMPEG Streaming updated image in loop to FB Live Video - facebook

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.

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.

Related

Laggy video when downloading from m3u8 link with ffmpeg

Im trying to download the video in this m3u8 link https://lbs-usp-hls-vod.cmore.se/vod/1aee4/l4fiymehvxx(13287875_ISMUSP).ism/l4fiymehvxx(13287875_ISMUSP).m3u8, and to do that I run this command:
ffmpeg -i "https://lbs-usp-hls-vod.cmore.se/vod/1aee4/l4fiymehvxx(13287875_ISMUSP).ism/l4fiymehvxx(13287875_ISMUSP).m3u8" -vcodec copy -acodec copy output.mp4
The video downloads fine without any errors, but when I play the video it dosen't look great because it looks like the frame rate is very low, but looking in videoproperties in VLC it says that it is 25 fps which is the same as the original video.
The m3u8 link comes from this website if you need to know that: https://www.tv4play.se/program/taskmaster/13287875
Do someone know what is causing this issue and how to fix it?
Thank you for any advice!
EDIT: I did manage to solve it myself after a lot of research. I just needed to add -fflags +igndts before the -i so the command looked like this
ffmpeg -fflags +igndts -i "https://lbs-usp-hls-vod.cmore.se/vod/1aee4/l4fiymehvxx(13287875_ISMUSP).ism/l4fiymehvxx(13287875_ISMUSP).m3u8" -vcodec copy -acodec copy output.mp4

How do you generate a looping animated gif for Facebook with ffmpeg

When I paste a giphy url (like this one) into a facebook post or comment, the gif plays immediately and loops indefinitely. When I upload ones I make from ffmpeg, neither of those things happen. You have to click a play button to start the animation and then it ends after one time through.
I have a couple of ffmpeg commands I use to create the gifs. They are:
ffmpeg -ss 10 -t 5 -i input.m4v -vf "fps=15,scale=800:-2:flags=lanczos,palettegen" -y palette.png
and
ffmpeg -ss 10.6 -t 5 -i input.m4v -i palette.png -filter_complex "fps=15,scale=800:-1:lanczos[video];[video][1:v]paletteuse" output.gif
The first one generates a custom color pallet that's used by the second one to create a high quality animated gif. I've also tried adding -loop 0 (i.e. ffmpeg -ss 10.6 -t 5 -i input.m4v -i palette.png -filter_complex "fps=15,scale=800:-1:lanczos[video];[video][1:v]paletteuse" -loop 0 output.gif) but that didn't work either.
I also tried uploading the ffmpeg generated images to a personal website and calling them from there but those didn't load at all.
In case it helps, here's a copy of one of the gifs (which autostarts and loops on StackOverflow for me but not on FB)
How does one go about creating a gif that will autostart and loop indefinitely for facebook?
(Note: I've got no problem if I need to do something with a personal website, but I don't want to use Giphly or the other animated gif sites directly if at all possible. Also worth pointing out that I discovered if I download the image from giphly and upload it, it doesn't autostart either. So, this may be something internal to FB, but I'd still like to figure that out.)
The file from Giphy appears to be a WebP, not a GIF:
ffmpeg -i giphy
[…]
Stream #0:0: Video: webp, none, 25 tbr, 25 tbn, 25 tbc
Firefox and mediainfo concur.
So try making a WebP instead:
ffmpeg -ss 10.6 -t 5 -i input.m4v -loop 0 output.webp
Your ffmpeg will have to be compiled with --enable-libwebp.
See ffmpeg -h encoder=libwebp and ffmpeg -h muxer=webp for more options.

Swapping FFMPEG input source

I'm using FFMPEG to stream RMTP to a server. I wish to change what I'm streaming without breaking the connection to this server.
My current FFMPEG command looks like so:
ffmpeg -f v4l2 -s 1280x720 -r 10 -i /dev/video0 -c:v libx264 -f flv -r 30 -pix_fmt yuv420p "rtmp://server live=true pubUser=user pubPasswd=pass playpath=stream"
If I wanted to change from /dev/video0 to /dev/video1 then I need to stop this program and re-run the command swapping out the -i bit.
Since FFMPEG can read from stdin as well as files, I believe it should be possible to switch the input source on the fly by either piping the output of a different program, or utilizing UNIX sockets. There may also be a solution built into FFMPEG which I'm not aware of.
My question now is: what's the simplest / least code / most recommended way of switching these inputs? Is there a third-party tool that's recommended? Does FFMPEG have an alternate command-line parameter I've never heard of? If I do use a UNIX socket of stdin, is there a recommended way to change what's being written to them?
One of my concerns is that if I have FFMPEG read in from a UNIX socket and in a separate shell I have a different instance of FFMPEG writing to this UNIX socket, during the brief period when I'm switching sources the first instance of FFMPEG (which is doing the broadcasting) would die, as it couldn't find any video data to stream.

FFMPEG corrupting audio data when trying to edit metadata

I'm trying to use FFMPEG to edit some metadata in Powershell. My problem is that FFMPEG simply outputs an audio file with the correct metadata, but the audio does not play. The length of the track is reduced to a fraction of a second. Here is the command I'm using in Powershell:
& $ffmpeg -y -i $flac.fullname -c copy -metadata track="$tracknumber" $flac.fullname
Previously, I tried having -map 0:0 in there too, but it didn't make a difference. Thanks for any help.
Edit: I'm not sure if this is intentional behavior or not, but if I change the output path to be a new destination (rather than saving over the old destination) it does work correctly. So as a workaround, I'm just using a temp folder as an output then moving the files back to where I want them.
FFmpeg does NOT do in-place editing. Destination has to be a new file.
ffmpeg -y -i file.flac -c copy -metadata track="$tracknumber" newfile.flac

how to split/cut video using vlc in command line after every N minute?

how to split or cut a video using vlc in command line into 5 minute chucks? I know how to do it manually i just go to view->advanced controls and press the record to indicate the start time and press record again to indicate stop time now is there a way to do this in command line? if so can we also make vlc automatically cut/split the video every 5 minutes?
I'd recommend to use FFmpeg. See FFmpeg: How to split video efficiently?
The command to get the first 5 minutes would be:
ffmpeg -i input.avi -vcodec copy -acodec copy -ss 00:00:00 -t 00:05:00 output1.avi