FFmpeg && nginx (centos 7)

工作上刚刚接触推流,借助nginx搭建一个rtmp服务器。配置过程简单做个记录

//用nginx搭建一个rtmp推流服务器
1 下载nginx-rtmp-module 地址:https://github.com/arut/nginx-rtmp-module
2 安装nginx 地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.8.1.tar.gz  
tar -zxvf nginx-1.8.1.tar.gz  
cd nginx-1.8.1  
./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module-master  --with-http_ssl_module    
make && make install


##如果提示缺少openssl那就先安装先关依赖库
#yum install glibc.i686
#yum –y update
#yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64   gcc-c++ 


或者 yum -y install openssl openssl-devel
##可以根据提示安装相关依赖库

##然后关于--add-module=../nginx-rtmp-module-master 这个编译选项,取决于你下载的nginx-rtmp-module的文件夹名称,如果
文件夹名称就是nginx-rtmp-module那选项就写这个名字,由于我下载的模块的文件夹名称是nginx-rtmp-module-master

所以编译选项写成--add-module=../nginx-rtmp-module-master


3 修改nginx配置文件 vi /usr/local/nginx/conf/nginx.conf 
添加:
rtmp {    
    
    server {    
    
        listen 1935;  #监听的端口  
    
        chunk_size 4000;    
          
           
        application hls {  #rtmp推流请求路径  
            live on;    
            hls on;    
            hls_path /usr/share/nginx/html/hls;    
            hls_fragment 5s;    
        }    
    }    
}  


修改http中的server模块:
[php] view plain copy
server {  
    listen       81;  
    server_name  localhost;  
  
    #charset koi8-r;  
  
    #access_log  logs/host.access.log  main;  
  
    location / {  
        root   /usr/share/nginx/html;  
        index  index.html index.htm;  
    }  
  
    #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;  
    }  
4 然后启动nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 


##注意
rtmp协议使用的1935端口需要去防火墙处打开此端口
查看已经开放的端口:  firewall-cmd --list-ports
开启端口: firewall-cmd --zone=public --add-port=1935/tcp --permanent
重启防火墙: firewallfirewall-cmd --reload


以上4步都成功之后就可以借助ffmpeg进行推流了。


//文件推流
ffmpeg -re -i KrisWu.mp4 -c copy -f flv rtmp://localhost:1935/myapp/test

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值