[FFmpeg-trac] #6067(avformat:new): HLS segment length not equal with what m3u8 reports, when ffmpeg restarts

FFmpeg trac at avcodec.org
Sun Jan 8 13:35:35 EET 2017


#6067: HLS segment length not equal with what m3u8 reports, when ffmpeg restarts
----------------------------------+--------------------------------------
             Reporter:  pero      |                     Type:  defect
               Status:  new       |                 Priority:  normal
            Component:  avformat  |                  Version:  git-master
             Keywords:            |               Blocked By:
             Blocking:            |  Reproduced by developer:  0
Analyzed by developer:  0         |
----------------------------------+--------------------------------------
 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!

--
Ticket URL: <https://trac.ffmpeg.org/ticket/6067>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list