Opened 22 months ago

Closed 22 months ago

Last modified 11 months ago

#5811 closed defect (worksforme)

live_start_index option doesn't work.

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

Description

This bug occurs when you try to copy live hls stream from start. ffmpeg has an option to set the segment number where it must start reading.

ffmpeg -h full
-live_start_index  <int>        .D...... segment index to start live streams at (negative values are from the end) (from INT_MIN to INT_MAX) (default -3)

But this option is totally broken, and ffmpeg always starts at the third last segment.

This happens because function select_cur_seq_no in hls.c uses c->live_start_index before ffmpeg sets its value to the specified by user.

Let's look to the call stack:
avformat_open_input --> s->iformat->read_header(s) --> hls_read_header --> pls->cur_seq_no = select_cur_seq_no(c, pls); --> select_cur_seq_no (here options was readed from HLSContext struct).

Because all options changes should occur after avformat_open_input call, there's no way to change this option value.

Looks like somebody tried to fix it and made AVFMT_FLAG_PRIV_OPT flag, which would eliminate s->iformat->read_header call in avformat_open_input. But as of today this flag isn't work (and it is unlikely will be worked in the future).

How to reproduce:

ffmpeg -re -i some_video.mp4 -c copy -hls_time 10 -hls_list_size 0 hls_stream/stream.m3u8 &
sleep 100
ffmpeg -i hls_stream/stream.m3u8 -live_start_index 0 new_video.mp4

Despite -live_start_index 0 option, ffmpeg dropped the first few segments.

Change History (7)

comment:1 Changed 22 months ago by cehoyos

  • Keywords hls added
  • Resolution set to worksforme
  • Status changed from new to closed

Works for me as documented, your analysis is definitely wrong, see for example mov_read_header() which reads a context variable mapped from a user option on the top of the function.
Feel free to reopen this ticket if you can provide the failing command line(s) together with the complete, uncut console output.

comment:2 Changed 22 months ago by smalukav

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Ok, just look what happens when you try to copy live hls stream.
Firstly, create live stream with option -re.

$ /opt/ffmpeg/bin/ffmpeg -re -i http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_2160p_60fps_normal.mp4 -c copy -hls_time 10 -hls_list_size 0 hls_stream/stream.m3u8
ffmpeg version N-81495-g11a631d Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --enable-rpath --prefix=/opt/ffmpeg --toolchain=hardened --enable-shared --enable-gpl --enable-nonfree --enable-openssl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libebur128
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.101 / 57. 54.101
  libavformat    57. 48.101 / 57. 48.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 58.100 /  6. 58.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_2160p_60fps_normal.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2013-12-17T16:40:26.000000Z
    title           : Big Buck Bunny, Sunflower version
    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
    genre           : Animation
    composer        : Sacha Goedegebure
  Duration: 00:10:34.53, start: 0.000000, bitrate: 8487 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 8002 kb/s, 60 fps, 60 tbr, 60k tbn, 120 tbc (default)
    Metadata:
      creation_time   : 2013-12-17T16:40:26.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, s16p, 160 kb/s (default)
    Metadata:
      creation_time   : 2013-12-17T16:40:28.000000Z
      handler_name    : GPAC ISO Audio Handler
    Stream #0:2(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 320 kb/s (default)
    Metadata:
      creation_time   : 2013-12-17T16:40:28.000000Z
      handler_name    : GPAC ISO Audio Handler
    Side data:
      audio service type: main
[hls @ 0xea7160] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, hls, to 'hls_stream/stream.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    composer        : Sacha Goedegebure
    title           : Big Buck Bunny, Sunflower version
    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
    genre           : Animation
    encoder         : Lavf57.48.101
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 8002 kb/s, 60 fps, 60 tbr, 90k tbn, 120 tbc (default)
    Metadata:
      creation_time   : 2013-12-17T16:40:26.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), 320 kb/s (default)
    Metadata:
      creation_time   : 2013-12-17T16:40:28.000000Z
      handler_name    : GPAC ISO Audio Handler
    Side data:
      audio service type: main
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:2 -> #0:1 (copy)

Stream created. Wait when ffmpeg transcribe to local live stream a lot of segments.

$ cat hls_stream/stream.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:13
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:12.483333,
stream0.ts
#EXTINF:7.616667,
stream1.ts
#EXTINF:11.466667,
stream2.ts
#EXTINF:12.300000,
stream3.ts
#EXTINF:8.200000,
stream4.ts
#EXTINF:8.333333,
stream5.ts
#EXTINF:11.916667,
stream6.ts
#EXTINF:11.750000,
stream7.ts
#EXTINF:8.333333,
stream8.ts
#EXTINF:11.700000,
stream9.ts
#EXTINF:8.333333,
stream10.ts
#EXTINF:8.750000,
stream11.ts
#EXTINF:10.050000,
stream12.ts
#EXTINF:12.500000,
stream13.ts
#EXTINF:7.000000,
stream14.ts
#EXTINF:9.633333,
stream15.ts
#EXTINF:10.216667,
stream16.ts
#EXTINF:9.900000,
stream17.ts
#EXTINF:9.833333,
stream18.ts
#EXTINF:10.966667,
stream19.ts
#EXTINF:9.000000,
stream20.ts
#EXTINF:12.033333,
stream21.ts

And now try to copy local stream to new video starting from the first segment.

$ /opt/ffmpeg/bin/ffmpeg -i hls_stream/stream.m3u8 -c copy -live_start_index 0 -v 45 new_video.mp4
ffmpeg version N-81495-g11a631d Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --enable-rpath --prefix=/opt/ffmpeg --toolchain=hardened --enable-shared --enable-gpl --enable-nonfree --enable-openssl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libebur128
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.101 / 57. 54.101
  libavformat    57. 48.101 / 57. 48.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 58.100 /  6. 58.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-i' ... matched as input file with argument 'hls_stream/stream.m3u8'.
Reading option '-c' ... matched as option 'c' (codec name) with argument 'copy'.
Reading option '-live_start_index' ... matched as AVOption 'live_start_index' with argument '0'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '99'.
Reading option 'new_video.mp4' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 99.
Successfully parsed a group of options.
Parsing a group of options: input file hls_stream/stream.m3u8.
Successfully parsed a group of options.
Opening an input file: hls_stream/stream.m3u8.
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream19.ts', offset 0, playlist 0
[h264 @ 0x1fb59a0] Reinit context to 3840x2160, pix_fmt: yuv420p
Input #0, hls,applehttp, from 'hls_stream/stream.m3u8':
  Duration: N/A, start: 191.736000, bitrate: N/A
  Program 0 
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: h264 (High), 1 reference frame ([27][0][0][0] / 0x001B), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], 60 fps, 60 tbr, 90k tbn, 120 tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 320 kb/s
    Metadata:
      variant_bitrate : 0
[mp4 @ 0x1fa62a0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
[mp4 @ 0x1fa62a0] track 1: codec frame size is not set
Output #0, mp4, to 'new_video.mp4':
  Metadata:
    encoder         : Lavf57.48.101
    Stream #0:0: Video: h264 (High), 1 reference frame ([33][0][0][0] / 0x0021), yuv420p, 3840x2160 (0x0) [SAR 1:1 DAR 16:9], q=2-31, 60 fps, 60 tbr, 90k tbn, 90k tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: ac3 ([165][0][0][0] / 0x00A5), 48000 Hz, 5.1(side), 320 kb/s
    Metadata:
      variant_bitrate : 0
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream20.ts', offset 0, playlist 0
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream21.ts', offset 0, playlist 0
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream22.ts', offset 0, playlist 0
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream23.ts', offset 0, playlist 0   
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream24.ts', offset 0, playlist 0   
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream25.ts', offset 0, playlist 0   
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream26.ts', offset 0, playlist 0   
[hls,applehttp @ 0x1f92820] HLS request for url 'hls_stream/stream27.ts', offset 0, playlist 0

Despite -live_start_index option, ffmpeg start reading only from segment 19, not the first segment.
And if you change in source code the default option value to 0 (start from the first segment) and recompile ffmpeg, these commands will work as expected.

comment:3 Changed 22 months ago by cehoyos

Please test with -f lavfi -i testsrc as input and -vcodec mpeg1video as codec so I can try to reproduce.
Is this only reproducible with -vcodec copy? It was not part of your original command line.

comment:4 Changed 22 months ago by smalukav

$ /opt/ffmpeg/bin/ffmpeg -re -f lavfi -i testsrc -vcodec mpeg1video -hls_time 10 -hls_list_size 0 hls_stream/stream.m3u8
ffmpeg version N-81495-g11a631d Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --enable-rpath --prefix=/opt/ffmpeg --toolchain=hardened --enable-shared --enable-gpl --enable-nonfree --enable-openssl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libebur128
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.101 / 57. 54.101
  libavformat    57. 48.101 / 57. 48.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 58.100 /  6. 58.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, lavfi, from 'testsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
[hls @ 0x1010d80] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, hls, to 'hls_stream/stream.m3u8':
  Metadata:
    encoder         : Lavf57.48.101
    Stream #0:0: Video: mpeg1video, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.54.101 mpeg1video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg1video (native))
Press [q] to stop, [?] for help
$ cat hls_stream/stream.m3u8                                                                           
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.080000,
stream0.ts
#EXTINF:10.080000,
stream1.ts
#EXTINF:10.080000,
stream2.ts
#EXTINF:10.080000,
stream3.ts
#EXTINF:10.080000,
stream4.ts
#EXTINF:9.600000,
stream5.ts
#EXTINF:10.080000,
stream6.ts
#EXTINF:10.080000,
stream7.ts
#EXTINF:10.080000,
stream8.ts
#EXTINF:10.080000,
stream9.ts
#EXTINF:10.080000,
stream10.ts
#EXTINF:9.600000,
stream11.ts
#EXTINF:10.080000,
stream12.ts
#EXTINF:10.080000,
stream13.ts
#EXTINF:10.080000,
stream14.ts
$ /opt/ffmpeg/bin/ffmpeg -i hls_stream/stream.m3u8 -vcodec mpeg1video -live_start_index 0 -v 45 new_video.mp4           
ffmpeg version N-81495-g11a631d Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --enable-rpath --prefix=/opt/ffmpeg --toolchain=hardened --enable-shared --enable-gpl --enable-nonfree --enable-openssl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libebur128
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.101 / 57. 54.101
  libavformat    57. 48.101 / 57. 48.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 58.100 /  6. 58.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream12.ts', offset 0, playlist 0
Input #0, hls,applehttp, from 'hls_stream/stream.m3u8':
  Duration: N/A, start: 121.440000, bitrate: 104857 kb/s
  Program 0 
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: mpeg1video, 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 320x240 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
[graph 0 input from stream 0:0 @ 0x837540] w:320 h:240 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[mp4 @ 0x85c420] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, mp4, to 'new_video.mp4':
  Metadata:
    encoder         : Lavf57.48.101
    Stream #0:0: Video: mpeg1video, 1 reference frame (j[0][0][0] / 0x006A), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
      encoder         : Lavc57.54.101 mpeg1video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video (native) -> mpeg1video (native))
Press [q] to stop, [?] for help
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream13.ts', offset 0, playlist 0
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream14.ts', offset 0, playlist 0
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream15.ts', offset 0, playlist 0
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream16.ts', offset 0, playlist 0   
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream17.ts', offset 0, playlist 0   
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream18.ts', offset 0, playlist 0   
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream19.ts', offset 0, playlist 0   
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream20.ts', offset 0, playlist 0   
[hls,applehttp @ 0x837820] HLS request for url 'hls_stream/stream21.ts', offset 0, playlist 0   

Is this only reproducible with -vcodec copy?

No, it doesn't depend on the codec. I guess it's only demuxer problem.

comment:5 Changed 22 months ago by cehoyos

  • Resolution set to worksforme
  • Status changed from reopened to closed
$ ffmpeg -v 45 -live_start_index 0 -i stream.m3u8 out.avi
ffmpeg version N-81473-gb2c6a11 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.100 / 57. 54.100
  libavformat    57. 48.100 / 57. 48.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 57.100 /  6. 57.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[hls,applehttp @ 0x35c3440] HLS request for url 'stream0.ts', offset 0, playlist 0
Input #0, hls,applehttp, from 'stream.m3u8':
  Duration: N/A, start: 1.440000, bitrate: 104857 kb/s
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: mpeg1video, 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 320x240 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
[graph 0 input from stream 0:0 @ 0x361baa0] w:320 h:240 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[avi @ 0x35e8d00] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf57.48.100
    Stream #0:0: Video: mpeg4, 1 reference frame (FMP4 / 0x34504D46), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
      encoder         : Lavc57.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[hls,applehttp @ 0x35c3440] HLS request for url 'stream1.ts', offset 0, playlist 0
[hls,applehttp @ 0x35c3440] HLS request for url 'stream2.ts', offset 0, playlist 0
[hls,applehttp @ 0x35c3440] HLS request for url 'stream3.ts', offset 0, playlist 0
[hls,applehttp @ 0x35c3440] HLS request for url 'stream4.ts', offset 0, playlist 0
frame= 1056 fps=0.0 q=9.4 Lsize=    1363kB time=00:00:42.24 bitrate= 264.3kbits/s speed= 140x
video:1332kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.320622%
Input file #0 (stream.m3u8):
  Input stream #0:0 (video): 1057 packets read (1382348 bytes); 1057 frames decoded;
  Total: 1057 packets (1382348 bytes) demuxed
Output file #0 (out.avi):
  Output stream #0:0 (video): 1056 frames encoded; 1056 packets muxed (1363729 bytes);
  Total: 1056 packets (1363729 bytes) muxed
$ ffmpeg -v 45 -live_start_index 11 -i stream.m3u8 out.avi
ffmpeg version N-81473-gb2c6a11 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.100 / 57. 54.100
  libavformat    57. 48.100 / 57. 48.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 57.100 /  6. 57.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[hls,applehttp @ 0x2be1440] HLS request for url 'stream11.ts', offset 0, playlist 0
Input #0, hls,applehttp, from 'stream.m3u8':
  Duration: N/A, start: 111.840000, bitrate: 104857 kb/s
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: mpeg1video, 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 320x240 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
[graph 0 input from stream 0:0 @ 0x2bf6280] w:320 h:240 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[avi @ 0x2bf2640] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf57.48.100
    Stream #0:0: Video: mpeg4, 1 reference frame (FMP4 / 0x34504D46), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
      encoder         : Lavc57.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[hls,applehttp @ 0x2be1440] HLS request for url 'stream12.ts', offset 0, playlist 0
[hls,applehttp @ 0x2be1440] HLS request for url 'stream13.ts', offset 0, playlist 0
[hls,applehttp @ 0x2be1440] HLS request for url 'stream14.ts', offset 0, playlist 0
[hls,applehttp @ 0x2be1440] HLS request for url 'stream15.ts', offset 0, playlist 0
frame= 1141 fps=0.0 q=7.6 Lsize=    1450kB time=00:00:45.64 bitrate= 260.3kbits/s speed= 152x
video:1417kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.321591%
Input file #0 (stream.m3u8):
  Input stream #0:0 (video): 1142 packets read (1160452 bytes); 1142 frames decoded;
  Total: 1142 packets (1160452 bytes) demuxed
Output file #0 (out.avi):
  Output stream #0:0 (video): 1141 frames encoded; 1141 packets muxed (1451289 bytes);
  Total: 1141 packets (1451289 bytes) muxed
$ ffmpeg -v 45 -live_start_index -15 -i stream.m3u8 out.avi
ffmpeg version N-81473-gb2c6a11 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      55. 29.100 / 55. 29.100
  libavcodec     57. 54.100 / 57. 54.100
  libavformat    57. 48.100 / 57. 48.100
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 57.100 /  6. 57.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
[hls,applehttp @ 0x1ece440] HLS request for url 'stream24.ts', offset 0, playlist 0
Input #0, hls,applehttp, from 'stream.m3u8':
  Duration: N/A, start: 241.440000, bitrate: 104857 kb/s
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: mpeg1video, 1 reference frame ([2][0][0][0] / 0x0002), yuv420p(tv), 320x240 [SAR 1:1 DAR 4:3], 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
[graph 0 input from stream 0:0 @ 0x1f0c780] w:320 h:240 pixfmt:yuv420p tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[avi @ 0x1ef41e0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, avi, to 'out.avi':
  Metadata:
    ISFT            : Lavf57.48.100
    Stream #0:0: Video: mpeg4, 1 reference frame (FMP4 / 0x34504D46), yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      variant_bitrate : 0
      encoder         : Lavc57.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg1video (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[hls,applehttp @ 0x1ece440] HLS request for url 'stream25.ts', offset 0, playlist 0
[hls,applehttp @ 0x1ece440] HLS request for url 'stream26.ts', offset 0, playlist 0
[hls,applehttp @ 0x1ece440] HLS request for url 'stream27.ts', offset 0, playlist 0
[hls,applehttp @ 0x1ece440] HLS request for url 'stream28.ts', offset 0, playlist 0
frame= 1119 fps=0.0 q=11.0 Lsize=    1423kB time=00:00:44.76 bitrate= 260.5kbits/s speed= 149x
video:1391kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.328217%
Input file #0 (stream.m3u8):
  Input stream #0:0 (video): 1120 packets read (1140142 bytes); 1120 frames decoded;
  Total: 1120 packets (1140142 bytes) demuxed
Output file #0 (out.avi):
  Output stream #0:0 (video): 1119 frames encoded; 1119 packets muxed (1424266 bytes);
  Total: 1119 packets (1424266 bytes) muxed

comment:6 Changed 11 months ago by Gunnat

  • Keywords hls.c added; hls removed
  • Priority changed from normal to critical

just fixed the funny live_start_index bug.
At least fix for the server and stream I am interested in.
Turns out like this in my case (10s segments)

  • pls->start_seq_no, whatever segment is streamed "now" from stream server
  • pls->n_segments, the max OLD segments the server keeps available, 1438,FOUR HOURS
  • c->live_start_index, where ffmpeg puts the command argument I give it, 1400

Note, pls->n_segments is given as a positive number although it is kindo negative, how max cmaller one can make the segmentcounter. (the thought-bug?)

THat is, a funny thing, shld i use PLUS 1400 or MINUS 1400?
Note, when asking for old, smaller number segments!

(seems the existing code did the same thought-bug in both cases?? always did nothing?)

So I made it accept both but always GO BACKWARDS (earlier), both in time and segments


/* index If this is a LIVE stream, start live_start_index segments from the

  • start or end */

printf("\n start_seq_no %d n_segments %d live_start_index %d \n",pls->start_seq_no,pls->n_segments,c->live_start_index) ;

if (c->live_start_index < 0) /* user gives neg number, 5th grade -/+ math*/

/* take max of two negative numbers, hehe*/
/* 93abcd, - 1438(4 hours back), -1400*/

seq_gunnar = pls->start_seq_no + FFMAX((- pls->n_segments), c->live_start_index);

else /* user gives pos number, kindo simpler, just subtract the smaller*/

/* 1400, 1438 */

seq_gunnar = pls->start_seq_no - FFMIN(c->live_start_index, pls->n_segments);

printf("\n start_seq_no %d n_segments %d live_start_index %d gunnar %d\n",pls->start_seq_no,pls->n_segments,c->live_start_index,seq_gunnar) ;

return seq_gunnar;


bottom line, the negative of a cpl of negative or not negative numbers is funny

PS Forgot, disabled lots of checks of seqment numbers in read_data subroutine, esp the reload: part.
A mess at the moment, cant do other backwards numbers than the full 4 hours
But better than nothing at all.

Last edited 11 months ago by Gunnat (previous) (diff)

comment:7 Changed 11 months ago by llogan

  • Keywords hls added; hls.c removed
  • Priority changed from critical to normal

Please send patches to the ffmpeg-devel mailing list.

Note: See TracTickets for help on using tickets.