Parsa Saei
Parsa Saei

Reputation: 1443

Reduce Latency For HLS Streaming FFMPEG

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?

Upvotes: 4

Views: 21699

Answers (4)

Pierz
Pierz

Reputation: 8168

There's various options to control latency in ffmpeg (see this question for some examples) for HLS and other streaming formats. The 'community' Low Latency (LHLS) was supported in one of the main HLS players (hls.js) but is has now been deprecated it in favour of Apple's Low Latency HLS.

Upvotes: 3

user18726875
user18726875

Reputation:

LHLS isn't that "awesome" in my opinion. See, normally HLS is encoded in 6 seconds long segments, with LHLS it's recommended to set this down to 2 seconds. Now, this is the part where it gets tricky. If you have a bunch of users and a couple of web servers to deliver the segments, what do you think how it will look like if your segments are only 2 sec. long? It will look like your servers are under a DDOS attack as you have to deliver more than 2x the segments as the slicing is down to 2 sec. I personally use 9 second long segments and have my player setup to buffer at least 2-3 minutes of the video. So there is enough time to get the 9 seconds long segments in the background (VideoJS here).

Besides, with 9 seconds long segments, you generating less http requests by the client. If you are running on CloudFlare as your CDN provider for example, maybe with a Cloudflare Load balancer enabled, you also have to pay less as you generate fewer requests, cheers.

Upvotes: 1

Brad
Brad

Reputation: 163612

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.

Upvotes: 12

iangetz
iangetz

Reputation: 512

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.

Upvotes: 5

Related Questions