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配置完毕

相关文章
|
7天前
|
应用服务中间件 PHP nginx
当你的nginx服务器和php服务器不在一起的时候,这个nginx 的root目录问题
两个服务器的网站代码目录需要对齐,docker容器里面也是一样
|
3月前
|
负载均衡 监控 应用服务中间件
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
240 61
|
3月前
|
安全 应用服务中间件 网络安全
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
253 60
|
2月前
|
存储 编解码 应用服务中间件
使用Nginx搭建流媒体服务器
本文介绍了流媒体服务器的特性及各种流媒体传输协议的适用场景,并详细阐述了使用 nginx-http-flv-module 扩展Nginx作为流媒体服务器的详细步骤,并提供了在VLC,flv.js,hls.js下的流媒体拉流播放示例。
310 1
|
4月前
|
缓存 并行计算 Ubuntu
Jetson 学习笔记(十一):jetson agx xavier 源码编译ffmpeg(3.4.1)和opencv(3.4.0)
本文是关于在Jetson AGX Xavier上编译FFmpeg(3.4.1)和OpenCV(3.4.0)的详细教程,包括编译需求、步骤、测试和可能遇到的问题及其解决方案。还提供了Jetson AGX Xavier编译CUDA版本的OpenCV 4.5.0的相关信息。
155 4
Jetson 学习笔记(十一):jetson agx xavier 源码编译ffmpeg(3.4.1)和opencv(3.4.0)
|
4月前
|
Ubuntu 应用服务中间件 nginx
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
本文是关于Ubuntu系统中使用ffmpeg 3.2.16源码编译OpenCV 3.4.0的安装笔记,包括安装ffmpeg、编译OpenCV、卸载OpenCV以及常见报错处理。
327 2
Ubuntu安装笔记(三):ffmpeg(3.2.16)源码编译opencv(3.4.0)
|
4月前
|
网络协议 应用服务中间件 nginx
FFmpeg错误笔记(一):nginx-rtmp-module推流出现 Server error: Already publishing
这篇文章讨论了在使用nginx-rtmp-module进行RTMP推流时遇到的“Server error: Already publishing”错误,分析了错误原因,并提供了详细的解决办法,包括修改nginx配置文件和终止异常的TCP连接。
307 0
FFmpeg错误笔记(一):nginx-rtmp-module推流出现 Server error: Already publishing
|
6月前
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何配置Web服务器(如Apache或Nginx)?
在Linux中,如何配置Web服务器(如Apache或Nginx)?
|
6月前
|
负载均衡 应用服务中间件 Linux
"揭晓nginx的神秘力量:如何实现反向代理与负载均衡,拯救服务器于水火?"
【8月更文挑战第20天】在Linux环境下,nginx作为高性能HTTP服务器与反向代理工具,在网站优化及服务器负载均衡中扮演重要角色。本文通过电商平台案例,解析nginx如何解决服务器压力大、访问慢的问题。首先介绍反向代理原理,即客户端请求经由代理服务器转发至内部服务器,隐藏真实服务器地址;并给出配置示例。接着讲解负载均衡原理,通过将请求分发到多个服务器来分散负载,同样附有配置实例。实践表明,采用nginx后,不仅服务器压力得到缓解,还提升了访问速度与系统稳定性。
190 3
|
6月前
|
负载均衡 应用服务中间件 Apache
Nginx与Apache的终极对决:揭秘Web服务器界的“速度与激情”!你不可不知的性能霸主如何颠覆传统,震撼互联网的根基!
【8月更文挑战第13天】互联网技术发展中,Web服务器至关重要,Nginx与Apache是最广泛使用的两种。Apache历史悠久,但Nginx以轻量级和高性能脱颖而出。Nginx采用事件驱动架构,高效处理大量并发连接,而Apache使用进程驱动,高并发下资源消耗大。以餐厅为例,Nginx像大堂经理同时处理多个顾客需求,远比Apache为每位顾客分配服务员更高效。性能测试显示Nginx处理能力远超Apache。此外,Nginx配置简洁灵活,尤其在负载均衡方面表现突出。尽管Apache适合动态内容处理,但在快速变化的互联网环境中,Nginx因其独特优势成为许多开发者和企业的首选。
101 7

热门文章

最新文章