nginx + rtmp 搭建流媒体服务器,手机推流,vlc拉流

    xiaoxiao2022-07-04  103

    1 服务器部分

    1.1 路径说明

    路径:/usr/local/src

    1.2 下载nginx-rtmp-module (我这里的目录是在/usr/local/src/下面)

    cd /usr/local/src

    nginx-rtmp-module的官方github地址:https://github.com/arut/nginx-rtmp-module

    git clone https://github.com/arut/nginx-rtmp-module.git

    ( 如果没有git进行安装,yum install git)

    1.3 nginx版本及安装

    下载 nginx-1.17.0.tar.gz 解压并安装(如果下载不到请自行查找)

    wget http://nginx.org/download/nginx-1.17.0.tar.gz

      解压:

    tar -zxvf nginx-1.17.0.tar.gz

       进入目录:

    cd nginx-1.17.0 ./configure --prefix=/usr/local/src/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module make && make install

    1.4 修改nginx配置文件

    nano /usr/local/src/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; } #1----------------------------------------- rtmp { server { listen 1935; chunk_size 4000; application cctvf { live on; hls on; hls_path /usr/local/src/nginx/html/cctvf; hls_fragment 5s; } } } #1end-------------------------------------- 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 85; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #2.---------------------------------------------------- location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root /usr/local/src/nginx-rtmp-module/; } #2 end------------------------------------------------- #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; # } #} }

    1.5 nginx运行与停止

    停止:

    ./usr/local/src/nginx/sbin/nginx -s stop

    运行:

    ./usr/local/src/nginx/sbin/nginx

    2 验证

    用浏览器打开http://ip:85

    正常的话,会显示以下页面:

    3 推流

    我使用手机推流。涂黑的是服务器IP。1935是端口。cctvf是nginx的application名字。

    app可以使用杏林推流。这个app是在应用商店里面搜索推流唯一搜到的结果……

    可以把摄像头麦克风推流,也可以推手机屏幕。

    4 拉流

    推荐使用VLC,因为支持多个平台。菜单媒体 -> 打开网络串流。输入网络URL,缓存推荐使用100ms。

    屏幕截图显示不了视频流内容。实际是能显示我的手机屏幕内容的。         

    参考资料

    1. 利用nginx与nginx-rtmp-module搭建流媒体服务器实现直播 2. ffmpeg+nginx+rtmp+web实现视频直播网站

    3. Nginx与Nginx-rtmp-module搭建RTMP视频直播和点播服务器

    4. 手把手教你搭建Nginx-rtmp流媒体服务器+使用ffmpeg推流 5. nginx + rtmp 搭建流媒体服务器

    6. 利用nginx与nginx-rtmp-module搭建流媒体服务器实现直播 7. NGINX-RTMP直播服务器搭建-OBS录制推流-VLC视频流播放 8. VLC播放器实现推流以及串流的方式

    20200725更新两个网址:

    9. 一步到位搭建直播推流服务器, https://blog.csdn.net/yingmuliuchuan/article/details/81540263

    10. srs(nginx+rtmp 的替代方案), https://github.com/ossrs/srs

    最新回复(0)