[FFmpeg-user] HLS segment time question

Moritz Barsnick barsnick at gmx.net
Wed Nov 9 19:40:31 EET 2016


On Wed, Nov 09, 2016 at 14:08:22 +0100, Gabor Alsecz wrote:
> Here is my command (i am piping input from memory bitmap):
> ffmpeg -y -loglevel info  -f rawvideo  -pix_fmt bgr24 -video_size 1920x1080
> -framerate 25   -i "-"   -pix_fmt yuv420p -profile:v baseline -hls_time 3
> -hls_list_size 0 -hls_segment_filename file%03d.ts -f hls out.m3u8
[...]
> As you have seen the segments are not 3 seconds long but 10. Any idea why?

I believe the issue is that the hls segmenter will by default only cut
at keyframes. Your input is created at 25 fps, and the libx264 encoder
defaults to a GOP (i.e. keyframe interval) of 250, which happens to 10
seconds. So the hls muxer can only cut at 10 second points.

To cut at arbitrary points, add the muxer option:
  -hls_flags +split_by_time

Unfortunately, the doc for the hls_time option doesn't mention this
(but the doc for the split_by_time flag does mention hls_time!). And it
mentions that some players may have problems with split points which
are not at keyframes, but I'm not sure about that. You can force
keyframes at your cut points by adding the encoder option
  -force_key_frames "expr:gte(t,n_forced*3)"
and you wouldn't even need the "-hls_flags" anymore.

Moritz


More information about the ffmpeg-user mailing list