Opened 6 years ago

Closed 6 years ago

#7798 closed defect (worksforme)

hls muxer often generates segments shorter than -hls_time

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

Description

Summary of the bug:
I'm using ffmpeg to take realtime video data from stdin and convert it into an HLS live stream. The documentation says that segments will be cut on the next keyframe after hls_time has passed, so effectively hls_time should be a minimum duration for segments. However in practice, I often see segments shorter than hls_time.

How to reproduce:

This is the command line I'm currently using:

% ffmpeg -nostdin -i pipe:0 -map i:0x1ff -map i:0x289 -f hls -hls_init_time 8 -hls_time 30 -hls_list_size 5 -hls_allow_cache 0 -vf yadif -codec libx264 -preset veryfast -tune zerolatency -x264-params keyint=100:min-keyint=100 -acodec libfdk_aac -b:a 128k ../output/index.m3u8
ffmpeg version N-93335-ga8c5ae4 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)
configuration: --enable-gpl --enable-libass --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --arch=x86_64 --cpu=znver1
libavutil      56. 26.100 / 56. 26.100
libavcodec     58. 47.103 / 58. 47.103
libavformat    58. 26.101 / 58. 26.101
libavdevice    58.  6.101 / 58.  6.101
libavfilter     7. 48.100 /  7. 48.100
libswscale      5.  4.100 /  5.  4.100
libswresample   3.  4.100 /  3.  4.100
libpostproc    55.  4.100 / 55.  4.100

Note that this command accepts realtime video input on stdin, if you're trying to reproduce it maybe try something like

% ffmpeg -re -i longtestvideo.mp4 -framerate 25 -f mpegts - | ffmpeg -nostdin -i pipe:0 -map i:0x1ff -map i:0x289 -f hls -hls_init_time 8 -hls_time 30 -hls_list_size 5 -hls_allow_cache 0 -vf yadif -codec libx264 -preset veryfast -tune zerolatency -x264-params keyint=100:min-keyint=100 -acodec libfdk_aac -b:a 128k ../output/index.m3u8

When I look at the generated index*.ts files, (after index5.ts, because index0-5 use hls_init_time instead of hls_time) the durations are between 21 and 34 seconds.

Also with

% ffmpeg -nostdin -i pipe:0 -map i:0x1ff -vf yadif -codec libx264 -preset veryfast -tune zerolatency -map i:0x289 -acodec libfdk_aac -b:a 128k -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 ../output/index.m3u8

the segment duration is sometimes less than 2 seconds.

I have also reproduced this bug on 3.4.4-0ubuntu0.18.04.1 and n4.1.1.

Attachments (1)

ffmpeg-20190316-225841.log (1.6 MB ) - added by Joshua Walsh 6 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by Carl Eugen Hoyos, 6 years ago

Are yadif and libfdk required to reproduce the issue?
Please provide the command line you tested together with the complete, uncut console output to make this a valid ticket.

comment:2 by Joshua Walsh, 6 years ago

Thanks for the feedback. I have reproduced the issue with more minimal settings. It turns out yadif, libfdk, piped input, and stream mapping were all extraneous.

Note that this log is from 3.4.4 on WSL. I don't currently have access to the computer I was building ffmpeg from source on.

$ ffmpeg -nostdin -i ./4minutetest.mp4 -vcodec libx264 -preset veryfast -acodec aac -b:a 128k -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 ./output/index.m3u8
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './4minutetest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:04:00.02, start: 0.000000, bitrate: 5381 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5033 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 342 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
[libx264 @ 0x7fffeb49a300] using SAR=1/1
[libx264 @ 0x7fffeb49a300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7fffeb49a300] profile High, level 4.0
[libx264 @ 0x7fffeb49a300] 264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=24 lookahead_threads=8 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[hls @ 0x7fffeb48e2e0] Opening './output/index0.ts' for writing
Output #0, hls, to './output/index.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.107.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc57.107.100 aac
[hls @ 0x7fffeb48e2e0] Opening './output/index1.ts' for writingA speed=4.66x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index2.ts' for writingA speed=5.18x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index3.ts' for writingA speed= 5.3x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index4.ts' for writingA speed=5.37x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index5.ts' for writingA speed=5.35x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index6.ts' for writingA speed=5.96x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index7.ts' for writingA speed= 6.1x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index8.ts' for writingA speed=5.99x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index9.ts' for writingA speed=5.88x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index10.ts' for writing speed=5.78x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index11.ts' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index12.ts' for writing speed=5.81x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index13.ts' for writing speed= 5.8x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index14.ts' for writing speed=5.86x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index15.ts' for writing speed=5.95x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index16.ts' for writing speed=5.92x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index17.ts' for writing speed=5.95x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index18.ts' for writing speed=6.02x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index19.ts' for writing speed=6.07x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index20.ts' for writing speed=6.08x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index21.ts' for writing speed=6.08x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index22.ts' for writing speed=6.14x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index23.ts' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index24.ts' for writing speed=6.23x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index25.ts' for writing speed=6.26x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index26.ts' for writing speed=6.26x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index27.ts' for writing speed=6.23x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index28.ts' for writing speed=6.18x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index29.ts' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index30.ts' for writing speed=6.17x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index31.ts' for writing speed=6.21x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index32.ts' for writing speed=6.26x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index33.ts' for writing speed=6.27x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index34.ts' for writing speed=6.26x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index35.ts' for writing speed=6.24x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index36.ts' for writing speed=6.17x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index37.ts' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index38.ts' for writing speed=6.17x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index39.ts' for writing speed=6.23x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index40.ts' for writing speed= 6.2x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index41.ts' for writing speed=6.17x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index42.ts' for writing speed=6.15x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index43.ts' for writing speed=6.17x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index44.ts' for writing speed=6.16x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index45.ts' for writing speed=6.16x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index46.ts' for writing speed=6.19x
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writing
[hls @ 0x7fffeb48e2e0] Opening './output/index.m3u8.tmp' for writinged= 6.2x
frame= 6000 fps=155 q=-1.0 Lsize=N/A time=00:04:00.00 bitrate=N/A speed=6.18x
video:119576kB audio:3763kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fffeb49a300] frame I:59    Avg QP:20.09  size:115507
[libx264 @ 0x7fffeb49a300] frame P:2012  Avg QP:22.57  size: 36698
[libx264 @ 0x7fffeb49a300] frame B:3929  Avg QP:24.85  size: 10637
[libx264 @ 0x7fffeb49a300] consecutive B-frames:  3.6% 25.9%  3.6% 66.8%
[libx264 @ 0x7fffeb49a300] mb I  I16..4: 14.8% 57.1% 28.1%
[libx264 @ 0x7fffeb49a300] mb P  I16..4:  9.1% 12.5%  1.6%  P16..4: 28.2% 12.4%  5.6%  0.0%  0.0%    skip:30.7%
[libx264 @ 0x7fffeb49a300] mb B  I16..4:  1.6%  1.6%  0.2%  B16..8: 14.2%  4.3%  0.6%  direct: 4.2%  skip:73.3%  L0:38.5% L1:44.7% BI:16.8%
[libx264 @ 0x7fffeb49a300] 8x8 transform intra:52.7% inter:61.3%
[libx264 @ 0x7fffeb49a300] coded y,uvDC,uvAC intra: 43.5% 35.7% 4.2% inter: 8.5% 8.9% 0.2%
[libx264 @ 0x7fffeb49a300] i16 v,h,dc,p: 36% 43% 15%  7%
[libx264 @ 0x7fffeb49a300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 32% 25%  3%  3%  3%  3%  3%  4%
[libx264 @ 0x7fffeb49a300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 67%  7%  2%  2%  2%  3%  2%  3%
[libx264 @ 0x7fffeb49a300] i8c dc,h,v,p: 59% 19% 19%  3%
[libx264 @ 0x7fffeb49a300] Weighted P-Frames: Y:3.1% UV:1.7%
[libx264 @ 0x7fffeb49a300] kb/s:4081.50
[aac @ 0x7fffeb48c380] Qavg: 228.645

Resulting segments are between 2 and 12 seconds long. I will attach a -report log file shortly.

Last edited 6 years ago by Joshua Walsh (previous) (diff)

by Joshua Walsh, 6 years ago

Attachment: ffmpeg-20190316-225841.log added

comment:3 by Steven Liu, 6 years ago

you should set the GOP and fps for the video codec: -g 125 -r:v 25 125/25 = 5s, every 5 seconds present a keyframe, and the hls will split the segment by the keyframe. looks like the bellow.

liuqideMacBook-Pro:ffmpeg liuqi$ ffmpeg -nostdin -f lavfi -i anullsrc -f lavfi -i nullsrc -vcodec libx264 -g 125 -r:v 25  -preset veryfast -acodec aac -b:a 128k -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 -t 60 ./output/index.m3u8
ffmpeg version N-92522-g370b8bd847 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  configuration: --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-version3 --enable-nonfree --enable-videotoolbox --enable-libxml2
  libavutil      56. 24.101 / 56. 24.101
  libavcodec     58. 40.100 / 58. 40.100
  libavformat    58. 23.100 / 58. 23.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, lavfi, from 'anullsrc':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #0:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
Input #1, lavfi, from 'nullsrc':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #1:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_u8 (native) -> aac (native))
[libx264 @ 0x7f988583e200] using SAR=1/1
[libx264 @ 0x7f988583e200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7f988583e200] profile High, level 1.3
[libx264 @ 0x7f988583e200] 264 - core 148 r2694 3b70645 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=125 keyint_min=12 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[hls @ 0x7f988583dc00] Opening './output/index0.ts' for writing
Output #0, hls, to './output/index.m3u8':
  Metadata:
    encoder         : Lavf58.23.100
    Stream #0:0: Video: h264 (libx264), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=-1--1, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.40.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.40.100 aac
[hls @ 0x7f988583dc00] Opening './output/index1.ts' for writing
[hls @ 0x7f988583dc00] Cannot use rename on non file protocol, this may lead to races and temporary partial files
[hls @ 0x7f988583dc00] Opening './output/index2.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index3.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index4.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index5.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index6.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index7.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index8.ts' for writingA speed=71.4x
[hls @ 0x7f988583dc00] Opening './output/index9.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index10.ts' for writing
[hls @ 0x7f988583dc00] Opening './output/index11.ts' for writing
frame= 1500 fps=0.0 q=-1.0 Lsize=N/A time=00:01:00.00 bitrate=N/A speed=72.4x
video:24kB audio:15kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7f988583e200] frame I:12    Avg QP: 7.25  size:    75
[libx264 @ 0x7f988583e200] frame P:372   Avg QP:10.01  size:    18
[libx264 @ 0x7f988583e200] frame B:1116  Avg QP:12.68  size:    15
[libx264 @ 0x7f988583e200] consecutive B-frames:  0.8%  0.0%  0.0% 99.2%
[libx264 @ 0x7f988583e200] mb I  I16..4: 99.7%  0.0%  0.3%
[libx264 @ 0x7f988583e200] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
[libx264 @ 0x7f988583e200] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%
[libx264 @ 0x7f988583e200] 8x8 transform intra:0.0%
[libx264 @ 0x7f988583e200] coded y,uvDC,uvAC intra: 0.1% 0.3% 0.0% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x7f988583e200] i16 v,h,dc,p: 94%  0%  6%  0%
[libx264 @ 0x7f988583e200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  0%  0% 100%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x7f988583e200] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x7f988583e200] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f988583e200] kb/s:3.19
[aac @ 0x7f988583fa00] Qavg: 65536.000
liuqideMacBook-Pro:ffmpeg liuqi$ cat output/index.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:7
#EXTINF:5.000000,
index7.ts
#EXTINF:5.000000,
index8.ts
#EXTINF:5.000000,
index9.ts
#EXTINF:5.000000,
index10.ts
#EXTINF:5.000000,
index11.ts
#EXT-X-ENDLIST
liuqideMacBook-Pro:ffmpeg liuqi$ ffmpeg -i output/index.m3u8
ffmpeg version N-92522-g370b8bd847 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  configuration: --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-version3 --enable-nonfree --enable-videotoolbox --enable-libxml2
  libavutil      56. 24.101 / 56. 24.101
  libavcodec     58. 40.100 / 58. 40.100
  libavformat    58. 23.100 / 58. 23.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[hls,applehttp @ 0x7fbf07002400] Opening 'output/index7.ts' for reading
Input #0, hls,applehttp, from 'output/index.m3u8':
  Duration: 00:00:25.00, start: 36.402811, bitrate: 0 kb/s
  Program 0
    Metadata:
      variant_bitrate : 0
    Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Metadata:
      variant_bitrate : 0
    Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp
    Metadata:
      variant_bitrate : 0
At least one output file must be specified
liuqideMacBook-Pro:ffmpeg liuqi$
Last edited 6 years ago by Steven Liu (previous) (diff)

comment:4 by Joshua Walsh, 6 years ago

With GOP and fps, this time using Windows binaries:

PS D:\> ffmpeg -nostdin -i ./4minutetest.mp4 -vcodec libx264 -g 125 -r:v 25 -preset veryfast -acodec aac -b:a 128k -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 ./output/index.m3u8
ffmpeg version N-93120-ga84af760b8 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20190212
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 47.100 / 58. 47.100
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './4minutetest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:04:00.02, start: 0.000000, bitrate: 5381 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5033 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 342 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
[libx264 @ 0000019097632080] using SAR=1/1
[libx264 @ 0000019097632080] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000019097632080] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0000019097632080] 264 - core 157 r2935 545de2f - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=24 lookahead_threads=8 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=125 keyint_min=12 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[hls @ 0000019097a81500] Opening './output/index0.ts' for writing
Output #0, hls, to './output/index.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.26.101
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.47.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.47.100 aac
[hls @ 0000019097a81500] Opening './output/index1.ts' for writingspeed=8.83x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index2.ts' for writingspeed=6.93x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index3.ts' for writingspeed=6.83x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index4.ts' for writingspeed=6.46x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index5.ts' for writingspeed=6.44x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index6.ts' for writingspeed=6.86x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index7.ts' for writingspeed= 7.2x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index8.ts' for writingspeed=7.33x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index9.ts' for writingspeed=7.14x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index10.ts' for writingpeed=6.97x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index11.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index12.ts' for writingpeed=6.46x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index13.ts' for writingpeed=6.43x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index14.ts' for writingpeed=6.47x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index15.ts' for writingpeed=6.56x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index16.ts' for writingpeed=6.57x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index17.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index18.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index19.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index20.ts' for writingpeed=6.56x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index21.ts' for writingpeed=6.55x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index22.ts' for writingpeed=6.57x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index23.ts' for writingpeed=6.55x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index24.ts' for writingpeed=6.62x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index25.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index26.ts' for writingpeed=6.76x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index27.ts' for writingpeed=6.78x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index28.ts' for writingpeed=6.74x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index29.ts' for writingpeed=6.69x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index30.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index31.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index32.ts' for writingpeed=6.73x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index33.ts' for writingpeed=6.79x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index34.ts' for writingpeed=6.78x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index35.ts' for writing
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index36.ts' for writingpeed=6.75x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index37.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index38.ts' for writingpeed=6.66x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index39.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index40.ts' for writingpeed=6.74x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index41.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index42.ts' for writingpeed=6.62x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index43.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index44.ts' for writingpeed=6.61x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index45.ts' for writingpeed=6.63x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index46.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index47.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index48.ts' for writingpeed=6.61x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing=6.63x
frame= 6000 fps=165 q=-1.0 Lsize=N/A time=00:04:00.00 bitrate=N/A speed=6.62x
video:122822kB audio:3905kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0000019097632080] frame I:80    Avg QP:19.91  size:115814
[libx264 @ 0000019097632080] frame P:2061  Avg QP:22.66  size: 36890
[libx264 @ 0000019097632080] frame B:3859  Avg QP:24.85  size: 10488
[libx264 @ 0000019097632080] consecutive B-frames:  5.3% 25.5%  4.0% 65.1%
[libx264 @ 0000019097632080] mb I  I16..4: 15.3% 55.1% 29.6%
[libx264 @ 0000019097632080] mb P  I16..4:  9.8% 21.2%  2.5%  P16..4: 22.8%  9.0%  4.1%  0.0%  0.0%    skip:30.7%
[libx264 @ 0000019097632080] mb B  I16..4:  1.6%  3.0%  0.3%  B16..8: 13.2%  3.7%  0.5%  direct: 3.8%  skip:74.0%  L0:38.7% L1:44.9% BI:16.4%
[libx264 @ 0000019097632080] 8x8 transform intra:62.4% inter:56.8%
[libx264 @ 0000019097632080] coded y,uvDC,uvAC intra: 51.6% 35.9% 4.3% inter: 6.7% 7.1% 0.1%
[libx264 @ 0000019097632080] i16 v,h,dc,p: 35% 41% 14% 11%
[libx264 @ 0000019097632080] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 31% 20%  4%  4%  4%  4%  4%  5%
[libx264 @ 0000019097632080] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 60%  7%  3%  3%  3%  3%  3%  3%
[libx264 @ 0000019097632080] i8c dc,h,v,p: 57% 19% 20%  4%
[libx264 @ 0000019097632080] Weighted P-Frames: Y:3.0% UV:1.5%
[libx264 @ 0000019097632080] kb/s:4192.30
[aac @ 0000019097c40980] Qavg: 693.003
PS D:\> Get-Content .\output\index.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:44
#EXTINF:5.000000,
index44.ts
#EXTINF:4.360000,
index45.ts
#EXTINF:5.520000,
index46.ts
#EXTINF:5.000000,
index47.ts
#EXTINF:4.160000,
index48.ts
#EXT-X-ENDLIST

Segment duration ranges from 2 seconds to 9 seconds.

(Also, setting GOP shouldn't be necessary based on the documentation's description of -hls_time)

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

Replying to JoshuaWalsh:

With GOP and fps, this time using Windows binaries:

PS D:\> ffmpeg -nostdin -i ./4minutetest.mp4 -vcodec libx264 -g 125 -r:v 25 -preset veryfast -acodec aac -b:a 128k -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_allow_cache 0 ./output/index.m3u8
ffmpeg version N-93120-ga84af760b8 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20190212
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 47.100 / 58. 47.100
  libavformat    58. 26.101 / 58. 26.101
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './4minutetest.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:04:00.02, start: 0.000000, bitrate: 5381 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5033 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 342 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
[libx264 @ 0000019097632080] using SAR=1/1
[libx264 @ 0000019097632080] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000019097632080] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 0000019097632080] 264 - core 157 r2935 545de2f - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=24 lookahead_threads=8 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=125 keyint_min=12 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[hls @ 0000019097a81500] Opening './output/index0.ts' for writing
Output #0, hls, to './output/index.m3u8':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.26.101
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.47.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.47.100 aac
[hls @ 0000019097a81500] Opening './output/index1.ts' for writingspeed=8.83x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index2.ts' for writingspeed=6.93x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index3.ts' for writingspeed=6.83x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index4.ts' for writingspeed=6.46x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index5.ts' for writingspeed=6.44x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index6.ts' for writingspeed=6.86x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index7.ts' for writingspeed= 7.2x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index8.ts' for writingspeed=7.33x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index9.ts' for writingspeed=7.14x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index10.ts' for writingpeed=6.97x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index11.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index12.ts' for writingpeed=6.46x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index13.ts' for writingpeed=6.43x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index14.ts' for writingpeed=6.47x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index15.ts' for writingpeed=6.56x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index16.ts' for writingpeed=6.57x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index17.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index18.ts' for writingpeed=6.54x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index19.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index20.ts' for writingpeed=6.56x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index21.ts' for writingpeed=6.55x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index22.ts' for writingpeed=6.57x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index23.ts' for writingpeed=6.55x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index24.ts' for writingpeed=6.62x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index25.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index26.ts' for writingpeed=6.76x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index27.ts' for writingpeed=6.78x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index28.ts' for writingpeed=6.74x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index29.ts' for writingpeed=6.69x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index30.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index31.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index32.ts' for writingpeed=6.73x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index33.ts' for writingpeed=6.79x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index34.ts' for writingpeed=6.78x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index35.ts' for writing
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index36.ts' for writingpeed=6.75x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index37.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index38.ts' for writingpeed=6.66x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index39.ts' for writingpeed=6.68x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index40.ts' for writingpeed=6.74x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index41.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index42.ts' for writingpeed=6.62x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index43.ts' for writingpeed=6.65x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index44.ts' for writingpeed=6.61x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index45.ts' for writingpeed=6.63x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index46.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index47.ts' for writingpeed=6.59x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index48.ts' for writingpeed=6.61x
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing
[hls @ 0000019097a81500] Opening './output/index.m3u8.tmp' for writing=6.63x
frame= 6000 fps=165 q=-1.0 Lsize=N/A time=00:04:00.00 bitrate=N/A speed=6.62x
video:122822kB audio:3905kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0000019097632080] frame I:80    Avg QP:19.91  size:115814
[libx264 @ 0000019097632080] frame P:2061  Avg QP:22.66  size: 36890
[libx264 @ 0000019097632080] frame B:3859  Avg QP:24.85  size: 10488
[libx264 @ 0000019097632080] consecutive B-frames:  5.3% 25.5%  4.0% 65.1%
[libx264 @ 0000019097632080] mb I  I16..4: 15.3% 55.1% 29.6%
[libx264 @ 0000019097632080] mb P  I16..4:  9.8% 21.2%  2.5%  P16..4: 22.8%  9.0%  4.1%  0.0%  0.0%    skip:30.7%
[libx264 @ 0000019097632080] mb B  I16..4:  1.6%  3.0%  0.3%  B16..8: 13.2%  3.7%  0.5%  direct: 3.8%  skip:74.0%  L0:38.7% L1:44.9% BI:16.4%
[libx264 @ 0000019097632080] 8x8 transform intra:62.4% inter:56.8%
[libx264 @ 0000019097632080] coded y,uvDC,uvAC intra: 51.6% 35.9% 4.3% inter: 6.7% 7.1% 0.1%
[libx264 @ 0000019097632080] i16 v,h,dc,p: 35% 41% 14% 11%
[libx264 @ 0000019097632080] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 31% 20%  4%  4%  4%  4%  4%  5%
[libx264 @ 0000019097632080] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 60%  7%  3%  3%  3%  3%  3%  3%
[libx264 @ 0000019097632080] i8c dc,h,v,p: 57% 19% 20%  4%
[libx264 @ 0000019097632080] Weighted P-Frames: Y:3.0% UV:1.5%
[libx264 @ 0000019097632080] kb/s:4192.30
[aac @ 0000019097c40980] Qavg: 693.003
PS D:\> Get-Content .\output\index.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:NO
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:44
#EXTINF:5.000000,
index44.ts
#EXTINF:4.360000,
index45.ts
#EXTINF:5.520000,
index46.ts
#EXTINF:5.000000,
index47.ts
#EXTINF:4.160000,
index48.ts
#EXT-X-ENDLIST

Segment duration ranges from 2 seconds to 9 seconds.

(Also, setting GOP shouldn't be necessary based on the documentation's description of -hls_time)

your output is near 5s,

if you want segment duration at 5, you can try -hls_time witn -hls_flags split_by_time, but i don't suggest this option, because it maybe not split at keyframe.

comment:6 by Joshua Walsh, 6 years ago

Per documentation, the segments should each be longer than 5 seconds and not just near to it, with the exception of the last segment which obviously will be constrained by the end of the input. Either the documentation is wrong, or the behaviour is wrong. I believe it's the behaviour that's wrong, because sometimes segments are significantly shorter, as noted in my original post

Last edited 6 years ago by Joshua Walsh (previous) (diff)

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

can you upload the 4minutetest.mp4 here?

comment:8 by Joshua Walsh, 6 years ago

Unfortunately it is non-free and I don't think I can share it. It's a news broadcast, so there are quite frequent scene changes between studio and live reporters, video clips, camera angle changes. I think the issue should be reproduceable with any content of this type.

I'm away at the moment but if nobody else can reproduce it I will try to produce a free test video that repros it once I get back.

Last edited 6 years ago by Joshua Walsh (previous) (diff)

comment:9 by Steven Liu, 6 years ago

the hlsenc split the segment:
If there have video stream, get current packet video, if the packet pts - the start of the segment pts is large than hls_time, and the packet flags is key, then close current file and open new file for the next segment.

for example, if the source video keyframe is looks like this:
kpppppppppkpppppppppkppppppppp
if the fps is 5 and gop is 10, then the segment duration is 2
if the source keyframe is looks like this:
kppkppppppppkpppppppkpppkppkppp
the 1st segment is: 12frames, fps is 5, 200ms per frame, 2.400000s, the 2nd segment is 1.600000s

if you want segment duration is 5s, the gop should right:

-g 125 -r:v 25 is the basic setting,
if you don't want set the gop, maybe use -hls_flags split_by_time can fix the problem, but that maybe have a new probem ,the start packet is not keyframe of the segment;

or you can submit a patch to fix the problem if you think that is a problem.

try the git master version please.

Last edited 6 years ago by Steven Liu (previous) (diff)

comment:10 by Steven Liu, 6 years ago

liuqideMacBook-Pro:dash liuqi$ mkdir output; ffmpeg -i ~/Movies/Test/bbb_sunflower_1080p_30fps_normal.mp4 -c:v libx264 -g 125 -r:v 25 -x264opts scenecut=0:keyint_min=125 -f hls -hls_time 5 -hls_list_size 0 -preset veryfast -t 60 output/output.m3u8
mkdir: output: File exists
ffmpeg version N-92522-g370b8bd847 Copyright (c) 2000-2018 the FFmpeg developers

built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-version3 --enable-nonfree --enable-videotoolbox --enable-libxml2
libavutil 56. 24.101 / 56. 24.101
libavcodec 58. 40.100 / 58. 40.100
libavformat 58. 23.100 / 58. 23.100
libavdevice 58. 6.100 / 58. 6.100
libavfilter 7. 46.100 / 7. 46.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/liuqi/Movies/Test/bbb_sunflower_1080p_30fps_normal.mp4':

Metadata:

major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2013-12-16T17:44:39.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: 3481 kb/s

Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2998 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
Metadata:

creation_time : 2013-12-16T17:44:39.000000Z
handler_name : GPAC ISO Video Handler

Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
Metadata:

creation_time : 2013-12-16T17:44:42.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-16T17:44:42.000000Z
handler_name : GPAC ISO Audio Handler

Side data:

audio service type: main

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:2 -> #0:1 (ac3 (native) -> aac (native))

Press [q] to stop, ? for help
[libx264 @ 0x7fb2d980d800] using SAR=1/1
[libx264 @ 0x7fb2d980d800] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fb2d980d800] profile High, level 4.0
[libx264 @ 0x7fb2d980d800] 264 - core 148 r2694 3b70645 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=125 keyint_min=63 scenecut=0 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[aac @ 0x7fb2d980f000] Using a PCE to encode channel layout "5.1(side)"
[hls @ 0x7fb2d9801000] Opening 'output/output0.ts' for writing
Output #0, hls, to 'output/output.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 : Lavf58.23.100
Stream #0:0(und): Video: h264 (libx264), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc (default)
Metadata:

creation_time : 2013-12-16T17:44:39.000000Z
handler_name : GPAC ISO Video Handler
encoder : Lavc58.40.100 libx264

Side data:

cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

Stream #0:1(und): Audio: aac (LC), 48000 Hz, 5.1(side), fltp, 394 kb/s (default)
Metadata:

creation_time : 2013-12-16T17:44:42.000000Z
handler_name : GPAC ISO Audio Handler
encoder : Lavc58.40.100 aac

Side data:

audio service type: main

[hls @ 0x7fb2d9801000] Opening 'output/output1.ts' for writing/A dup=2 drop=26 speed=2.03x
[hls @ 0x7fb2d9801000] Cannot use rename on non file protocol, this may lead to races and temporary partial files
[hls @ 0x7fb2d9801000] Opening 'output/output2.ts' for writing/A dup=2 drop=48 speed=1.81x
[hls @ 0x7fb2d9801000] Opening 'output/output3.ts' for writing/A dup=2 drop=73 speed=1.76x
[hls @ 0x7fb2d9801000] Opening 'output/output4.ts' for writing/A dup=2 drop=102 speed=1.69x
[hls @ 0x7fb2d9801000] Opening 'output/output5.ts' for writing/A dup=2 drop=126 speed=1.78x
[hls @ 0x7fb2d9801000] Opening 'output/output6.ts' for writing/A dup=2 drop=149 speed=1.77x
[hls @ 0x7fb2d9801000] Opening 'output/output7.ts' for writing/A dup=2 drop=175 speed= 1.7x
[hls @ 0x7fb2d9801000] Opening 'output/output8.ts' for writing/A dup=2 drop=200 speed=1.66x
[hls @ 0x7fb2d9801000] Opening 'output/output9.ts' for writing/A dup=2 drop=224 speed=1.56x
[hls @ 0x7fb2d9801000] Opening 'output/output10.ts' for writingA dup=2 drop=249 speed=1.56x
[hls @ 0x7fb2d9801000] Opening 'output/output11.ts' for writingA dup=2 drop=276 speed=1.55x
frame= 1500 fps= 39 q=-1.0 Lsize=N/A time=00:01:00.01 bitrate=N/A dup=2 drop=298 speed=1.57x
video:19037kB audio:2891kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fb2d980d800] frame I:12 Avg QP:17.25 size:251213
[libx264 @ 0x7fb2d980d800] frame P:415 Avg QP:21.68 size: 32557
[libx264 @ 0x7fb2d980d800] frame B:1073 Avg QP:25.25 size: 2765
[libx264 @ 0x7fb2d980d800] consecutive B-frames: 2.5% 4.8% 4.4% 88.3%
[libx264 @ 0x7fb2d980d800] mb I I16..4: 23.3% 19.6% 57.1%
[libx264 @ 0x7fb2d980d800] mb P I16..4: 5.0% 2.2% 0.8% P16..4: 30.1% 12.0% 7.3% 0.0% 0.0% skip:42.5%
[libx264 @ 0x7fb2d980d800] mb B I16..4: 0.4% 0.1% 0.0% B16..8: 6.5% 1.7% 0.2% direct: 2.2% skip:88.9% L0:35.2% L1:46.8% BI:18.1%
[libx264 @ 0x7fb2d980d800] 8x8 transform intra:24.8% inter:45.5%
[libx264 @ 0x7fb2d980d800] coded y,uvDC,uvAC intra: 34.2% 44.6% 21.0% inter: 5.7% 6.1% 0.8%
[libx264 @ 0x7fb2d980d800] i16 v,h,dc,p: 69% 19% 8% 4%
[libx264 @ 0x7fb2d980d800] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 21% 28% 4% 5% 5% 5% 5% 5%
[libx264 @ 0x7fb2d980d800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 13% 10% 9% 9% 10% 8% 12% 9%
[libx264 @ 0x7fb2d980d800] i8c dc,h,v,p: 60% 19% 15% 6%
[libx264 @ 0x7fb2d980d800] Weighted P-Frames: Y:4.6% UV:4.3%
[libx264 @ 0x7fb2d980d800] kb/s:2599.04
[aac @ 0x7fb2d980f000] Qavg: 192.171
liuqideMacBook-Pro:dash liuqi$ cat output/output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:5.000000,
output0.ts
#EXTINF:5.000000,
output1.ts
#EXTINF:5.000000,
output2.ts
#EXTINF:5.000000,
output3.ts
#EXTINF:5.000000,
output4.ts
#EXTINF:5.000000,
output5.ts
#EXTINF:5.000000,
output6.ts
#EXTINF:5.000000,
output7.ts
#EXTINF:5.000000,
output8.ts
#EXTINF:5.000000,
output9.ts
#EXTINF:5.000000,
output10.ts
#EXTINF:5.000000,
output11.ts
#EXT-X-ENDLIST
liuqideMacBook-Pro:dash liuqi$

use https://peach.blender.org/download/

comment:11 by Joshua Walsh, 6 years ago

Tried using Git master in my original post, but I haven't had access to my work PC since then so wasn't set up to build from source.

I want segment duration >= 5s, it doesn't need to be 5s exactly. I don't want to force GOP and I don't want to disable scenecut.

If the packet pts - the start of the segment pts is large than hls_time, and the packet flags is key, then close current file and open new file for the next segment

I don't understand how this can produce segments shorter than -hls_time, since packet pts - start of segment pts will be less than hls_time.

With your second example:

kppkppppppppkpppppppkpppkppkppp

First segment is
kppkpppppppp
That makes sense. Remaining data is:
kpppppppkpppkppkppp
But to produce a second segment of 1.6s length:
kppppppp
would require splitting while packet pts - seg start pts < hls_time, no? If respecting hls_time, second segment should be
kpppppppkpppkppkppp (2.4s again)

I'm happy to try to write a patch, but I'm not a C/C++ developer so it's difficult for me to get my head around ffmpeg's internals.

Last edited 6 years ago by Joshua Walsh (previous) (diff)

in reply to:  11 comment:12 by Steven Liu, 6 years ago

Replying to JoshuaWalsh:

Tried using Git master in my original post, but I haven't had access to my work PC since then so wasn't set up to build from source.

I want segment duration >= 5s, it doesn't need to be 5s exactly. I don't want to force GOP and I don't want to disable scenecut.

If the packet pts - the start of the segment pts is large than hls_time, and the packet flags is key, then close current file and open new file for the next segment

I don't understand how this can produce segments shorter than -hls_time, since packet pts - start of segment pts will be less than hls_time.

With your second example:

kppkppppppppkpppppppkpppkppkppp

First segment is
kppkpppppppp
That makes sense. Remaining data is:
kpppppppkpppkppkppp
But to produce a second segment of 1.6s length:
kppppppp
would require splitting while packet pts - seg start pts < hls_time, no? If respecting hls_time, second segment should be
kpppppppkpppkppkppp (2.4s again)

No, the end_pts is compute by (segment numbers * hls_time), maybe this is not good, but this is allowed by users pass several years.
because the keyframe position is not standard, if you want hlsenc split at 5, you should try hls_flags split_by_time

I'm happy to try to write a patch, but I'm not a C/C++ developer so it's difficult for me to get my head around ffmpeg's internals.

liuqideMacBook-Pro:dash liuqi$ mkdir output; ffmpeg -i ~/Movies/Test/bbb_sunflower_1080p_30fps_normal.mp4 -c:v libx264 -f hls -hls_time 5 -hls_flags split_by_time -hls_list_size 0 -preset veryfast -t 60 -an output/output.m3u8
mkdir: output: File exists
ffmpeg version N-92522-g370b8bd847 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  configuration: --enable-fontconfig --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libspeex --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-version3 --enable-nonfree --enable-videotoolbox --enable-libxml2
  libavutil      56. 24.101 / 56. 24.101
  libavcodec     58. 40.100 / 58. 40.100
  libavformat    58. 23.100 / 58. 23.100
  libavdevice    58.  6.100 / 58.  6.100
  libavfilter     7. 46.100 /  7. 46.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/liuqi/Movies/Test/bbb_sunflower_1080p_30fps_normal.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2013-12-16T17:44:39.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: 3481 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 2998 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2013-12-16T17:44:39.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
      creation_time   : 2013-12-16T17:44:42.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-16T17:44:42.000000Z
      handler_name    : GPAC ISO Audio Handler
    Side data:
      audio service type: main
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x7fb098807600] using SAR=1/1
[libx264 @ 0x7fb098807600] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fb098807600] profile High, level 4.0
[libx264 @ 0x7fb098807600] 264 - core 148 r2694 3b70645 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[hls @ 0x7fb098805600] Opening 'output/output0.ts' for writing
Output #0, hls, to 'output/output.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         : Lavf58.23.100
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 90k tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2013-12-16T17:44:39.000000Z
      handler_name    : GPAC ISO Video Handler
      encoder         : Lavc58.40.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[hls @ 0x7fb098805600] Opening 'output/output1.ts' for writing/A dup=2 drop=0 speed=1.87x
[hls @ 0x7fb098805600] Cannot use rename on non file protocol, this may lead to races and temporary partial files
[hls @ 0x7fb098805600] Opening 'output/output2.ts' for writing/A dup=2 drop=0 speed=1.69x
[hls @ 0x7fb098805600] Opening 'output/output3.ts' for writing/A dup=2 drop=0 speed=1.58x
[hls @ 0x7fb098805600] Opening 'output/output4.ts' for writing/A dup=2 drop=0 speed=1.55x
[hls @ 0x7fb098805600] Opening 'output/output5.ts' for writing/A dup=2 drop=0 speed=1.64x
[hls @ 0x7fb098805600] Opening 'output/output6.ts' for writing/A dup=2 drop=0 speed=1.65x
[hls @ 0x7fb098805600] Opening 'output/output7.ts' for writing/A dup=2 drop=0 speed=1.58x
[hls @ 0x7fb098805600] Opening 'output/output8.ts' for writing/A dup=2 drop=0 speed=1.54x
[hls @ 0x7fb098805600] Opening 'output/output9.ts' for writing/A dup=2 drop=0 speed=1.52x
[hls @ 0x7fb098805600] Opening 'output/output10.ts' for writingA dup=2 drop=0 speed=1.54x
[hls @ 0x7fb098805600] Opening 'output/output11.ts' for writingA dup=2 drop=0 speed=1.52x
frame= 1800 fps= 46 q=-1.0 Lsize=N/A time=00:00:59.93 bitrate=N/A dup=2 drop=0 speed=1.54x
video:17525kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fb098807600] frame I:12    Avg QP:15.83  size:227217
[libx264 @ 0x7fb098807600] frame P:487   Avg QP:22.42  size: 25400
[libx264 @ 0x7fb098807600] frame B:1301  Avg QP:25.88  size:  2190
[libx264 @ 0x7fb098807600] consecutive B-frames:  2.1%  3.4%  3.3% 91.1%
[libx264 @ 0x7fb098807600] mb I  I16..4: 38.3% 14.1% 47.6%
[libx264 @ 0x7fb098807600] mb P  I16..4:  3.6%  1.7%  0.2%  P16..4: 29.7% 11.6%  6.7%  0.0%  0.0%    skip:46.5%
[libx264 @ 0x7fb098807600] mb B  I16..4:  0.3%  0.1%  0.0%  B16..8:  5.4%  1.3%  0.2%  direct: 2.0%  skip:90.8%  L0:36.9% L1:45.3% BI:17.8%
[libx264 @ 0x7fb098807600] 8x8 transform intra:25.3% inter:46.9%
[libx264 @ 0x7fb098807600] coded y,uvDC,uvAC intra: 28.5% 39.2% 17.2% inter: 4.7% 5.3% 0.6%
[libx264 @ 0x7fb098807600] i16 v,h,dc,p: 68% 19%  9%  4%
[libx264 @ 0x7fb098807600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 21% 29%  3%  5%  5%  5%  4%  5%
[libx264 @ 0x7fb098807600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 12% 11%  8%  9% 10%  8% 13%  9%
[libx264 @ 0x7fb098807600] i8c dc,h,v,p: 63% 18% 15%  5%
[libx264 @ 0x7fb098807600] Weighted P-Frames: Y:3.3% UV:3.3%
[libx264 @ 0x7fb098807600] kb/s:2392.71
liuqideMacBook-Pro:dash liuqi$ cat output/output.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:5.000000,
output0.ts
#EXTINF:5.000000,
output1.ts
#EXTINF:5.000000,
output2.ts
#EXTINF:4.933333,
output3.ts
#EXTINF:4.966667,
output4.ts
#EXTINF:5.000000,
output5.ts
#EXTINF:5.066667,
output6.ts
#EXTINF:4.966667,
output7.ts
#EXTINF:5.066667,
output8.ts
#EXTINF:5.000000,
output9.ts
#EXTINF:4.900000,
output10.ts
#EXTINF:5.100000,
output11.ts
#EXT-X-ENDLIST
liuqideMacBook-Pro:dash liuqi$

comment:13 by Steven Liu, 6 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.