17

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

ffmpeg -i http://127.0.0.1:4242/bysid/7275 -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

k961
  • 577
  • 1
  • 5
  • 19

2 Answers2

27

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: https://www.ffmpeg.org/ffmpeg-formats.html

Bent Olsen
  • 385
  • 3
  • 6
  • I replaced -f segment to -f hls, but I got error: Could not write header for output file #0 (incorrect codec parameters ?): Invali d argument – Dr.jacky Jul 25 '15 at 12:21
  • 1
    An example using -f hls and also -hls_flags delete_segments: ffmpeg -v verbose -i "rtsp://admin:XXX@192.168.2.73:554/cam/realmonitor?channel=1&subtype=0" -vf scale=1920:1080 -vcodec libx264 -r 25 -b:v 1000000 -crf 31 -an -sc_threshold 0 -f hls -hls_time 5 -hls_list_size 5 -hls_flags delete_segments stream.m3u8 – super_ylam Apr 20 '21 at 04:04
2

USE

-segment_wrap 10

for wrap and rewrite segment files