zoukankan      html  css  js  c++  java
  • 在Ubuntu下使用nginx-rtmp-module搭建直播系统

    直播系统最简单地包括推流和拉流,在这里先使用nginx-rtmp-module作为流媒体服务器。

    流媒体服务器搭建

    1. nginx-rtmp-module下载和安装

    源码地址:https://github.com/arut/nginx-rtmp-module
    使用git命令下载:git clone https://github.com/arut/nginx-rtmp-module.git

    2.nginx源码下载及编译安装

    nginx下载: wget http://nginx.org/download/nginx-1.16.0.tar.gz
    最新版本可以查看http://nginx.org/en/download.html 得到。

    在编译nginx之前,需要先下载编译安装好zlib、openssl、pure库

    
    wget http://www.zlib.net/zlib-1.2.11.tar.gz
    tar xf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure
    make && make install
    
    wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
    tar xf openssl-1.0.2l.tar.gz
    cd openssl-1.0.2l
    ./config
    make && make install
    
    
    wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
    tar xf pcre-8.42.tar.gz
    cd pcre-8.42
    ./configure
    make && make install
    

    安装之前可以先检查下自己的电脑有没有已经安装了。

    然后就可以开始编译nginx了:

    tar xf nginx-1.16.0.tar.gz
    cd nginx-1.16.0/
    ./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-http_ssl_module  --with-pcre=../pcre-8.42 --with-openssl=../openssl-1.0.2l --with-zlib=../zlib-1.2.11
    
    make && make install
    

    注意:执行./configure命令时的路径要对应。

    执行完上述步骤后,如果没有错误,nginx就会已经部署在/user/local/nginx目录。

    cd /user/local/nginx
    tree
    
    # 启动和关闭nginx
    sudo /user/local/nginx/sbin/nginx
    sudo /user/local/nginx/sbin/nginx -s  stop
    

    3. 配置rtmp转发

    修改nginx.conf文件,以支持RTMP:

    rtmp {  
        server {  
            listen 9999;  
      	#直播
            application live {  
                live on;  
            }
     
    	#点播
    	application vod {
                play /tmp/video;
        	}
     
        }  
    }
    

    修改完成之后重启nginx:

    /usr/local/nginx/sbin/nginx -s reload
    

    通过netstat -ltn命令我们可以看到9999端口正在监听.这便是我们配置的rtmp的服务端口。

    FFmpeg推流

    安装ffmpeg

    sudo apt-get install ffmpeg
    
    

    推流

     ffmpeg -re -i input.mp4 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 1280x720 -q 10 rtmp://127.0.0.1:9999/live/test
    

    ffplay拉流

    ffplay rtmp://127.0.0.1:9999/live/test
    

    如此,一个最简单的直播系统就搭建完成了。

  • 相关阅读:
    POJ
    CodeForces
    51Nod 1256 扩展欧几里得求乘法逆元
    SDUT 3917
    SDUT 3918
    从零开始实现asp.net MVC4框架网站的用户登录以及权限验证模块 详细教程
    bootstrap资料索引
    理解Login函数
    细说@Html.ActionLink()的用法
    RGB颜色对照表
  • 原文地址:https://www.cnblogs.com/xl2432/p/11090613.html
Copyright © 2011-2022 走看看