[FFmpeg-user] Hardening ffmpeg stream download?

Bo Berglund bo.berglund at gmail.com
Thu Jun 9 19:16:28 EEST 2022


I have a question regarding how to "harden" my video stream downloads so they do
not get corrupted if a glitch occurs, like Internet loss or something else.

As it is now my streams download fine if all is working OK but when a glitch
occurs the download stops and the video file on disk becomes unplayable.

It happened again yesterday due to a power outage, but has happened before for
other reasons like fiber connectivity problems etc.

The remaining file is not viewable and depending on the viewer I can get a
message talking about missing moov something.

So my download script uses this basic ffmpeg command to download the video:

CMD="ffmpeg -hide_banner ${MODE} -i \"${M3U8URL}\" -vf scale=w=-4:h=480 -c:v
libx264 -preset fast -crf 26 -c:a aac -t ${CAPTURETIME} ${TARGETFILE}"

Where:
MODE="-referer \"${VIDEOURL}\""
M3U8URL is the stream's m3u8 URL
CAPTURETIME is the time in seconds to download
TARGETFILE is the output mp4 file

Now I wonder if there is some additional ffmpeg argument that can be added to
make the output contuinuously "complete" such that it can be played as far as
the download was done?

Or if it is impossible given the output file format, is there some other format
that can be used to harden the download?

For example, can the download just write to file after reformatting the size but
in say ts format and another process *simultaneously* read that file and convert
it to mp4 during download?

Then at least if the main download stops the "raw" ts file would remain...
Of course given that ts ia about 10x larger on disk than mp4 one has to manage
this carefully to not fill up the drive..


-- 
Bo Berglund
Developer in Sweden



More information about the ffmpeg-user mailing list