原创; linux_手把手教ubuntu搭建rtmp视频推送服务
1,装置conda,ffmpeg,nginx,nginx-rtmp-module
(倡议先批改主机pip,conda的源)
装置conda,创立环境::conda create -n rstp python=3.7
报错:Solving environment: | failed
top可看出内存不足,换个大内存机器
装置ffmpeg:4.0
sudo add-apt-repository ppa:jonathonf/ffmpeg-4sudo apt-get updatesudo apt-get install ffmpeg如果应用了:sudo apt-get install ffmpeg(默认2.8),先卸载掉,防止烦扰
下载Nginx源码:wget http://nginx.org/download/ngi...
下载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
sudo apt-get install gccsudo apt-get install build-essential
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
sudo apt-get install libpcre3 libpcre3-dev
报错:./configure: error: SSL modules require the OpenSSL library.
sudo apt-get install openssl libssl-dev
报错:./configure: error: the HTTP gzip module requires the zlib library.
sudo apt install zlib1g-dev
sudo make
sudo make install
验证:
胜利后重启Nginx:systemctl restart nginx,输出机器外网ip,查看是否nginx默认页面
查看是否胜利:
/usr/local/nginx/sbin/nginx -V是否蕴含:相似 --add-module=nginx-rtmp-module
拜访nginx的welcome,确保nginx装置无问题
2,nginx配置批改
外层:
rtmp{ server { listen 1935; chunk_size 4096; application live { live on; } }}
http的内层增加:
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
换nginx版本,自己采纳了1.7,同时确保nginx应用的源码形式装置,如果apt-get装置,卸载洁净重新安装
此时nginx的配置如下:
#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; } }}
3,推流和拉流
记得凋谢虚拟机端口,否则容易喜剧(telnet测试下近程机端口)
终端(循环推送):ffmpeg -stream_loop -1 -i 1.mp4 -f flv rtmp://localhost:1935/live/test1vlc:rtmp://118.25.10.138:1935/live/test1
奇怪的是:以下参数组也仍然好使,端口1935去掉.
终端(循环推送):ffmpeg -stream_loop -1 -i 1.mp4 -f flv rtmp://localhost/live/test1vlc:rtmp://118.25.10.138/live/test1
查了下rtmp默认端口就是1935,所以不加端口,理论就是从1935获得的,故确保近程主机放开端口1935
如何实现多路?
启动多个ffmpeg即可. 须要注意cpu和网络占用状况
rtmp://localhost/live/test2,rtmp://localhost/live/test3等等
如何实现帧率控制?
参数-r管制帧率
nohup ffmpeg -stream_loop -1 -r 1 -i 3.mp4 -f flv rtmp://localhost/live/3 &
4,docker
查资料时发现,曾经有人制作了dofacker,能够间接应用.
https://hub.docker.com/r/data...
参考
https://blog.csdn.net/u014552...
https://blog.csdn.net/u014552...