原创博客地址:软件_搭建rtmp视频推送环境,腾讯云,ubuntu16
(建议先修改主机pip,conda的源)
安装conda,创建环境::conda create -n rstp python=3.7
报错:Solving environment: | failed
1 |
top可看出内存不足,换个大内存机器 |
安装ffmpeg:4.0
1 2 3 4 |
sudo add-apt-repository ppa:jonathonf/ffmpeg-4 sudo apt-get update sudo apt-get install ffmpeg 如果使用了:sudo apt-get install ffmpeg(默认2.8),先卸载掉,避免干扰 |
下载Nginx源码:wget http://nginx.org/download/nginx-1.17.10.tar.gz
下载nginx-rtmp-module:wget github.com/arut/nginx-rtmp-module/archive/master.zip
在nginx源码路径下执行:sudo ./configure –add-module=/home/john/nginx-rtmp-module-master/(注意后面的路径是解压后的rtmp源码路径)
报错:./configure: error: C compiler cc is not found
1 2 |
sudo apt-get install gcc sudo apt-get install build-essential |
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
1 |
sudo apt-get install libpcre3 libpcre3-dev |
报错:./configure: error: SSL modules require the OpenSSL library.
1 |
sudo apt-get install openssl libssl-dev |
报错:./configure: error: the HTTP gzip module requires the zlib library.
1 |
sudo apt install zlib1g-dev |
sudo make
sudo make install
验证:
成功后重启Nginx:systemctl restart nginx,输入机器外网ip,查看是否nginx默认页面
检查是否成功:
1 2 |
/usr/local/nginx/sbin/nginx -V 是否包含:类似 --add-module=nginx-rtmp-module |
访问nginx的welcome,确保nginx安装无问题
外层:
1 2 3 4 5 6 7 8 9 10 11 12 |
rtmp { server { listen 1935; chunk_size 4096; application live { live on; } } } |
http的内层添加:
1 2 3 4 5 6 7 8 9 10 |
server { listen 8080; location /stat{ rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl{ root /home/cjc/安装包/nginx/nginx-rtmp-module-master; } } |
报错:nginx: [emerg] unknown directive “rtmp” in /etc/nginx/nginx.conf:12
1 |
换nginx版本,本人采用了1.7,同时确保nginx使用的源码方式安装,如果apt-get安装,卸载干净重新安装 |
此时nginx的配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#user nobody; worker_processes 1; events { worker_connections 1024; } rtmp { server { listen 1935; chunk_size 4096; application live { live on; } } } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8080; location /stat{ rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl{ root /home/john/nginx-rtmp-module-master; } } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } |
记得开放虚拟机端口,否则容易悲剧(telnet测试下远程机端口)
1 2 |
终端(循环推送):ffmpeg -stream_loop -1 -i 1.mp4 -f flv rtmp://localhost:1935/live/test1 vlc:rtmp://118.25.10.138:1935/live/test1 |
奇怪的是:以下参数组也依然好使,端口1935去掉.
1 2 |
终端(循环推送):ffmpeg -stream_loop -1 -i 1.mp4 -f flv rtmp://localhost/live/test1 vlc:rtmp://118.25.10.138/live/test1 |
查了下rtmp默认端口就是1935,所以不加端口,实际就是从1935取得的,故确保远程主机放开端口1935
如何实现多路?
启动多个ffmpeg即可. 需要留意cpu和网络占用情况
1 |
rtmp://localhost/live/test2,rtmp://localhost/live/test3等等 |
如何实现帧率控制?
参数-r控制帧率
1 |
nohup ffmpeg -stream_loop -1 -r 1 -i 3.mp4 -f flv rtmp://localhost/live/3 & |
查资料时发现,已经有人制作了dofacker,可以直接使用.
https://hub.docker.com/r/datarhei/nginx-rtmp/
https://blog.csdn.net/u014552102/article/details/86599289
https://blog.csdn.net/u014552102/article/details/86606465