Opened 7 years ago

Closed 7 years ago

#5988 closed enhancement (fixed)

hls muxer: missing EXT-X-DISCONTINUITY tag after playlist append

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

Description

Hi,
I'd like to stream an ip camera picture as a HLS stream. I run ffmpeg in a bash script in an infinite loop. When the connection to the camera fails, ffmpeg exits and because of the infinite loop ffmpeg tries to reconnect. When it successfully reconnect I want it to append new segments to the existing m3u8 playlist:

ffmpeg -rtsp_transport tcp -i "rtsp://x.x.x.x:554" -an -c:v h264_nvenc -b:v 900k -r 25 -g 100 -no-scenecut 1 -strict_gop 1 -profile:v main -pixel_format yuv420p -preset default -f hls -hls_time 4 -hls_list_size 2700 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start vp20.m3u8

When ffmpeg exits it should omit EXT-X-ENDLIST tag. It's working great with the "omit_endlist" hls_flag
When ffmpeg reconnects successfully it should add EXT-X-DISCONTINUITY tag to the end of the playlist, and after that it should append the new segments. But EXT-X-DISCONTINUITY tag is not added.
Because of the missing EXT-X-DISCONTINUITY tag JWplayer and VideoJS has problems to play the stream after a ffmpeg reconnect.

Thanks!

Change History (14)

comment:1 by Carl Eugen Hoyos, 7 years ago

Keywords: DISCONTINUITY removed
Priority: normalwish
Type: defectenhancement

Please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output to make this a valid ticket.

comment:2 by pero, 7 years ago

It behaves the same with the latest git version.

I simplified ffmpeg parameters a bit:

ffmpeg -rtsp_transport tcp -i "rtsp://x.x.x.x:554/h264/ch1/sub/av_stream" -an -c:v copy -f hls -hls_time 4 -hls_list_size 5 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start output.m3u8

output:

ffmpeg version N-82751-g83a75bf Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: 
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.109 / 57. 66.109
  libavformat    57. 58.101 / 57. 58.101
  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/h264/ch1/sub/av_stream':
  Metadata:
    title           : Media Presentation
  Duration: N/A, start: 0.240800, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt470bg, progressive), 704x576, 25 fps, 25 tbr, 90k tbn, 50 tbc
Output #0, hls, to 'output.m3u8':
  Metadata:
    title           : Media Presentation
    encoder         : Lavf57.58.101
    Stream #0:0: Video: h264 (Main), yuv420p(tv, bt470bg, progressive), 704x576, q=2-31, 25 fps, 25 tbr, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help

comment:3 by Carl Eugen Hoyos, 7 years ago

Version: 3.2.1git-master

comment:4 by Steven Liu, 7 years ago

Owner: set to Steven Liu
Status: newopen

comment:5 by Steven Liu, 7 years ago

Try the new patch from Maillist please, and check is that you want.

[PATCH] avformat/hlsenc: fix ticket id 5988 for DISCONTINUITY

comment:6 by pero, 7 years ago

Thx stevenliu!
I tried your patch, but it's not solve this issue.

Maybe I was not clear enough. If ffmpeg stops at segment output83.ts, than after restart the playlist should be like this:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:81
#EXTINF:4.000,
output81.ts
#EXTINF:4.000,
output82.ts
#EXTINF:2.601089,
output83.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000,
output84.ts
#EXTINF:4.000,
output85.ts

But the EXT-X-DISCONTINUITY tag is missing.

Thanks

comment:7 by Steven Liu, 7 years ago

localhost:hlsenc StevenLiu$
localhost:hlsenc StevenLiu$ rm -rf output*;./ffmpeg -i ~/Movies/objectC/facebook.mp4 -an -c:v copy -f hls -hls_time 4 -hls_list_size 5 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start -t 50 output.m3u8
ffmpeg version N-82759-g1f5630a 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. 41.101 / 55. 41.101
libavcodec 57. 66.109 / 57. 66.109
libavformat 57. 58.101 / 57. 58.101
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.m3u8':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : This File is Created by Easy RealMedia Tools@!
encoder : Lavf57.58.101
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
frame= 1252 fps=0.0 q=-1.0 Lsize=N/A time=00:00:49.96 bitrate=N/A speed= 676x
video:4842kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
localhost:hlsenc StevenLiu$
localhost:hlsenc StevenLiu$ cat output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:9
#EXT-X-MEDIA-SEQUENCE:2
#EXTINF:3.240000,
output2.ts
#EXTINF:8.400000,
output3.ts
#EXTINF:5.480000,
output4.ts
#EXTINF:8.760000,
output5.ts
#EXTINF:4.120000,
output6.ts
localhost:hlsenc StevenLiu$ ./ffmpeg -i ~/Movies/objectC/facebook.mp4 -an -c:v libx264 -g 4 -f hls -hls_time 4 -hls_list_size 5 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start -t 5 output.m3u8
ffmpeg version N-82759-g1f5630a 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. 41.101 / 55. 41.101
libavcodec 57. 66.109 / 57. 66.109
libavformat 57. 58.101 / 57. 58.101
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

[libx264 @ 0x7f9fc8005e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x7f9fc8005e00] profile High, level 3.0
Output #0, hls, to 'output.m3u8':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : This File is Created by Easy RealMedia Tools@!
encoder : Lavf57.58.101
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.109 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= 125 fps= 77 q=-1.0 Lsize=N/A time=00:00:04.88 bitrate=N/A speed=3.02x
video:561kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7f9fc8005e00] frame I:32 Avg QP:17.64 size: 14492
[libx264 @ 0x7f9fc8005e00] frame P:58 Avg QP:21.00 size: 1740
[libx264 @ 0x7f9fc8005e00] frame B:35 Avg QP:17.34 size: 265
[libx264 @ 0x7f9fc8005e00] consecutive B-frames: 56.0% 8.0% 36.0% 0.0%
[libx264 @ 0x7f9fc8005e00] mb I I16..4: 60.6% 25.6% 13.8%
[libx264 @ 0x7f9fc8005e00] mb P I16..4: 10.1% 5.7% 0.3% P16..4: 21.3% 4.9% 0.9% 0.0% 0.0% skip:56.9%
[libx264 @ 0x7f9fc8005e00] mb B I16..4: 0.1% 0.0% 0.0% B16..8: 7.5% 0.4% 0.1% direct: 0.5% skip:91.3% L0:32.4% L1:64.6% BI: 2.9%
[libx264 @ 0x7f9fc8005e00] 8x8 transform intra:27.9% inter:87.9%
[libx264 @ 0x7f9fc8005e00] coded y,uvDC,uvAC intra: 25.0% 46.0% 18.9% inter: 4.4% 9.1% 0.0%
[libx264 @ 0x7f9fc8005e00] i16 v,h,dc,p: 59% 11% 5% 25%
[libx264 @ 0x7f9fc8005e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 17% 16% 5% 6% 8% 5% 6% 4%
[libx264 @ 0x7f9fc8005e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 24% 13% 4% 6% 6% 5% 6% 5%
[libx264 @ 0x7f9fc8005e00] i8c dc,h,v,p: 69% 17% 11% 3%
[libx264 @ 0x7f9fc8005e00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f9fc8005e00] ref P L0: 89.1% 4.5% 5.0% 1.4%
[libx264 @ 0x7f9fc8005e00] ref B L1: 96.0% 4.0%
[libx264 @ 0x7f9fc8005e00] kb/s:918.34
localhost:hlsenc StevenLiu$ cat output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:9
#EXT-X-MEDIA-SEQUENCE:4
#EXTINF:5.480000,
output4.ts
#EXTINF:8.760000,
output5.ts
#EXTINF:4.120000,
output6.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
output7.ts
#EXTINF:0.960000,
output8.ts
localhost:hlsenc StevenLiu$

This is after patch result.
Double check it please.

comment:8 by Steven Liu, 7 years ago

localhost:hlsenc StevenLiu$
localhost:hlsenc StevenLiu$ rm -rf output*;./ffmpeg -i ~/Movies/objectC/facebook.mp4 -an -c:v copy -f hls -hls_time 4 -hls_list_size 5 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start -t 50 output.m3u8
ffmpeg version N-82759-g1f5630a 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. 41.101 / 55. 41.101
libavcodec 57. 66.109 / 57. 66.109
libavformat 57. 58.101 / 57. 58.101
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.m3u8':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : This File is Created by Easy RealMedia Tools@!
encoder : Lavf57.58.101
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
frame= 1252 fps=0.0 q=-1.0 Lsize=N/A time=00:00:49.96 bitrate=N/A speed= 676x
video:4842kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
localhost:hlsenc StevenLiu$
localhost:hlsenc StevenLiu$ cat output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:9
#EXT-X-MEDIA-SEQUENCE:2
#EXTINF:3.240000,
output2.ts
#EXTINF:8.400000,
output3.ts
#EXTINF:5.480000,
output4.ts
#EXTINF:8.760000,
output5.ts
#EXTINF:4.120000,
output6.ts
localhost:hlsenc StevenLiu$ ./ffmpeg -i ~/Movies/objectC/facebook.mp4 -an -c:v libx264 -g 4 -f hls -hls_time 4 -hls_list_size 5 -hls_flags +delete_segments -hls_flags +append_list -hls_flags +omit_endlist -hls_flags +discont_start -t 5 output.m3u8
ffmpeg version N-82759-g1f5630a 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. 41.101 / 55. 41.101
libavcodec 57. 66.109 / 57. 66.109
libavformat 57. 58.101 / 57. 58.101
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

[libx264 @ 0x7f9fc8005e00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0x7f9fc8005e00] profile High, level 3.0
Output #0, hls, to 'output.m3u8':

Metadata:

major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
description : This File is Created by Easy RealMedia Tools@!
encoder : Lavf57.58.101
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.109 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= 125 fps= 77 q=-1.0 Lsize=N/A time=00:00:04.88 bitrate=N/A speed=3.02x
video:561kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7f9fc8005e00] frame I:32 Avg QP:17.64 size: 14492
[libx264 @ 0x7f9fc8005e00] frame P:58 Avg QP:21.00 size: 1740
[libx264 @ 0x7f9fc8005e00] frame B:35 Avg QP:17.34 size: 265
[libx264 @ 0x7f9fc8005e00] consecutive B-frames: 56.0% 8.0% 36.0% 0.0%
[libx264 @ 0x7f9fc8005e00] mb I I16..4: 60.6% 25.6% 13.8%
[libx264 @ 0x7f9fc8005e00] mb P I16..4: 10.1% 5.7% 0.3% P16..4: 21.3% 4.9% 0.9% 0.0% 0.0% skip:56.9%
[libx264 @ 0x7f9fc8005e00] mb B I16..4: 0.1% 0.0% 0.0% B16..8: 7.5% 0.4% 0.1% direct: 0.5% skip:91.3% L0:32.4% L1:64.6% BI: 2.9%
[libx264 @ 0x7f9fc8005e00] 8x8 transform intra:27.9% inter:87.9%
[libx264 @ 0x7f9fc8005e00] coded y,uvDC,uvAC intra: 25.0% 46.0% 18.9% inter: 4.4% 9.1% 0.0%
[libx264 @ 0x7f9fc8005e00] i16 v,h,dc,p: 59% 11% 5% 25%
[libx264 @ 0x7f9fc8005e00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 17% 16% 5% 6% 8% 5% 6% 4%
[libx264 @ 0x7f9fc8005e00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 24% 13% 4% 6% 6% 5% 6% 5%
[libx264 @ 0x7f9fc8005e00] i8c dc,h,v,p: 69% 17% 11% 3%
[libx264 @ 0x7f9fc8005e00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f9fc8005e00] ref P L0: 89.1% 4.5% 5.0% 1.4%
[libx264 @ 0x7f9fc8005e00] ref B L1: 96.0% 4.0%
[libx264 @ 0x7f9fc8005e00] kb/s:918.34
localhost:hlsenc StevenLiu$ cat output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:9
#EXT-X-MEDIA-SEQUENCE:4
#EXTINF:5.480000,
output4.ts
#EXTINF:8.760000,
output5.ts
#EXTINF:4.120000,
output6.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
output7.ts
#EXTINF:0.960000,
output8.ts
localhost:hlsenc StevenLiu$

This is after patch result.
Double check it please.

comment:9 by pero, 7 years ago

Stevenliu, sorry I must have made a mistake. I checked again and it is working now.
I don't know how things are going here. Will this patch be availeble in the next stable release?

Thank you!

comment:10 by Steven Liu, 7 years ago

Resolution: fixed
Status: openclosed

comment:11 by pero, 7 years ago

Resolution: fixed
Status: closedreopened

I found one more problem with this.
If ffmpeg restarts, now the #EXT-X-DISCONTINUITY tag is added to the end of the playlist.
But if ffmpeg restarts again, then it adds #EXT-X-DISCONTINUITY to the end, but the previously added #EXT-X-DISCONTINUITY tag is removed.

comment:12 by Steven Liu, 7 years ago

I've send a new patch base the before patch in the mail list, you can use the patch and test it base the old patch.

comment:13 by pero, 7 years ago

Thank you Steven! It's working perfectly now.

comment:14 by Steven Liu, 7 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.