Ffmpeg Http Live Streaming Remove Old Segments

Ffmpeg Http Live Streaming Remove Old Segments

Hello i Have a Live HTTP stream input for ffmpeg i want to create HLS streaming im using ffmpeg to do this

ffmpeg -i  -map 0 -codec:v libx264 -codec:a copy -f ssegment -segment_list playlist.m3u8 -segment_list_type hls -segment_list_size 10 -segment_list_flags +live -segment_time 10 out%03d.ts

i works fine i just want to delete the old segmens that are not shown in playlist.m3u8

segment_list_size 10

this will keep the last 10 in the playlist file i want to keep only these files on hard disk

2 Answers

You can use the recently added option to the HLS segmenter:

-hls_flags delete_segments

You will need to change your command to use the HLS segmenter rather than the stream segmenter by using -f hls instead of -f ssegment.

I've been using this option and it doesn't do exactly what you request, but rather it's implemented to be compliant with the HLS spec. See the ffmpeg documentation for more information:

2

USE

-segment_wrap 10

for wrap and rewrite segment files

Your Answer

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

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.