实时监控系统/直播系统(三)- 用RTMP推流到Nginx,并用VLC拉流显示到Qt界面

一、项目思路

实时监控系统/直播系统,通过V4L2接口从摄像头采集YUYV格式的视频;用H264对视频数据进行编码;然后通过RTMP协议发送至支持了rtmp的nginx流媒体服务器;用客户端使用VLC从服务器拉流显示。

V4L2----->H264----->RTMP------>nginx------>VLC

二、配置环境

2.1、nginx搭建rtmp流媒体服务器

2.1.1、环境说明:

系统:ubuntu16.04    pcre库:pcre.8.37   服务器:nginx-1.5.0

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

2.1.2、下载安装pcre库

pcre是一个轻量级的perl函数库,nginx的HTTP模块需要靠它来解析正则表达式,所以需要先安装该库。

1)解压pcre-8.37.tar.gz

tar -xvf pcre-8.37.tar.gz

cd pcre-8.37

2)配置编译pcre

./configure 配置编译选项

make 编译

sudo make install 安装编译的库到系统

2.1.3、编译安装nginx

准备文件:

/home/edu/Nginx

------nginx-1.5.0.tar.gz

------master.zip

------pcre-8.37.tar.gz

1)tar -xvf nginx-1.5.0.tar.gz 解压源码包

2)unzip master.zip

3)cd nginx-1.5.0

4)sudo ./configure --add-module=../nginx-rtmp-module-master  --with-http_stub_status_module --with-http_ssl_module 配置

5)sudo make

4)sudo make install

2.1.4、启动nginx

sudo /usr/local/nginx/sbin/nginx

成功标志:

edu@edu:/usr/local/nginx/sbin$ sudo  ./nginx
edu@edu:/usr/local/nginx/sbin$ ps  -aux  |  grep  nginx
root       5693  0.0  0.0  24936   404 ?        Ss   23:53   0:00 nginx: master process ./nginx
nobody     5694  0.0  0.1  25384  2428 ?        S    23:53   0:00 nginx: worker process
edu        5696  0.0  0.0  15984   968 pts/6    S+   23:53   0:00 grep --color=auto nginx

2.2、nginx添加rtmp支持

sudo vi /usr/local/nginx/conf/nginx.conf

# RTMP 模块配置
rtmp {
    server {
            listen 9090;  # RTMP服务器监听端口9090
    
            # 应用程序配置
            application live {
                        live on;  # 启用直播功能
                    }
    
    
    
            application webcam {
                        live on;
                    }
    
            application mypush {
                        live on;
                        push rtmp://example.com/backup;  # 将流推送到另一个RTMP服务器
                    }
    
            application mypull {
                        live on;
                        pull rtmp://example.com/mytv;  # 从另一个RTMP服务器拉取流
                    }
    
            application mystaticpull {
                        live on;
                        pull rtmp://example.com/mytv;  # 从另一个RTMP服务器拉取流
                    }
    
            application vod {
                        play /home/edu/Nginx/videos;  # 指定存储VOD文件的目录
                    }
    
            application vod2 {
                        play /home/edu/Nginx/videos2;
                    }
    
            application videochat {
                        live on;
                        wait_video on;  # 等待视频流开始再发布
                        wait_key on;  # 等待关键帧再发布
                    }
    
            # 可以根据需要添加更多的应用程序配置
        }
}


# HTTP 模块配置
http {
    server {
        listen 80;  # HTTP服务器监听端口80

        # RTMP统计信息
        location /stat {
            rtmp_stat all;  # 获取所有应用程序的统计信息
            rtmp_stat_stylesheet /path/to/style.css;  # 指定样式表用于美化统计页面
        }

        # HLS片段访问
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;  # 设置HLS播放列表的MIME类型
                video/mp2t ts;  # 设置MPEG2传输流的MIME类型
            }
            root /path/to/hls;  # 指定存储HLS片段的目录
            add_header Cache-Control no
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值