0

I am partially downloading a video file, sequentially.

What I've managed to achieve is for FFmpeg to encode the file as it is being downloaded if the download is faster than encoding. I cannot guarantee that the download will always be faster than encoding.

When download becomes slower than encoding I get this error, and ffmpeg exists:

[matroska,webm @ 0x1248040d0] File ended prematurely

What I am hoping to achieve is for FFmpeg to wait/hang until new bits are added to the input file, and continue with encoding when it has enough of bits for a new segment until file is complete.

I am using this command to generate hls stream:

    ffmpeg -y \
        -i ./appdata/input/Sintel.mkv \
        -preset fast \
        -c:a aac \
        -b:a 192k \
        -ac 2 \
        -c:v libx264 \
        -b:v 1024k \
        -profile:v high \
        -level 4.1 \
        -crf 34 \
        -pix_fmt yuv420p \
        -threads 0 \
        -f hls \
        -hls_list_size 0 \
        -hls_time 10 \
        -hls_playlist_type event \
        -hls_flags independent_segments+append_list \
        -master_pl_name "livestream.m3u8" \
        ./appdata/test/livestream-%v.m3u8

Can FFmpeg monitor and process the input as new bits are added to the input file?

Best solution I got so far was is to use segments and segments list from this answer: Resuming a partially-completed encode with FFmpeg

And couple it with some programming to keep retrying in the loop until the input file is complete, however, that feels like a bad solution that I would love to avoid.

1 Answer 1

2

Add -follow 1 before the input i.e.

ffmpeg -y \
    -rw_timeout 30M -follow 1 -i ./appdata/input/Sintel.mkv \

Note that the option belongs to the file protocol. It won't apply to other protocols, and ability to wait for further data depends on whether the other protocol allows it.

The option -rw_timeout is needed to terminate the file read. If no updates have occurred in that interval, ffmpeg will treat it as EOF. Its value is in microseconds i.e. 1M = 1 million microseconds = 1 second.

1
  • Thank you my friend, you are a true life saviour
    – Vjerci
    Dec 29, 2023 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.