37.FFmpeg+OpenCV直播推流(nginx服务器搭建和测试)

简介:
介绍

Nginx是一款轻量级的Web服务器反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强。今天来分享一下如何安装配置nginx服务器,并应用于直播推流中。

开发环境

Ubuntu 16 64位+Windows10

安装

1.root用户登录Ubuntu,使用如下命令下载nginx

wget http://nginx.org/download/nginx-1.12.1.tar.gz

2.nginx依赖于一些开源库,这些我们需要下载下来

apt install  libssl-dev
注意zlib1g   g前边是个数字1不是字母l
apt install zlib1g-dev
apt install libpcre3-dev
apt install gcc
apt install g++

3.接下来将nginx解压

tar -xvf nginx-1.12.1.tar.gz 

4.下载rtmp模块
使用git下载,没有下载git先安装

apt install git

在github上找到nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module.git

将这个module添加到nginx上

./configure --add-module=/root/nginx-1.12.1/nginx-rtmp-module

nginx关联module.png
5.开始编译

make 

可能在系统中已经安装了nginx,为了防止无法覆盖,先rm

这是个默认安装目录
rm -r /usr/local/nginx/

6.安装

make install

然后进入到usr/local/nginx目录
注意这是root根目录下的

cd usr/local/nginx/sbin/

7.执行nginx

./nginx

8.查看是否已运行

ps -ef|grep nginx

在浏览器上输入ip查看如果显示welcome to nginx表示已经运行成功
nginx启动成功.png
9.rtmp配置
进入nginx安装目录:usr/local/nginx/conf修改nginx.conf文件(注意是安装目录,不要傻傻的去解压包中修改)

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                }
        }
}

添加了这个之后,就可以推流了,我们使用ffmepg推一把试试.注意live是什么,端口是什么

ffmpeg -i C:\Users\renzhenming\Desktop\一首《秋意浓》打动阿琴冷酷的心,星爷太会泡妞了.mp4 -f flv -c copy rtmp://192.168.1.108/live

然后通过vcl播放器,输入rtmp://192.168.1.108/live可以看到播放成功

然后在设置一把通过浏览器监听nginx状态,还是在nginx.conf中添加

server {
        listen 8080;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
                //样式表的位置,这个表是nginx-rtmp-module中的
                root /root/nginx-1.12.1/nginx-rtmp-module;
        }
    }

这样一来,我们通过浏览器就可以看到推流的状态了
在浏览器中输入

http://192.168.xx.xx:8080/stat

完整的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;


events {
    worker_connections  1024;
}

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        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 8080;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
                root /root/nginx-1.12.1/nginx-rtmp-module;
        }
    }
    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;
    #    }
    #}

}

至此,nginx配置完毕

相关文章
|
5天前
|
编解码 Java Android开发
FFmpeg开发笔记(三十一)使用RTMP Streamer开启APP直播推流
RTMP Streamer是一款开源的安卓直播推流框架,支持RTMP、RTSP和SRT协议,适用于各种直播场景。它支持H264、H265、AV1视频编码和AAC、G711、OPUS音频编码。本文档介绍了如何使用Java版的RTMP Streamer,建议使用小海豚版本的Android Studio (Dolphin)。加载项目时,可添加国内仓库加速依赖下载。RTMP Streamer包含五个模块:app、encoder、rtmp、rtplibrary和rtsp。完成加载后,可以在手机上安装并运行APP,提供多种直播方式。开发者可以从《FFmpeg开发实战:从零基础到短视频上线》获取更多信息。
31 7
FFmpeg开发笔记(三十一)使用RTMP Streamer开启APP直播推流
|
19天前
|
Web App开发 安全 Linux
FFmpeg开发笔记(二十六)Linux环境安装ZLMediaKit实现视频推流
《FFmpeg开发实战》书中介绍轻量级流媒体服务器MediaMTX,但其功能有限,不适合生产环境。推荐使用国产开源的ZLMediaKit,它支持多种流媒体协议和音视频编码标准。以下是华为欧拉系统下编译安装ZLMediaKit和FFmpeg的步骤,包括更新依赖、下载源码、配置、编译、安装以及启动MediaServer服务。此外,还提供了通过FFmpeg进行RTSP和RTMP推流,并使用VLC播放器拉流的示例。
33 3
FFmpeg开发笔记(二十六)Linux环境安装ZLMediaKit实现视频推流
|
1天前
|
NoSQL 关系型数据库 MySQL
linux服务器重启php,nginx,redis,mysql命令
linux服务器重启php,nginx,redis,mysql命令
8 1
|
4天前
|
运维 Java 测试技术
Spring运维之boo项目表现层测试加载测试的专用配置属性以及在JUnit中启动web服务器发送虚拟请求
Spring运维之boo项目表现层测试加载测试的专用配置属性以及在JUnit中启动web服务器发送虚拟请求
11 3
|
27天前
|
编解码 Linux iOS开发
FFmpeg开发笔记(二十三)使用OBS Studio开启RTMP直播推流
OBS(Open Broadcaster Software)是一款开源、跨平台的直播和和Linux。官网为<https://obsproject.com/>。要使用OBS进行直播,需执行四步:1) 下载并安装OBS Studio(<https://obsproject.com/download>),2) 启动流媒体服务器如MediaMTX,生成RTMP推流地址,3) 打开OBS Studio,设置直播服务为自定义RTMP服务器(127.0.0.1:1935/stream),调整视频分辨率,4) 添加视频来源并开始直播。同时,通过FFmpeg的拉流程序验证直播功能正常。
40 4
FFmpeg开发笔记(二十三)使用OBS Studio开启RTMP直播推流
|
4天前
|
NoSQL Redis 数据安全/隐私保护
连接测试服务器redis
连接测试服务器redis
14 1
|
5天前
|
弹性计算 应用服务中间件 Linux
双剑合璧:在同一ECS服务器上共存Apache与Nginx的实战攻略
在ECS服务器上同时部署Apache和Nginx的实战:安装更新系统,Ubuntu用`sudo apt install apache2 nginx`,CentOS用`sudo yum install httpd nginx`。配置Nginx作为反向代理,处理静态内容及转发动态请求到Apache(监听8080端口)。调整Apache的`ports.conf`监听8080。重启服务测试,实现两者高效协同,提升Web服务性能。记得根据流量和需求优化配置。【6月更文挑战第21天】
131 1
|
21天前
|
NoSQL 关系型数据库 应用服务中间件
jdk1.8、mysql、redis、nginx centos云服务器安装配置
jdk1.8、mysql、redis、nginx centos云服务器安装配置
|
4天前
|
缓存 负载均衡 应用服务中间件
Nginx 是一个高性能的开源反向代理服务器和 Web 服务器
Nginx 是一个高性能的开源反向代理服务器和 Web 服务器
12 0
|
16天前
|
Linux Shell 测试技术
Linux服务器测试脚本集合
LemonBench是iLemonrain创作的Linux服务器性能测试工具,能一键检测系统信息、网络、CPU、内存和硬盘性能。
14 0