gpt4 book ai didi

nginx - 减少+30秒的HLS延迟

转载 作者:行者123 更新时间:2023-12-04 12:31:46 36 4
gpt4 key购买 nike

Ubuntu 12.04

nginx 1.2.4

avconv版本

avconv version 0.8.10-4:0.8.10-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
built on Feb 6 2014 20:56:59 with gcc 4.6.3
avconv 0.8.10-4:0.8.10-0ubuntu0.12.04.1
libavutil 51. 22. 2 / 51. 22. 2
libavcodec 53. 35. 0 / 53. 35. 0
libavformat 53. 21. 1 / 53. 21. 1
libavdevice 53. 2. 0 / 53. 2. 0
libavfilter 2. 15. 0 / 2. 15. 0
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 52. 0. 0 / 52. 0. 0

我正在使用avconv和nginx创建HLS流,但是现在我的延迟通常超过30秒。经过大量阅读后,我知道HLS具有内置的延迟,并且期望10s,甚至更可取,但30s似乎是非常极端的。

我在nginx-rtmp谷歌论坛上看到了很多讨论,特别是 this线程有很多建议。我试图通过减少 hls_fragmenthls_playlist_length来减少解决我的问题的方法,但是它们并没有起到很大的作用。

nginx.conf:
#user  nobody;
worker_processes 1;

error_log logs/error.log debug;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65;

server {
listen 8888;
server_name localhost;

add_header 'Access-Control-Allow-Origin' "*";

location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp;
}

# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
# you can move stat.xsl to a different location
root /usr/build/nginx-rtmp-module;
}

# rtmp control
location /control {
rtmp_control all;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

rtmp {
server {
listen 1935;
ping 30s;
notify_method get;

application myapp {
live on;

hls on;
hls_path /tmp/hls;
hls_base_url http://x.x.x.x:8888/hls/;
hls_sync 2ms;
hls_fragment 2s;

#hls_variant _low BANDWIDTH=160000;
#hls_variant _mid BANDWIDTH=320000;
#hls_variant _hi BANDWIDTH=640000;
}
}
}

avconv命令:
avconv -r 30 -y -f image2pipe -codec:v mjpeg -i - -f flv -codec:v libx264 -profile:v baseline -preset ultrafast -tune zerolatency -an -f flv rtmp://127.0.0.1:1935/myapp/mystream

编辑

我知道这不是瓶颈,因为我也在使用nginx生成RTMP流。该RTMP流具有非常小的延迟(几秒钟)。

最佳答案

详细说明将hls_playlist减少到4s,将hls_fragment减少到1s的答案很好。但是,请务必注意,如果源视频的关键帧间隔大于hls_fragment长度,则nginx通常将必须创建更长的片段,并且延迟会增加。

我们获得的最低延迟是hls_fragment为1s,源视频关键帧间隔也为1s。通过这些设置,我们实现了不到7秒的延迟。

关于nginx - 减少+30秒的HLS延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24038308/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com