Forcing FFMPEG to honour segment length in HLS Stream Creator



Published: 2019-04-03 16:59:02 +0000
Categories: BASH,

Language

BASH

Description

HLS Stream Creator uses FFmpeg under the hood in order to create HLS compatible video segments. However, FFmpeg will try to be smart about where it splits segments, so the interval specified on the command line may not always be honoured (depending on where keyframes are located and scenecut believes there's been a scene change).

This can occasionally lead to an annoying situation where segment lengths are significantly longer than expected, which may impact upon delivery

By exporting a couple of flags, however, it's possible to force FFmpeg to segment far closer to (and usually on) the expected interval. Be aware that this can severely impact video quality (which is why it's not forced by default)

Snippet

# Set GOP size to Desired interval (num of frames)
# and Scenecut threshold to 0
FFMPEG_FLAGS='-crf 22 -g [Desired interval] -sc_threshold 0'
export FFMPEG_FLAGS

# Run HLS Stream Creator 
~/repos/HLS-Stream-Creator/HLS-Stream-Creator.sh -i [input file] -s [segment length] -o [output dir]

Usage Example

# Take a 15fps video. We want 1 second segments
# Set GOP size to 15 (1 seconds worth of 15fps video = 15)
# and Scenecut threshold to 0
FFMPEG_FLAGS='-crf 22 -g 15 -sc_threshold 0'
export FFMPEG_FLAGS

# Run HLS Stream Creator
~/repos/HLS-Stream-Creator/HLS-Stream-Creator.sh -i Kazam_screencast_00003.mp4 -s 1 -o test.mp4.hls2

Requires

Video Example

License

BSD-3-Clause

Keywords

FFmpeg, HLS, HTTP Live Streaming, Segment, Fragment, GOP,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter