Search code examples
ffmpeghttp-live-streaming

Making hls files with -hls_time > 10


I am building a local app for watching local videos from the browser, because of some of the videos beeing over 1hour they started to lagg out and using HLS instead of .mp4 solved this.

In the app I'm building the user will often skip 10-40 seconds forward. My question is: Should I use -hls_time 60 or would it be better to just use -hls_time 10

Current code: ffmpeg -i "input.mp4" -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_playlist_type vod -f hls "input\index.m3u8"


Solution

  • Longer segments imply greater segment sizes so after a seek the player might take longer to resume depending on the available bandwidth and whether the required segment has already been retrieved or not.

    If the app is intended for mobile devices where network conditions are expected to vary you will also need to consider adaptive streaming. In this case, with longer segments you will see less quality switching but you risk stalling the playback. You can find a more detailed article here.

    Some observations about your ffmpeg command:

    • don't set the level as it's already auto-calculated if not specified and you risk getting it wrong and messing device compatibility checks.
    • segments are cut only on keyframes and their duration can be greater than the specified hls_time. If you need precise segment durations you need to insert a keyframe at the desired interval.