将HLS延迟从+30秒减少

Ric*_*ick 6 nginx http-live-streaming avconv

Ubuntu 12.04

nginx 1.2.4

avconv -version

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
Run Code Online (Sandbox Code Playgroud)

我正在使用avconv和nginx创建一个HLS流,但是现在我的延迟通常超过30秒.经过多次阅读后,我意识到HLS已经内置了延迟,预计会有10秒甚至是首选,但30秒似乎非常极端.

我已经看过很多关于nginx-rtmp谷歌群的讨论,特别是这个帖子有很多建议.我试图通过减少hls_fragment和减少解决我的问题,hls_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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

编辑

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

小智 6

我曾经遇到过同样的问题。我在 nginx.conf 中添加了两个参数,然后延迟减少到 10 秒甚至更少。这是我的conf:

    application hls {
        hls_playlist_length 4s; 
        hls_fragment 1s
    }
Run Code Online (Sandbox Code Playgroud)

但是,我不得不说 10 秒似乎是我们的限制。有什么更好的解决方案吗?

  • 最后,我们完全放弃了 HLS,转而使用 nodejs 服务器,该服务器将通过套接字传递帧。[链接](http://phoboslab.org/log/2013/09/html5-live-video-streaming-via-websockets) (3认同)

bro*_*rod 6

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

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

  • 我给出了这个答案,因为您绝对必须将源关键帧间隔设置为一个低值,否则您将不会像原始问题预期的那样获得低于 10 秒的延迟(并且我不允许添加评论,所以我还能怎么做)尚未明确提及的重要区别?) (3认同)
  • 我觉得这更像是评论而不是答案。 (2认同)