使用NGINX-RTMP从远程计算机播放视频

时间:2015-04-16 12:35:24

标签: nginx jwplayer

我正在尝试使用带有rtmp协议的nginx-rtmp来传输视频。 我创建了一个index.html,并使用rtmp url在其上嵌入JWPlayer。 在localhost上,当我尝试同样的事情时,我可以从浏览器播放视频但是从同一本地网络中的另一台计算机播放视频(在浏览器中打开index.html,网址为http://172.16.40.162:8080)我收到错误消息。 但是当我尝试使用vlc(rtmp url:rtmp://172.16.40.162/vod/test)时,它可以工作。
这里是index.html的代码

    <!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>VoD Example</title>
        <script src="http://jwpsrv.com/library/s7iNvOAyEeSMdQ4AfQhyIQ.js"></script>
    </head>

<body>
    <div id='videotest'></div>
    <script type='text/javascript'>
        jwplayer('videotest').setup({
        file: 'rtmp://localhost/vod/test',
        width: '50%',
        aspectratio: '16:9'
        });
</script>
</body>
</html>

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       8080;
        server_name  localhost;

        # 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/local/nginx/html;
        }

        # rtmp control
        location /control {
            rtmp_control all;
        }

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

rtmp {
    server {
        listen 1935;
    notify_method get;
    chunk_size 8192;

        application vod {
        allow play all;
        wait_video on;
            play /var/www/Videos;
        push rtmp://localhost/vod/test;
        }
    }
}

我收到以下消息:

acces.log

    172.16.40.148 - - [16/Apr/2015:13:08:33 +0100] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0"
172.16.40.148 [16/Apr/2015:13:19:29 +0100] PLAY "vod" "test" "" - 382 3660906 "" "LNX 9,0,124,2" (1m 58s)
127.0.0.1 [16/Apr/2015:13:51:47 +0100] PLAY "vod" "test" "" - 483 3669724 "http://172.16.40.162:8080/" "LNX 11,2,202,457" (1m 50s)

error.log中

2015/04/16 13:07:06 [notice] 3771#0: using the "epoll" event method
    2015/04/16 13:07:06 [notice] 3771#0: nginx/1.5.0
    2015/04/16 13:07:06 [notice] 3771#0: built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
    2015/04/16 13:07:06 [notice] 3771#0: OS: Linux 2.6.32-504.12.2.el6.x86_64
    2015/04/16 13:07:06 [notice] 3771#0: getrlimit(RLIMIT_NOFILE): 1024:4096
    2015/04/16 13:07:06 [notice] 3772#0: start worker processes
    2015/04/16 13:07:06 [notice] 3772#0: start worker process 3773
    2015/04/16 13:08:41 [info] 3773#0: *3 client closed connection while waiting for request, client: 172.16.40.148, server: 0.0.0.0:8080

我使用的视频信息(我执行了ffmpeg -i test.flv)

    Input #0, flv, from 'test.flv':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42isom
    encoder         : Lavf56.30.100
  Duration: 00:01:50.03, start: 0.060000, bitrate: 270 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 30.30 fps, 30 tbr, 1k tbn, 60 tbc
    Stream #0:1: Audio: mp3, 22050 Hz, stereo, s16p, 64 kb/s

1 个答案:

答案 0 :(得分:2)

index.html中使用file: 'rtmp://localhost/vod/test'替换file: 'rtmp://172.16.40.162/vod/test'

JWPlayer Flash将从客户端计算机请求该URL 。使用localhost显然不起作用,因为它在同一台计算机上查找流。