Opened 6 weeks ago

Last modified 6 weeks ago

#6238 new defect

Wrong first TS segment length in HLS output

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

Description

Hi All!

My original ffmpeg command is very complicated, so I reproduce this bug with a much simplier command, here it is:

ffmpeg -i 720.mp4 -c:a aac -ab 64k -c:v mpeg4 -b:v 1800k -r 25 -g 100 -f hls -hls_time 4 -hls_list_size 5400 -hls_flags +delete_segments+append_list+omit_endlist playlist.m3u8

output:

ffmpeg version N-83894-g4e3cc4b 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. 48.100 / 55. 48.100
  libavcodec     57. 83.100 / 57. 83.100
  libavformat    57. 66.104 / 57. 66.104
  libavdevice    57.  3.100 / 57.  3.100
  libavfilter     6. 76.100 /  6. 76.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '720.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.101
  Duration: 00:44:51.20, start: 0.000000, bitrate: 1858 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1802 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 51 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, hls, to '2/playlist.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.104
    Stream #0:0(und): Video: mpeg4, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1800 kb/s, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.83.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/1800000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC), 16000 Hz, mono, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc57.83.100 aac

the created m3u8:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.064000,
playlist0.ts
#EXTINF:4.000000,
playlist1.ts
#EXTINF:4.000000,
playlist2.ts
#EXTINF:4.000000,
playlist3.ts
#EXTINF:4.000000,
playlist4.ts
#EXTINF:4.000000,
playlist5.ts
#EXTINF:4.000000,
playlist6.ts
#EXTINF:4.000000,
playlist7.ts
#EXTINF:4.000000,

As you can see the first segment is 4.064 sec long, which is wrong.

Thank you!

Attachments (1)

test240.mp4 (2.2 MB) - added by pero 6 weeks ago.

Change History (5)

comment:1 Changed 6 weeks ago by stevenliu

MacBook:book StevenLiu$ ffmpeg -i ~/Movies/objectC/facebook.mp4 -c:a aac -ab 64k -c:v mpeg4 -b:v 1800k -r 25 -g 100 -f hls -hls_time 4 -hls_list_size 5400 -hls_flags +delete_segments+append_list+omit_endlist playlist.m3u8
ffmpeg version N-83894-g4e3cc4b 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 --enable-videotoolbox
  libavutil      55. 48.100 / 55. 48.100
  libavcodec     57. 83.100 / 57. 83.100
  libavformat    57. 66.104 / 57. 66.104
  libavdevice    57.  3.100 / 57.  3.100
  libavfilter     6. 76.100 /  6. 76.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
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, hls, to 'playlist.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    description     : This File is Created by Easy RealMedia Tools@!
    encoder         : Lavf57.66.104
    Stream #0:0(und): Video: mpeg4, yuv420p, 640x480, q=2-31, 1800 kb/s, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.83.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/1800000 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC), 44100 Hz, stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc57.83.100 aac
frame=  613 fps=290 q=2.0 Lsize=N/A time=00:00:24.65 bitrate=N/A speed=11.7x    
video:2234kB audio:194kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[aac @ 0x7f8dcb817600] Qavg: 303.284
MacBook:book StevenLiu$ 
MacBook:book StevenLiu$ cat playlist.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
playlist0.ts
#EXTINF:4.000000,
playlist1.ts
#EXTINF:4.000000,
playlist2.ts
#EXTINF:4.000000,
playlist3.ts
#EXTINF:4.000000,
playlist4.ts
#EXTINF:4.000000,
playlist5.ts
#EXTINF:0.520000,
playlist6.ts
MacBook:book StevenLiu$ 

upload your test 720.mp4 please

Changed 6 weeks ago by pero

comment:2 follow-up: Changed 6 weeks ago by pero

I attached a small test file.

comment:3 in reply to: ↑ 2 Changed 6 weeks ago by stevenliu

Replying to pero:

I attached a small test file.

MacBook:book StevenLiu$ ffmpeg -i ~/Movies/Test/test240.mp4 -an -c:v mpeg4 -b:v 1800k -r 25 -g 100 -f hls -hls_time 4 -hls_list_size 5400 -hls_flags +delete_segments+append_list+omit_endlist playlist.m3u8
ffmpeg version N-83894-g4e3cc4b 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 --enable-videotoolbox
  libavutil      55. 48.100 / 55. 48.100
  libavcodec     57. 83.100 / 57. 83.100
  libavformat    57. 66.104 / 57. 66.104
  libavdevice    57.  3.100 / 57.  3.100
  libavfilter     6. 76.100 /  6. 76.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/Test/test240.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.101
  Duration: 00:01:00.03, start: 0.000000, bitrate: 309 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], 252 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 52 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[mpeg4 @ 0x7fdcf4013600] Invalid pixel aspect ratio 640/639, limit is 255/255 reducing
Output #0, hls, to 'playlist.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.104
    Stream #0:0(und): Video: mpeg4, yuv420p, 426x240 [SAR 1:1 DAR 71:40], q=2-31, 1800 kb/s, SAR 640:639 DAR 16:9, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.83.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/1800000 buffer size: 0 vbv_delay: -1
frame= 1500 fps=1476 q=2.0 Lsize=N/A time=00:00:59.96 bitrate=N/A dup=2 drop=0 speed=  59x    
video:1117kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
MacBook:book StevenLiu$ cat playlist.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
playlist0.ts
#EXTINF:4.000000,
playlist1.ts
#EXTINF:4.000000,
playlist2.ts
#EXTINF:4.000000,
playlist3.ts
#EXTINF:4.000000,
playlist4.ts
#EXTINF:4.000000,
playlist5.ts
#EXTINF:4.000000,
playlist6.ts
#EXTINF:4.000000,
playlist7.ts
#EXTINF:4.000000,
playlist8.ts
#EXTINF:4.000000,
playlist9.ts
#EXTINF:4.000000,
playlist10.ts
#EXTINF:4.000000,
playlist11.ts
#EXTINF:4.000000,
playlist12.ts
#EXTINF:4.000000,
playlist13.ts
#EXTINF:4.000000,
playlist14.ts
MacBook:book StevenLiu$ 
MacBook:book StevenLiu$ 
MacBook:book StevenLiu$ 
MacBook:book StevenLiu$ ffmpeg -i ~/Movies/Test/test240.mp4 -an -c:v mpeg4 -b:v 1800k -r 25 -g 100 -f hls -hls_time 4 -hls_list_size 5400 -hls_flags +delete_segments+append_list+omit_endlist playlist.m3u8
ffmpeg version N-83894-g4e3cc4b 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 --enable-videotoolbox
  libavutil      55. 48.100 / 55. 48.100
  libavcodec     57. 83.100 / 57. 83.100
  libavformat    57. 66.104 / 57. 66.104
  libavdevice    57.  3.100 / 57.  3.100
  libavfilter     6. 76.100 /  6. 76.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/Test/test240.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.101
  Duration: 00:01:00.03, start: 0.000000, bitrate: 309 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 426x240 [SAR 640:639 DAR 16:9], 252 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 52 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[mpeg4 @ 0x7fd078804c00] Invalid pixel aspect ratio 640/639, limit is 255/255 reducing
Output #0, hls, to 'playlist.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.66.104
    Stream #0:0(und): Video: mpeg4, yuv420p, 426x240 [SAR 1:1 DAR 71:40], q=2-31, 1800 kb/s, SAR 640:639 DAR 16:9, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.83.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/1800000 buffer size: 0 vbv_delay: -1
frame= 1500 fps=1157 q=2.0 Lsize=N/A time=00:00:59.96 bitrate=N/A dup=2 drop=0 speed=46.2x    
video:1117kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
MacBook:book StevenLiu$ cat playlist.m3u8 
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
playlist0.ts
#EXTINF:4.000000,
playlist1.ts
#EXTINF:4.000000,
playlist2.ts
#EXTINF:4.000000,
playlist3.ts
#EXTINF:4.000000,
playlist4.ts
#EXTINF:4.000000,
playlist5.ts
#EXTINF:4.000000,
playlist6.ts
#EXTINF:4.000000,
playlist7.ts
#EXTINF:4.000000,
playlist8.ts
#EXTINF:4.000000,
playlist9.ts
#EXTINF:4.000000,
playlist10.ts
#EXTINF:4.000000,
playlist11.ts
#EXTINF:4.000000,
playlist12.ts
#EXTINF:4.000000,
playlist13.ts
#EXTINF:4.000000,
playlist14.ts
#EXT-X-DISCONTINUITY
#EXTINF:4.000000,
playlist15.ts
#EXTINF:4.000000,
playlist16.ts
#EXTINF:4.000000,
playlist17.ts
#EXTINF:4.000000,
playlist18.ts
#EXTINF:4.000000,
playlist19.ts
#EXTINF:4.000000,
playlist20.ts
#EXTINF:4.000000,
playlist21.ts
#EXTINF:4.000000,
playlist22.ts
#EXTINF:4.000000,
playlist23.ts
#EXTINF:4.000000,
playlist24.ts
#EXTINF:4.000000,
playlist25.ts
#EXTINF:4.000000,
playlist26.ts
#EXTINF:4.000000,
playlist27.ts
#EXTINF:4.000000,
playlist28.ts
#EXTINF:4.000000,
playlist29.ts
MacBook:book StevenLiu$ 

Because the audio pts and duration, maybe you can try without audio

comment:4 Changed 6 weeks ago by pero

Thank you!

Yes it is working without audio.
I'm a bit stucked here, because i need the audio. The original sources are two IP cams:

ffmpeg
-rtsp_transport tcp -thread_queue_size 512 -i rtsp://X.X.X.X:555
-rtsp_transport tcp -thread_queue_size 512 -i rtsp://X.X.X.X:556
-filter_complex "[0:v]scale=736:552,crop=w=222:h=552:x=288:y=0[outside];[1:v][outside]overlay=shortest=1:x=5:y=5[pip]"
-map [pip] -map 1:a -c:a aac -ab 64k -c:v h264_nvenc -cbr 1 -b:v 1800k -maxrate 2000k -r 25 -g 100 -bf 2 -refs 4 -no-scenecut 1 -strict_gop 1 -profile:v high -pixel_format yuv420p -preset default
-f hls -hls_time 4 -hls_list_size 5400 -hls_flags +delete_segments+append_list+omit_endlist test.m3u8

I tried to play with setpts, without success

The weird thing is that one of the cams returns this:
Duration: N/A, start: 0.000000, bitrate: N/A

but the other:
Duration: N/A, start: 0.241000, bitrate: N/A

Is it normal?
Can you please suggest something, what I should try to make this work with audio?

THX!

Note: See TracTickets for help on using tickets.