rtmp测试地址_环境搭建RTMP

RTMP 使用的默认端口是 1935

1 大纲

  1. 搭建 RTMP 服务器
  2. 使用 OBS 推流
  3. 使用 VLC 拉流

2 搭建 RTMP 服务器

此处我们使用 Nginx 来搭建服务

  1. 下载 Nginx 源码并编译
  2. 安装 Nginx 的 rtmp 扩展模块
  3. 修改 Nginx 配置并启动服务

2.1 下载 Nginx 源码并编译

#version: nginx-1.19.1.tar.gz
#download: http://nginx.org/download/
tar -zxvf /mnt/share/nginx-1.19.1.tar.gz -C .
cd nginx-1.19.1/
git clone https://github.com/arut/nginx-rtmp-module.git
# 使用 --add-module 来指定安装
./configure --prefix=/root/rtmp-server/nginx-1.19.1/_install --add-module=/root/rtmp-server/nginx-1.19.1/nginx-rtmp-module/
make && make install
# 启动和停止
./_install/sbin/nginx
./_install/sbin/nginx -s stop
  • 编译之前要保证自己的编译环境有pcre pcre-devel zlib zlib-devel openssl openssl-devel的依赖

2.2 安装 Nginx 的 rtmp 扩展模块

  • 下载扩展包 git clone https://github.com/arut/nginx-rtmp-module.git
  • 编译 Nginx 的时候使用--add-module=来指定扩展包的路径
  • 配置文件修改扩展包的路径 location /stat.xsl
  • Gentoo 安装的时候只需添加 RTMP 的 USE 即可

2.3 修改 Nginx 配置并启动服务

用法:
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# ./_install/sbin/nginx -h
nginx version: nginx/1.19.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /root/rtmp-server/nginx-1.19.1/_install/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# ls _install/
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# ls _install/conf/
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1#
  • 可以使用 -c 来指定配置文件
范例:
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# cat /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

                #wzy
                location /stat {
                        rtmp_stat all;
                        rtmp_stat_stylesheet stat.xsl;
                        }
                location /stat.xsl {
                        root /usr/local/nginx-rtmp-module-master/;
                        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

# wzy
rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application vod {
                        play /wzy/;
                }

                application live {
                        live on;
                        record off;
                }
        }
}

root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1#
修改:
# 如果提示 403 错误
user  root;
...
http {
  ...
  server {
    ...
    # wzy
    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
        }
    location /stat.xsl {
        root /root/rtmp-server/nginx-1.19.1/nginx-rtmp-module;
        }
  }
}
...
# wzy
rtmp {
    server {
        listen 1935;
        chunk_size 4096;
        # 点播: /wzy/xxx.mp4
        application vod {
              play /wzy/;
        }
        # 直播
        application live {
              live on;
              record off;
        }
    }
}
启动:
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# ./_install/sbin/nginx
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1# ps aux | grep nginx
root     31036  0.0  0.0  39684   908 ?        Ss   17:41   0:00 nginx: master process ./_install/sbin/nginx
root     31037  0.0  0.0  44516  3824 ?        S    17:41   0:00 nginx: worker process
root     31039  0.0  0.0  11464  1036 pts/1    S+   17:41   0:00 grep --color=auto nginx
root@wzy-VirtualBox:~/rtmp-server/nginx-1.19.1#
  • welcome

    5099c1e4124ef8a743447c594cc5e981.png

  • live[stat]

    751b874f81f9ac7d38de5abbecfce45a.png

3 使用 OBS 推流

  1. OBS Studio 可以使用腾讯电脑管家下载也可以自己百度下载
  2. 打开 OBS->设置->推流,服务选自定义,地址填 rtmp://192.168.16.223/live
  3. 选择媒体源,点击开始推流,目前我自己测试 OBS 使用的是 MP4 格式,不支持 4k,不支持 h264
  • OBS push

    0b54567dd5ece61225aeb794ae8d8f30.png

4 使用 VLC 拉流

  1. 打开 VLC->媒体->打开网络串流->网络,地址填 rtmp://192.168.16.223/live
  • vlc pull

    833f64b4191abea946876c2f05d4b2a4.png

5 RTMP 点播

  1. 将 MP4 文件放置到/wzy/路径下
  2. 打开 VLC->媒体->打开网络串流->网络,地址填 rtmp://192.168.16.223:1935/vod/aaa.mp4
  • vlc vod

    8606f40d1b9ffc180ed3ad79adce36ed.png

  • vod[stat]

    4d22d452b08e31015ca22ae6c798e514.png

- END -

#rtmpdump# #RTMP# #OBS# #推流# #Nginx# #VLC# #点播#

交叉编译のrtmpdump

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值