Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6067 closed defect (fixed)

HLS segment length not equal with what m3u8 reports, when ffmpeg restarts

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

Description

Hi All,

I'm streaming my IP camera's picture. I create LIVE DVR HLS stream and it is embed in my website with JWPlayer Premium. It is adaptive, it contains 4 streams.

Unfortunatelly the internet connection of this camera is not stable, during the 6 hours long playlist, ffmpeg restart lot of times. (ffmpeg is in a bash script's infinite loop)

My problem is that sometimes, when I switch between stream versions, jwplayer fails: Sometimes it just freezes completely, sometimes picture freezes for 30-40 sec, but after this it switches successfully. Sometimes it switches, but not to the right time.
And sometimes it is switching without any problem.
I haven't find any logic, when this is happening.

First I wanted to know if HLS stream is correct, so I did some investigation.

I compared the 4 m3u8 playlists, if they are identical and I found out that they are not. There were differences in the last TS segment length when ffmpeg reconnects. I realised that the reason for this is that 2 of the streams have B frames and the other 2 do not have.
The length differences maybe because of the encoding differences.
Because of this, I dropped baseline profile, which does not support B frames, so now all 4 streams is encoded with B frames and have main or high profile.

Now the 4 playlist is identical, but the jwplayer problems are still exits.

So after this I examined what segment length are in the playlist and what are the actual lenght of the TS segments. I found out that when there is no ffmpeg restarts, then all TS files duration is exactly 4 sec long, as it is reported in the playlists. But when ffmpeg is stopping then the duration of the last segment is slightly different.

For example:
in the playlist the TS duration is 1 sec but the actual duration is 1.08 sec.
or
in the playlist the TS duration is 0.16 sec but the actual duration is 0.24 sec.

It seems like the difference is always 0.08 sec.

I think with lots of reconnects in the playlists, this can cause unexpected things, such as my problem with jwplayer.

Here is the full ffmpeg command i use right now:

ffmpeg -nostdin -nostats -rtsp_transport tcp -thread_queue_size 512 -i rtsp://x.x.x.x:554 -i /root/streams/vp.feszek/watermark_HD.png -filter_complex "[0]fps=25[fpsok];[fpsok][1] overlay=0:0,drawtext=fontfile=/root/fonts/courbd.ttf:textfile=/root/streams/meteo/vmeteo/TEMP:fontsize=26:fontcolor=white:x=690:y=18:reload=1,drawtext=fontfile=/root/fonts/courbd.ttf:textfile=/root/streams/meteo/vmeteo/HUM:fontsize=26:fontcolor=white:x=930-tw:y=18:reload=1,drawtext=fontfile=/root/fonts/courbd.ttf:text='%{localtime\:%Y.%m.%d. %T}':fontsize=30:fontcolor=white:x=w-390:y=h-100:shadowcolor=black:shadowx=1:shadowy=1,split=5 [720p] [l1] [l2] [l3] [c];[c] fps=fps=1 [cur];[l1]scale=848:480 [480p];[l2]scale=640:360 [360p];[l3]scale=424:240 [240p]" -map:v [720p] -an -c:v h264_nvenc -b:v 2200k -r 25 -g 100 -bf 2 -refs 4 -no-scenecut 1 -strict_gop 1 -profile:v high -pixel_format yuv420p -preset default -metadata title="InfoCAM.hu Madarles1 720p" -f tee "[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_720p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/$datum/720p/playlist.m3u8" -map:v [480p] -an -c:v h264_nvenc -b:v 1500k -r 25 -g 100 -bf 2 -refs 4 -no-scenecut 1 -strict_gop 1 -profile:v main -pixel_format yuv420p -preset default -metadata title="InfoCAM.hu Madarles1 480p" -f tee "[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_480p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/$datum/480p/playlist.m3u8" -map:v [360p] -an -c:v h264_nvenc -b:v 750k -r 25 -g 100 -bf 2 -refs 4 -no-scenecut 1 -strict_gop 1 -profile:v main -pixel_format yuv420p -preset default -metadata title="InfoCAM.hu Madarles1 360p" -f tee "[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_360p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/$datum/360p/playlist.m3u8" -map:v [240p] -an -c:v h264_nvenc -b:v 500k -r 25 -g 100 -bf 2 -refs 4 -no-scenecut 1 -strict_gop 1 -profile:v main -pixel_format yuv420p -preset default -metadata title="InfoCAM.hu Madarles1 240p" -f tee "[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_240p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/$datum/240p/playlist.m3u8" -map [cur] -f image2 -y -update 1 -r 1 -qscale:v 3 /var/www/html/nv/madarles/current.jpg

And it's output:

ffmpeg version N-83024-g95d9a85 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --enable-filter=drawtext --enable-nonfree --enable-libfreetype
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 71.100 / 57. 71.100
  libavformat    57. 62.100 / 57. 62.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
Input #0, rtsp, from 'rtsp:/x.x.x.x:554':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 0.239911, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt709, progressive), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #1, png_pipe, from '/root/streams/vp.feszek/watermark_HD.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 1280x720 [SAR 2834:2834 DAR 16:9], 25 tbr, 25 tbn, 25 tbc
[swscaler @ 0x2f85a00] deprecated pixel format used, make sure you did set range correctly
Output #0, tee, to '[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_720p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/20170108120108/720p/playlist.m3u8':
  Metadata:
    title           : InfoCAM.hu Madarles1 720p
    encoder         : Lavf57.62.100
    Stream #0:0: Video: h264 (h264_nvenc) (High), yuv420p, 1280x720, q=-1--1, 2200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.71.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/2200000 buffer size: 4400000 vbv_delay: -1
Output #1, tee, to '[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_480p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/20170108120108/480p/playlist.m3u8':
  Metadata:
    title           : InfoCAM.hu Madarles1 480p
    encoder         : Lavf57.62.100
    Stream #1:0: Video: h264 (h264_nvenc) (Main), yuv420p, 848x480, q=-1--1, 1500 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.71.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/1500000 buffer size: 3000000 vbv_delay: -1
Output #2, tee, to '[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_360p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/20170108120108/360p/playlist.m3u8':
  Metadata:
    title           : InfoCAM.hu Madarles1 360p
    encoder         : Lavf57.62.100
    Stream #2:0: Video: h264 (h264_nvenc) (Main), yuv420p, 640x360, q=-1--1, 750 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.71.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/750000 buffer size: 1500000 vbv_delay: -1
Output #3, tee, to '[f=hls:hls_time=4:hls_list_size=5400:hls_flags=+delete_segments+append_list+omit_endlist]/var/www/html/nv/madarles/hls/madarles_240p.m3u8|[f=hls:hls_playlist_type=2]/var/www/html/storage/nv/madarles/archivum/20170108120108/240p/playlist.m3u8':
  Metadata:
    title           : InfoCAM.hu Madarles1 240p
    encoder         : Lavf57.62.100
    Stream #3:0: Video: h264 (h264_nvenc) (Main), yuv420p, 424x240, q=-1--1, 500 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc57.71.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/500000 buffer size: 1000000 vbv_delay: -1
Output #4, image2, to '/var/www/html/nv/madarles/current.jpg':
  Metadata:
    title           : Media Presentation
    encoder         : Lavf57.62.100
    Stream #4:0: Video: mjpeg, yuvj420p(pc), 1280x720, q=2-31, 200 kb/s, 1 fps, 1 tbn, 1 tbc (default)
    Metadata:
      encoder         : Lavc57.71.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 (h264) -> fps
  Stream #1:0 (png) -> overlay:overlay
  split:output0 -> Stream #0:0 (h264_nvenc)
  scale -> Stream #1:0 (h264_nvenc)
  scale -> Stream #2:0 (h264_nvenc)
  scale -> Stream #3:0 (h264_nvenc)
  fps -> Stream #4:0 (mjpeg)


As you can see I use the "tee" format, which create 2 hls outputs. The first is the live stream, the second goes to the webcam's archives.

Here it is in action: http://madarles.hu/

Thanks for any help!

Change History (25)

comment:1 by Steven Liu, 7 years ago

Can this problem be reproduce by simple command line?

comment:2 by Steven Liu, 7 years ago

Owner: set to Steven Liu
Status: newopen

comment:3 by Steven Liu, 7 years ago

localhost:ffmpeg StevenLiu$ ffmpeg -i ~/Movies/objectC/facebook.mp4 -c:v libx264 -g 50 -an -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -t 14 output_test.m3u8
ffmpeg version N-82254-g75a1311 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.22.102
    description     : This File is Created by Easy RealMedia Tools@!
  Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0x7fc349007800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x7fc349007800] profile High, level 3.0
Output #0, hls, to 'output_test.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf57.57.100
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 640x480, q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.66.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  350 fps= 79 q=-1.0 Lsize=N/A time=00:00:13.88 bitrate=N/A speed=3.15x    
video:627kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fc349007800] frame I:7     Avg QP:16.85  size: 21811
[libx264 @ 0x7fc349007800] frame P:130   Avg QP:20.10  size:  3050
[libx264 @ 0x7fc349007800] frame B:213   Avg QP:20.62  size:   436
[libx264 @ 0x7fc349007800] consecutive B-frames: 16.3%  6.3%  4.3% 73.1%
[libx264 @ 0x7fc349007800] mb I  I16..4: 42.3% 37.9% 19.8%
[libx264 @ 0x7fc349007800] mb P  I16..4:  6.8%  4.8%  0.3%  P16..4: 27.1%  9.3%  3.5%  0.0%  0.0%    skip:48.2%
[libx264 @ 0x7fc349007800] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8: 18.4%  0.9%  0.1%  direct: 0.5%  skip:80.0%  L0:34.5% L1:61.7% BI: 3.8%
[libx264 @ 0x7fc349007800] 8x8 transform intra:39.3% inter:79.6%
[libx264 @ 0x7fc349007800] coded y,uvDC,uvAC intra: 29.2% 51.2% 14.4% inter: 5.7% 8.9% 0.2%
[libx264 @ 0x7fc349007800] i16 v,h,dc,p: 38% 17%  4% 41%
[libx264 @ 0x7fc349007800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 19% 18%  4%  7%  8%  6%  6%  5%
[libx264 @ 0x7fc349007800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 28% 12%  5%  6%  6%  6%  6%  5%
[libx264 @ 0x7fc349007800] i8c dc,h,v,p: 59% 24% 12%  4%
[libx264 @ 0x7fc349007800] Weighted P-Frames: Y:1.5% UV:0.0%
[libx264 @ 0x7fc349007800] ref P L0: 69.8% 16.6% 10.8%  2.8%  0.0%
[libx264 @ 0x7fc349007800] ref B L0: 92.9%  6.3%  0.9%
[libx264 @ 0x7fc349007800] ref B L1: 97.9%  2.1%
[libx264 @ 0x7fc349007800] kb/s:366.88
localhost:ffmpeg StevenLiu$ ffmpeg -i ~/Movies/objectC/facebook.mp4 -c:v libx264 -g 50 -an -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -t 10 output_test.m3u8
ffmpeg version N-82254-g75a1311 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.22.102
    description     : This File is Created by Easy RealMedia Tools@!
  Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0x7f8fda80e400] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x7f8fda80e400] profile High, level 3.0
Output #0, hls, to 'output_test.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf57.57.100
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 640x480, q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.66.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=  250 fps= 86 q=-1.0 Lsize=N/A time=00:00:09.88 bitrate=N/A speed=3.39x    
video:486kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7f8fda80e400] frame I:5     Avg QP:17.56  size: 21163
[libx264 @ 0x7f8fda80e400] frame P:104   Avg QP:20.44  size:  3004
[libx264 @ 0x7f8fda80e400] frame B:141   Avg QP:21.53  size:   565
[libx264 @ 0x7f8fda80e400] consecutive B-frames: 21.2%  8.8%  6.0% 64.0%
[libx264 @ 0x7f8fda80e400] mb I  I16..4: 48.9% 34.1% 17.0%
[libx264 @ 0x7f8fda80e400] mb P  I16..4:  8.3%  5.8%  0.4%  P16..4: 27.8%  8.1%  2.6%  0.0%  0.0%    skip:47.0%
[libx264 @ 0x7f8fda80e400] mb B  I16..4:  0.1%  0.0%  0.0%  B16..8: 19.7%  1.3%  0.2%  direct: 0.7%  skip:78.0%  L0:30.7% L1:64.4% BI: 4.9%
[libx264 @ 0x7f8fda80e400] 8x8 transform intra:38.6% inter:82.3%
[libx264 @ 0x7f8fda80e400] coded y,uvDC,uvAC intra: 25.2% 49.4% 10.5% inter: 6.3% 10.4% 0.1%
[libx264 @ 0x7f8fda80e400] i16 v,h,dc,p: 38% 15%  3% 43%
[libx264 @ 0x7f8fda80e400] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 17% 20%  4%  7%  8%  6%  6%  4%
[libx264 @ 0x7f8fda80e400] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 24% 15%  4%  6%  6%  5%  6%  5%
[libx264 @ 0x7f8fda80e400] i8c dc,h,v,p: 61% 22% 13%  4%
[libx264 @ 0x7f8fda80e400] Weighted P-Frames: Y:1.9% UV:0.0%
[libx264 @ 0x7f8fda80e400] ref P L0: 68.6% 17.8% 10.8%  2.8%  0.0%
[libx264 @ 0x7f8fda80e400] ref B L0: 93.2%  6.0%  0.8%
[libx264 @ 0x7f8fda80e400] ref B L1: 98.0%  2.0%
[libx264 @ 0x7f8fda80e400] kb/s:398.29
localhost:ffmpeg StevenLiu$ 
localhost:ffmpeg StevenLiu$ ffmpeg -i output_test
localhost:ffmpeg StevenLiu$ cat output_test.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:2
#EXTINF:4.000000,
output_test2.ts
#EXTINF:1.960000,
output_test3.ts
#EXTINF:4.000000,
output_test4.ts
#EXTINF:4.000000,
output_test5.ts
#EXTINF:1.960000,
output_test6.ts
localhost:ffmpeg StevenLiu$ ffmpeg -i output_test2.ts -i output_test3.ts -i output_test4.ts -i output_test5.ts -i output_test6.ts
ffmpeg version N-82254-g75a1311 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mpegts, from 'output_test2.ts':
  Duration: 00:00:04.00, start: 9.480000, bitrate: 380 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #1, mpegts, from 'output_test3.ts':
  Duration: 00:00:02.00, start: 13.480000, bitrate: 306 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #1:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #2, mpegts, from 'output_test4.ts':
  Duration: 00:00:04.00, start: 1.480000, bitrate: 345 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #2:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #3, mpegts, from 'output_test5.ts':
  Duration: 00:00:04.00, start: 5.480000, bitrate: 527 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #3:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #4, mpegts, from 'output_test6.ts':
  Duration: 00:00:02.00, start: 9.480000, bitrate: 424 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #4:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
At least one output file must be specified
localhost:ffmpeg StevenLiu$ 




I cannot reproduce it here
Last edited 7 years ago by Steven Liu (previous) (diff)

comment:4 by pero, 7 years ago

Hi Stevenliu,

I can see duration differences in your example too.
output_test3.ts and output_test6.ts length is 1.96 sec in the playlist, but ffmpeg reports 2 sec duration.

in reply to:  4 ; comment:5 by Steven Liu, 7 years ago

Replying to pero:

Hi Stevenliu,

I can see duration differences in your example too.
output_test3.ts and output_test6.ts length is 1.96 sec in the playlist, but ffmpeg reports 2 sec duration.

ok, i see, all the last segment have this problem, +0.08s, is that right?

in reply to:  5 comment:6 by pero, 7 years ago

ok, i see, all the last segment have this problem, +0.08s, is that right?

Right. In my case there are 0.08 sec differences

comment:7 by pero, 7 years ago

I checked again the playlists and I realised there are 0.04 sec differences too, but 0.08 sec diff is much more frequently.

in reply to:  7 comment:8 by Steven Liu, 7 years ago

Replying to pero:

I checked again the playlists and I realised there are 0.04 sec differences too, but 0.08 sec diff is much more frequently.

Ah, the last segment is not use split, just use

hls_write_trailer 
AVFormatContext *oc = hls->avf; 
av_write_trailer(oc);

comment:9 by Steven Liu, 7 years ago

let me think how to fix it.

in reply to:  7 comment:10 by Steven Liu, 7 years ago

Replying to pero:

I checked again the playlists and I realised there are 0.04 sec differences too, but 0.08 sec diff is much more frequently.

ok, i have sent a patch into mail list, you can test it.

comment:11 by pero, 7 years ago

Thank you Stevenliu! I applied the patch and now I'm waiting for restarts.

comment:12 by pero, 7 years ago

BTW, is it normal, if I create adaptive stream and I do not use B frames in one of the stream version, than the playlists will differ on restarts? (I main the last segment lenght will be different)
Now as I wrote, as a workaround I use B frames in all the stream version, but it would be great if the stream can have a baseline profile stream for very old clients.

comment:13 by pero, 7 years ago

There was one restart now. Unfortunatelly there is still 0.04 sec difference.

comment:14 by Steven Liu, 7 years ago

i have resent a new patch, it's ok now, please check it carefully.

localhost:hlsenc StevenLiu$ ./ffmpeg -i ~/Movies/objectC/facebook.mp4 -c:v copy -an -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -hls_list_size 0 -t 25 output_test.m3u8
ffmpeg version N-83030-g648c8dc Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 71.100 / 57. 71.100
  libavformat    57. 62.100 / 57. 62.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.22.102
    description     : This File is Created by Easy RealMedia Tools@!
  Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, hls, to 'output_test.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf57.62.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, q=2-31, 797 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[hls @ 0x7fd179001200] hls->dpp = [0.040000]
frame=  627 fps=0.0 q=-1.0 Lsize=N/A time=00:00:24.96 bitrate=N/A speed= 526x    
video:2285kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
localhost:hlsenc StevenLiu$ cat output_test.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:10.000000,
output_test0.ts
#EXTINF:10.000000,
output_test1.ts
#EXTINF:3.240000,
output_test2.ts
#EXTINF:1.840000,
output_test3.ts
localhost:hlsenc StevenLiu$ ffmpeg -i output_test0.ts -i output_test1.ts -i output_test2.ts -i output_test3.ts 
ffmpeg version N-82254-g75a1311 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mpegts, from 'output_test0.ts':
  Duration: 00:00:10.00, start: 1.480000, bitrate: 899 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #1, mpegts, from 'output_test1.ts':
  Duration: 00:00:10.00, start: 11.480000, bitrate: 714 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #1:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #2, mpegts, from 'output_test2.ts':
  Duration: 00:00:03.24, start: 21.480000, bitrate: 456 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #2:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #3, mpegts, from 'output_test3.ts':
  Duration: 00:00:01.84, start: 24.720000, bitrate: 1165 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #3:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
At least one output file must be specified
localhost:hlsenc StevenLiu$ ./ffmpeg -i ~/Movies/objectC/facebook.mp4 -c:v copy -an -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -hls_list_size 0 -t 25 output_test.m3u8
ffmpeg version N-83030-g648c8dc Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 43.100 / 55. 43.100
  libavcodec     57. 71.100 / 57. 71.100
  libavformat    57. 62.100 / 57. 62.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 68.100 /  6. 68.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/StevenLiu/Movies/objectC/facebook.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.22.102
    description     : This File is Created by Easy RealMedia Tools@!
  Duration: 02:00:27.85, start: 0.000000, bitrate: 893 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, 797 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 87 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Output #0, hls, to 'output_test.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf57.62.100
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x480, q=2-31, 797 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[hls @ 0x7fd79f80d800] hls->dpp = [0.040000]
frame=  627 fps=0.0 q=-1.0 Lsize=N/A time=00:00:24.96 bitrate=N/A speed= 817x    
video:2285kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
localhost:hlsenc StevenLiu$ cat output_test.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:10.000000,
output_test0.ts
#EXTINF:10.000000,
output_test1.ts
#EXTINF:3.240000,
output_test2.ts
#EXTINF:1.840000,
output_test3.ts
#EXT-X-DISCONTINUITY
#EXTINF:10.000000,
output_test4.ts
#EXTINF:10.000000,
output_test5.ts
#EXTINF:3.240000,
output_test6.ts
#EXTINF:1.840000,
output_test7.ts
localhost:hlsenc StevenLiu$ ffmpeg -i output_test4.ts -i output_test5.ts -i output_test6.ts -i output_test7.ts 
ffmpeg version N-82254-g75a1311 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mpegts, from 'output_test4.ts':
  Duration: 00:00:10.00, start: 1.480000, bitrate: 899 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #1, mpegts, from 'output_test5.ts':
  Duration: 00:00:10.00, start: 11.480000, bitrate: 714 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #1:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #2, mpegts, from 'output_test6.ts':
  Duration: 00:00:03.24, start: 21.480000, bitrate: 456 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #2:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
Input #3, mpegts, from 'output_test7.ts':
  Duration: 00:00:01.84, start: 24.720000, bitrate: 1165 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #3:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
At least one output file must be specified
localhost:hlsenc StevenLiu$ ffprobe -show_frames -of xml output_test3.ts |grep -r "pict_type=\"B\""
ffprobe version N-82254-g75a1311 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --enable-libass --enable-opengl --enable-libx264 --enable-libmp3lame --enable-gpl --enable-nonfree --prefix=/usr/local --enable-libopencv --enable-libtesseract --enable-libspeex --enable-libfreetype --enable-libfontconfig --enable-libfdk-aac
  libavutil      55. 35.100 / 55. 35.100
  libavcodec     57. 66.101 / 57. 66.101
  libavformat    57. 57.100 / 57. 57.100
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 66.100 /  6. 66.100
  libswscale      4.  3.100 /  4.  3.100
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mpegts, from 'output_test3.ts':
  Duration: 00:00:01.84, start: 24.720000, bitrate: 1165 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2228400" pkt_pts_time="24.760000" pkt_dts="2228400" pkt_dts_time="24.760000" best_effort_timestamp="2228400" best_effort_timestamp_time="24.760000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="12596" pkt_size="81" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="3" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2232000" pkt_pts_time="24.800000" pkt_dts="2232000" pkt_dts_time="24.800000" best_effort_timestamp="2232000" best_effort_timestamp_time="24.800000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="12220" pkt_size="219" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="2" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2235600" pkt_pts_time="24.840000" pkt_dts="2235600" pkt_dts_time="24.840000" best_effort_timestamp="2235600" best_effort_timestamp_time="24.840000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="12784" pkt_size="37" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="4" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2242800" pkt_pts_time="24.920000" pkt_dts="2242800" pkt_dts_time="24.920000" best_effort_timestamp="2242800" best_effort_timestamp_time="24.920000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="13724" pkt_size="75" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="7" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2246400" pkt_pts_time="24.960000" pkt_dts="2246400" pkt_dts_time="24.960000" best_effort_timestamp="2246400" best_effort_timestamp_time="24.960000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="13536" pkt_size="94" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="6" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2250000" pkt_pts_time="25.000000" pkt_dts="2250000" pkt_dts_time="25.000000" best_effort_timestamp="2250000" best_effort_timestamp_time="25.000000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="13912" pkt_size="30" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="8" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2257200" pkt_pts_time="25.080000" pkt_dts="2257200" pkt_dts_time="25.080000" best_effort_timestamp="2257200" best_effort_timestamp_time="25.080000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="15040" pkt_size="90" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="11" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2260800" pkt_pts_time="25.120000" pkt_dts="2260800" pkt_dts_time="25.120000" best_effort_timestamp="2260800" best_effort_timestamp_time="25.120000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="14664" pkt_size="190" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="10" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2264400" pkt_pts_time="25.160000" pkt_dts="2264400" pkt_dts_time="25.160000" best_effort_timestamp="2264400" best_effort_timestamp_time="25.160000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="15228" pkt_size="46" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="12" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2275200" pkt_pts_time="25.280000" pkt_dts="2275200" pkt_dts_time="25.280000" best_effort_timestamp="2275200" best_effort_timestamp_time="25.280000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="24628" pkt_size="39" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="16" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2278800" pkt_pts_time="25.320000" pkt_dts="2278800" pkt_dts_time="25.320000" best_effort_timestamp="2278800" best_effort_timestamp_time="25.320000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="24440" pkt_size="100" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="15" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2289600" pkt_pts_time="25.440000" pkt_dts="2289600" pkt_dts_time="25.440000" best_effort_timestamp="2289600" best_effort_timestamp_time="25.440000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="36660" pkt_size="151" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="19" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2307600" pkt_pts_time="25.640000" pkt_dts="2307600" pkt_dts_time="25.640000" best_effort_timestamp="2307600" best_effort_timestamp_time="25.640000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="80840" pkt_size="3007" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="24" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2318400" pkt_pts_time="25.760000" pkt_dts="2318400" pkt_dts_time="25.760000" best_effort_timestamp="2318400" best_effort_timestamp_time="25.760000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="106408" pkt_size="4328" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="27" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2325600" pkt_pts_time="25.840000" pkt_dts="2325600" pkt_dts_time="25.840000" best_effort_timestamp="2325600" best_effort_timestamp_time="25.840000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="120696" pkt_size="3877" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="29" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2336400" pkt_pts_time="25.960000" pkt_dts="2336400" pkt_dts_time="25.960000" best_effort_timestamp="2336400" best_effort_timestamp_time="25.960000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="145888" pkt_size="3385" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="32" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
(standard input):        <frame media_type="video" stream_index="0" key_frame="0" pkt_pts="2358000" pkt_pts_time="26.200000" pkt_dts="2358000" pkt_dts_time="26.200000" best_effort_timestamp="2358000" best_effort_timestamp_time="26.200000" pkt_duration="3600" pkt_duration_time="0.040000" pkt_pos="202288" pkt_size="3204" width="640" height="480" pix_fmt="yuv420p" pict_type="B" coded_picture_number="38" display_picture_number="0" interlaced_frame="0" top_field_first="0" repeat_pict="0"/>
localhost:hlsenc StevenLiu$ 

comment:15 by pero, 7 years ago

Stevenliu! I think the situation is worse now :) After a restart the FIRST segment are much longer then 4 secs.

Very soon I will try the second patch, but i can see in your example, that there are 10 sec segments, but it should be 4 sec (-hls_time 4)

in reply to:  15 comment:16 by Steven Liu, 7 years ago

Replying to pero:

Stevenliu! I think the situation is worse now :) After a restart the FIRST segment are much longer then 4 secs.

Very soon I will try the second patch, but i can see in your example, that there are 10 sec segments, but it should be 4 sec (-hls_time 4)

No, my test mp4 is not 4s one GOP, so the hls_time 4 is not enabled, it is split by keyframe default. It's not a problem, you could ignore it.

comment:17 by pero, 7 years ago

ok, I applied the new patch. There was one restart until now, and it was working correctly :)
I will wait for more restarts and will report here what happend.

THX!

comment:18 by pero, 7 years ago

Now there were more then 10 restarts and TS lenghts are correct now. It seems like this bug is fixed. Thank you!
But now I found a new problem: all the TS segments are 4 sec long or shorter, but the #EXT-X-TARGETDURATION tag is 5. It should be 4, isn't it?

I think this bug is present since this patch, because i checked archives from yesterday and all playlists have #EXT-X-TARGETDURATION:4

Last edited 7 years ago by pero (previous) (diff)

in reply to:  18 comment:19 by Steven Liu, 7 years ago

Replying to pero:

Now there were more then 10 restarts and TS lenghts are correct now. It seems like this bug is fixed. Thank you!
But now I found a new problem: all the TS segments are 4 sec long or shorter, but the #EXT-X-TARGETDURATION tag is 5. It should be 4, isn't it?

I think this bug is present since this patch, because i checked archives from yesterday and all playlists have #EXT-X-TARGETDURATION:4

ok, you can use the new patch to fix the new problem, it's because use ceil function problem.
you can apply this patch base the before patch.

comment:20 by Steven Liu, 7 years ago

you can test it carefulness ;)

localhost:hlsenc StevenLiu$ ./ffmpeg -v quiet -i ~/Movies/objectC/facebook.mp4 -c:v libx264 -g 50 -an -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -hls_list_size 0 -t 15 output_test.m3u8
localhost:hlsenc StevenLiu$ cat output_test.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
output_test0.ts
#EXTINF:4.000000,
output_test1.ts
#EXTINF:4.000000,
output_test2.ts
#EXTINF:3.000000,
output_test3.ts
localhost:hlsenc StevenLiu$ ./ffmpeg -v quiet -i ~/Movies/objectC/facebook.mp4 -c:v libx264 -g 13 -f hls -hls_time 4 -hls_flags +delete_segments+append_list+omit_endlist -hls_list_size 0 -t 25 output_test.m3u8
localhost:hlsenc StevenLiu$ cat output_test.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
output_test0.ts
#EXTINF:4.000000,
output_test1.ts
#EXTINF:4.000000,
output_test2.ts
#EXTINF:3.000000,
output_test3.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.160000,
output_test4.ts
#EXTINF:4.160000,
output_test5.ts
#EXTINF:4.160000,
output_test6.ts
#EXTINF:3.640000,
output_test7.ts
#EXTINF:4.160000,
output_test8.ts
#EXTINF:3.840000,
output_test9.ts
#EXTINF:0.880000,
output_test10.ts
localhost:hlsenc StevenLiu$ 

comment:21 by pero, 7 years ago

Thank you, everything is OK now. :) Will you merge this to git master?

Unfortunately this was not the reason for JWPlayer issues, but now I think the stream is OK, so I can report this to JWPlayer's support.

May I ask you to test my stream on your Mac if stream switching is working correctly? (​http://madarles.hu/)
I can only try it on an iPad, and it is working prefectly on it. I think the problem only exists on Windows with Chrome or Firefox.

Thank you!

comment:22 by pero, 7 years ago

You can use the timestamp on the right bottom corner as a reference, to check if switching is OK
Maybe on a mac there is no manual switch button, but if you put it in fullscreen, then it should switch to 720p.

comment:23 by Steven Liu, 7 years ago

i cannot use the website better, the network is terrible here, i think you can try a new player named sewise, https://github.com/jackzhang1204/sewise-player

comment:24 by Steven Liu, 7 years ago

Resolution: fixed
Status: openclosed

comment:25 by an_ffmpeg_user, 7 years ago

The OP's issue sounds very similar to https://trac.ffmpeg.org/ticket/5009 regarding the declared EXTINF duration of the last segment in the m3u8. This patch is likely to resolve #5009.

Thanks @stevenliu.

/an_ffmpeg_user

Note: See TracTickets for help on using tickets.