我使用此代码从mp4文件创建实时流:
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
但是在流媒体时间,有很长的延迟。
看来,这种延迟存在于具有非常高质量的流式视频上,就像我用于直播的视频(4k)一样。
我如何减少延迟和减少内存使用量呢?
答案 0 :(得分:0)
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.