I'm trying to get ffmpeg to convert a realtime video stream (provided via stdin) to HLS.

ffmpeg -nostdin -i pipe:0 -map i:0x66 -map i:0x67 -f hls -hls_init_time 5 -hls_time 5 -hls_list_size 5 -hls_flags delete_segments -hls_allow_cache 0 -vf yadif -codec libx264 -preset veryfast -tune zerolatency -x264-params keyint=150 -acodec aac -b:a 128k ../output/index.m3u8

It mostly works, but the -hls_time argument appears to be completely ignored, as many of the generated segments are less than 3 seconds long. (In one case, a segment was just over 1 second long)

I initially ran into this issue on ffmpeg 3.4.4, (the highest version released for Ubuntu Bionic Beaver) but I've now built ffmpeg from source and I'm still having the same issue.

$ ffmpeg -version
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

What am I doing wrong?

  • Are any segments greater than 5 seconds? – Gyan Mar 15 at 18:04
  • @Gyan Yes, I have seen some as long as 7 seconds. Based on my input video's framerate of 25fps and keyint=150, if hls_time is using the default value of 2s then segments could be as long as 8 seconds. If hls_time is respected, segments might be up to 11 seconds in length. So this also suggests that hls_time is still using the default value. – Joshua Walsh Mar 16 at 4:27
  • Change to -x264-params keyint=150:min-keyint=150 and check. – Gyan Mar 16 at 5:15
  • @Gyan I set -hls_time 8 -x264-params keyint=100:min-keyint=100 and now my segments all seem to be between 4 and 12 seconds long. It's weird, hls_time does seem to be ignored, but if it's using the default value of 2 and I'm forcing keyframes every 4 seconds, I'd expect every segment to be 4 seconds long exactly. – Joshua Walsh Mar 16 at 7:32
  • It seems it's not ignoring hls_time. I set hls_time to 30 seconds and now my segments are roughly 22 seconds long. – Joshua Walsh Mar 16 at 7:39

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.