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

标签 nginx jwplayer

我正在尝试使用 nginx-rtmp 和 rtmp 协议(protocol)来传输视频。 我创建了一个index.html,并在其上嵌入了带有rtmp url 的JWPlayer。 在本地主机上,我可以从浏览器播放视频,但是当我尝试相同的操作(在浏览器中打开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;
        }
    }
}

我收到这些消息:

access.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)

错误日志

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

最佳答案

index.html 中将 file: 'rtmp://localhost/vod/test' 替换为 file: 'rtmp://172.16.40.162/点播/测试'

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

关于nginx - 使用 NGINX-RTMP 从远程计算机播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29674906/

相关文章:

javascript - JW Player 6 寻找和暂停

javascript - 如何从 JW Player 获取媒体 url?

jquery - JWPlayer onComplete 显示一个弹出窗口

jwplayer - 如何在播放前获取视频时长?

php - nginx :allow folder access only from localhost

Nginx 代理 : rewrite rule for root request

django - Nginx Config for 2 django applications 2 different endpoints 1 server host

ruby-on-rails-3 - Assets 未在 Rails 应用程序的生产中加载

nginx - 如何配置 nginx 以显示文件内容而不是下载它?

php - 将数据库中的值插入 JWPlayer 设置 'file' 源