Restartable HLS encoding in ffmpeg

232 Views Asked by At

I'm trying to encode a HLS video in a restartable way so that it can be run on a preemptive VM. It's possible with the segment muxer in FFmpeg to create HLS files with mpegts that can be restarted (Using the -ss [time], -segment_start_number [num], -mpegts_copyts 1, segment_list_type csv and -segment_list_flags live flags and a bit of coding) but I cannot find equivalent "live" writing for the hls muxer specifically.

Either I need a solution that allows for writing fmp4 fragments using the segment muxer or live writing for the hls muxer.

1

There are 1 best solutions below

0
TheGreatRambler On

It is possible to accomplish this via -hls_playlist_type event and -hls_flags append_list. For example:

ffmpeg -i testvideo.mp4 -f hls -hls_playlist_type event -hls_segment_type fmp4 -hls_time 3 -hls_list_size 0 -hls_flags append_list -hls_segment_filename full.%d.m4s -c:v libx264 -b:v 20M full.m3u8

The generated init.mp4 will always be (nearly) identical (differs by a few bytes but decodes the same), regardless of start point, so only the last copy needs to be kept. The actual m3u8 can be generated using code at the end.