Opened 3 months ago

Closed 3 months ago

#7131 closed defect (fixed)

-f hls -hls_list_size X -hls_flags delete_segments does not delete all old segments

Reported by: tmm1 Owned by: stevenliu
Priority: wish Component: avformat
Version: git-master Keywords: hls
Cc: stevenliu Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

The option -hls_list_size doesn't seem to work as intended when used with -hls_flags delete_segments.

For example, if I set the list size to 5:

$ ffmpeg -i h264.ts -an -c:v copy -f hls -hls_time 1 -hls_list_size 5 -hls_flags delete_segments+split_by_time out/test.m3u8
ffmpeg version N-90638-g3b2fd96048 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.1)
  configuration: --prefix=/tmp/ffmpeg-master --enable-libxml2 --enable-shared --disable-static --disable-stripping --disable-manpages
  libavutil      56. 13.100 / 56. 13.100
  libavcodec     58. 17.100 / 58. 17.100
  libavformat    58. 11.101 / 58. 11.101
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 14.100 /  7. 14.100
  libswscale      5.  0.102 /  5.  0.102
  libswresample   3.  0.101 /  3.  0.101
Input #0, mpegts, from 'h264.ts':
  Duration: 00:00:30.50, start: 60513.123933, bitrate: 3759 kb/s
  Program 1
  No Program
    Stream #0:0[0xefd]: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc
    Stream #0:1[0xeff]: Audio: ac3, 48000 Hz, mono, fltp, 64 kb/s
    Stream #0:2[0xefe]: Audio: ac3, 48000 Hz, stereo, fltp, 384 kb/s
[hls @ 0x7f8dc8803600] Opening 'out/test0.ts' for writing
Output #0, hls, to 'out/test.m3u8':
  Metadata:
    encoder         : Lavf58.11.101
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 59.94 fps, 59.94 tbr, 90k tbn, 59.94 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[hls @ 0x7f8dc8803600] Opening 'out/test1.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test2.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test3.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test4.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test5.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test6.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test7.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test8.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test9.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test10.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test11.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test12.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test13.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test14.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test15.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test16.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test17.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test18.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test19.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test20.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test21.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test22.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test23.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test24.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test25.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test26.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test27.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test28.ts' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
[hls @ 0x7f8dc8803600] Opening 'out/test.m3u8.tmp' for writing
frame= 1722 fps=0.0 q=-1.0 Lsize=N/A time=00:00:29.27 bitrate=N/A speed= 631x
video:11218kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

The m3u8 contains 5 entries as expected:

$ cat out/test.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:1
#EXT-X-MEDIA-SEQUENCE:24
#EXTINF:1.034022,
test24.ts
#EXTINF:0.933956,
test25.ts
#EXTINF:1.084056,
test26.ts
#EXTINF:1.000667,
test27.ts
#EXTINF:0.750500,
test28.ts
#EXT-X-ENDLIST

But more than 5 segments still exist on disk. While some old segments are deleted, not enough to ensure that only 5 still exist:

$ ls -lhrt out
total 4.4M
-rw-r--r-- 1 tmm1 wheel 446K Apr  9 19:04 test18.ts
-rw-r--r-- 1 tmm1 wheel 427K Apr  9 19:04 test19.ts
-rw-r--r-- 1 tmm1 wheel 382K Apr  9 19:04 test20.ts
-rw-r--r-- 1 tmm1 wheel 363K Apr  9 19:04 test21.ts
-rw-r--r-- 1 tmm1 wheel 386K Apr  9 19:04 test22.ts
-rw-r--r-- 1 tmm1 wheel 446K Apr  9 19:04 test23.ts
-rw-r--r-- 1 tmm1 wheel 442K Apr  9 19:04 test24.ts
-rw-r--r-- 1 tmm1 wheel 297K Apr  9 19:04 test25.ts
-rw-r--r-- 1 tmm1 wheel 505K Apr  9 19:04 test26.ts
-rw-r--r-- 1 tmm1 wheel 406K Apr  9 19:04 test27.ts
-rw-r--r-- 1 tmm1 wheel 304K Apr  9 19:04 test28.ts
-rw-r--r-- 1 tmm1 wheel  229 Apr  9 19:04 test.m3u8

Change History (5)

comment:1 Changed 3 months ago by stevenliu

That is because the vs->nb_entries = 0 hls_list_size times, and +1 to hls_list_size, the it is n = 2 * hls_list_size + 1, if this is not good,
what about save the segments to hls_list_size + 1 ?

comment:2 Changed 3 months ago by stevenliu

That is because the vs->nb_entries = 0 hls_list_size times, and +1 to hls_list_size, the it is n = 2 * hls_list_size + 1, if this is not good,
what about save the segments to hls_list_size + 1 ?

comment:3 Changed 3 months ago by tmm1

hls_list_size + 1 sounds good to me.

comment:4 Changed 3 months ago by stevenliu

  • Component changed from undetermined to avformat
  • Keywords hls added
  • Owner set to stevenliu
  • Priority changed from normal to wish
  • Status changed from new to open

comment:5 Changed 3 months ago by stevenliu

  • Resolution set to fixed
  • Status changed from open to closed
Note: See TracTickets for help on using tickets.