Reduce Latency For HLS Streaming FFMPEG

13,649

Solution 1

4k video

...

In start of streaming delay exists for few seconds

Yes, of course it does. It takes time to buffer enough data for playback of the very high bitrates. Not only that but your HLS player is typically going to need a few segments before decoding even starts. As @iangetz says, you can reduce the segment length but now you're going to have even more overhead due to all the extra HTTP requests.

Reduce Latency For HLS Streaming

Don't use HLS. HLS, nor any other segmented streaming protocol (like DASH) is optimized for low latency. It's optimized for re-use of HTTP CDNs, for playback that can survive a network change (such as when you go from WiFi to LTE), and for client-selectable (often dynamically) quality.

The very nature of a segmented protocol requires relatively large buffers to be chunked out and then uploaded to the server/CDN individually. This is really useful, but not a good tradeoff if you require low latency.

If latency matters to you, you need an entirely different technology. Take a look at WebRTC. With this technology, the video streams in real time, codecs are optimized for latency over quality, and reliability is reduced in favor of latency. It also requires a significant investment in distribution infrastructure.

I can't imagine a situation where someone who cares about 4k video thinking that a reduction in quality is going to be worth the tradeoff for low latency. You cannot have everything you want... you must choose what is actually important to you and optimize from there. If you want low latency, you're going to have to reduce your quality and spend a lot of money and time on infrastructure to support the effort. If you want high quality and reliable streams, you can keep good encoding parameters while using DASH (or HLS) for distrubtion on existing HTTP-based CDNs.

Solution 2

That is likely the player filling its buffer with enough content before it starts playing.

You could reduce the video segment size with 'hls_time' so each segment downloads faster but this incurs more HTTP requests to your server. Additionally, you can reduce the first segment with 'hls_init_time' and leave other segments as-is.

http://ffmpeg.org/ffmpeg-all.html#hls-1

hls_init_time seconds Set the initial target segment length in seconds. Default value is 0. Segment will be cut on the next key frame after this time has passed on the first m3u8 list. After the initial playlist is filled ffmpeg will cut segments at duration equal to hls_time

hls_time seconds Set the target segment length in seconds. Default value is 2. Segment will be cut on the next key frame after this time has passed.

Another option is to reduce the amount of buffer your player requires before it starts playback. I'm not sure what player you're using but most have this option.

Solution 3

There's now specific options for low latency HLS in ffmpeg. Whilst the 'community' Low Latency (LHLS) is currently supported, in one of the main HLS players (hls.js) there are moves to deprecate it in favour of Apple's latest evolution of their Low Latency HLS.

Share:
13,649
parsa
Author by

parsa

C#, ASP.Net MVC, dotnet core, css, JavaScript, SQL Server, FFMPEG, PHP (Laravel, Yii), MySQL, MongoDB, Angular, WordPrerss, React, Python

Updated on June 04, 2022

Comments

  • parsa
    parsa almost 2 years

    I used hls streaming via ffmpeg.
    In start of streaming delay exists for few seconds.
    when I want to have straming from a 4k video in stream during very delays exist.
    What I can to do?