Nginx-rtmp流媒体服务器及使用ffmpeg推流

1、安装Nginx依赖
创建nginx-dependence文件夹,在该文件夹中安装依赖:

mkdir nginx-dependence
cd nginx-dependence

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40/
./configure
make
sudo make install

wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make
sudo make install

wget https://www.openssl.org/source/old/1.1.0/openssl-1.1.0.tar.gz
tar -zxvf openssl-1.1.0.tar.gz
cd openssl-1.1.0/
./config
make
sudo make install

在nginx-dependence目录中,先下载nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git

2、安装Nginx
首先运行:

apt-get install build-essential
apt-get install libtool

然后下载源码,并进行编译:

mkdir nginx

wget http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0/

./configure --prefix=/home/xxxxxx/nginx --with-pcre=../nginx-dependence/pcre-8.40 --with-zlib=../nginx-dependence/zlib-1.2.11 --with-openssl=../nginx-dependence/openssl-1.1.0  --with-http_ssl_module --add-module=../nginx-dependence/nginx-rtmp-module
make
sudo make install

启动和停止nginx服务器:

sudo /home/xxxxxx/nginx/sbin/nginx
sudo /home/xxxxxx/nginx/sbin/nginx -s stop

如果没有报任何错误,则可以打开浏览器看看nginx是否启动成功。
打开浏览器,输入localhost 或本机的IP地址,按回车,如果看到下面的界面,说明nginx已经安装成功并且启动成功了。
在这里插入图片描述
3、配置Nginx流媒体服务器
nginx服务器有一个配置文件叫做nginx.conf ,这个文件默认是位于/home/xxxxxx/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;

error_log logs/error.log debug;

events {
    worker_connections  1024;
}

rtmp{
     server{
        listen 1935;
        application videotest{
            live on;
        }
    }
}

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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   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;
        }

        # 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;
    #    }
    #}

}

其中rtmp就是rtmp服务器模块。
可以通过访问rtmp://localhost/videotest 来访问videotest这个资源。
live on 表示这是实时的传输。

4、使用 ffmpeg 推流本地视频,使用ffplay查看
在这里插入图片描述

-re : 表示使用文件的原始帧率进行读取
-i :这个参数表示输入 ,后面参数就是输入文件
vcodec copy : -vcodec表示使用的视频编解码器 ,前缀v表示video,copy  表示复制使用源文件的视频编解码器。
-acodec copy : -acodec表示使用的音频编解码器,前缀a表示audio,copy 表示使用源文件的音频编解码器。
-b:v 800k : -b:v表示视频的比特率(bitrate) ,为800k。
-b:a 32k : 表示音频的比特率为32k。
-f flv : -f表示format ,强制输出格式为flv,也叫封装(mux),封装要做的事就是把视频和音频混合在一起,进行同步。
rtmp://localhost/videotest 表示输出的"文件名",这个文件名可以是一个本地的文件,也可以指定为rtmp流媒体地址(推流)。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值