Search code examples
ffmpeglive-streaminghttp-live-streaming

How to make low latency and have good quality for hls live streaming


I used this code for create live stream from a mp4 file:

ffmpeg -re -i input.mp4 
-c:a aac -c:v libx264 -s uhd2160 -f hls -hls_list_size 0 2160p/out.m3u8  
-c:a aac -c:v libx264 -s 2560x1440 -f hls -hls_list_size 0 1440p/out.m3u8  
-c:a aac -c:v libx264 -s hd1080 -f hls -hls_list_size 0 1080p/out.m3u8  
-c:a aac -c:v libx264 -s hd720 -f hls -hls_list_size 0 720p/out.m3u8  
-c:a aac -c:v libx264 -s hd480 -f hls -hls_list_size 0 480p/out.m3u8  
-c:a aac -c:v libx264 -s nhd  -f hls -hls_list_size 0 360p/out.m3u8 
-c:a aac -c:v libx264 -s cga  -f hls -hls_list_size 0 200p/out.m3u8

but in streaming time, there are very latency.
it seems, this latency exists on streaming videos which have very heigh quality,just like the video(4k) which I used that for livestream.
How can I decrease this delay and decrease memory usage for that?


Solution

  • How to make low latency and have good quality for hls live streaming

    You can't.

    HLS by its very nature is segmented... and relatively large segments at that. The more you try to decrease, the more extreme your overhead becomes. Even then, going under 7 or 8 seconds is very difficult.

    You can switch to technologies geared towards low latency, such as WebRTC, but there are quality trade-offs. With low latency, codecs are optimized in such a way that they favor latency over quality... quality suffers. I don't know what "good quality" is to you, but you'll have to decide what's actually important to you in your application.

    There is no magic video technology that provides low latency, excellent quality, high compatibility, and ease of scaling. It simply doesn't work that way. Give that up, consider what really matters to you, choose the right trade-offs for your scenario, and make a new question if you need help considering the right technology.