36

Qt显示视频流——nginx+rtmp搭建直播服务器(二)

 4 years ago
source link: https://www.tuicool.com/articles/aYBR7jN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

上次介绍的是使用ffmpeg推流,这次介绍的是使用 nginx + rtmp 搭建直播服务器。

环境:ubuntu 16.04

一、  安装 nginx rtmp 模块

1.  下载安装   nginx nginx-rtmp 编译依赖工具

sudo apt-get install -y curl build-essential libpcre3 libpcre3-dev libpcre++-dev zlib1g-dev libcurl4-openssl-dev libssl-dev

2.  创建编译所用目录

mkdir -p ~nginx_src

cd ~nginx_src

3.  下载 nginx 源码包并解压

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

tar -zxvf nginx-1.11.8.tar.gz

4.  下载 nginx-rtmp-module 模块 源码包( RTMP 模块源码包)并解压

wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

unzip master.zip

5.  进入 nginx 目录设定编译参数

cd  cd nginx-1.11.8

./configure--prefix=/usr/local/dev_workspace/nginx   --add-module=../nginx-rtmp-module-master --with-http_ssl_module

6.  编译安装

make

sudo make install

注意:如果没有安装第一步的依赖工具,可能出现以下错误:

./configure: error: the HTTP rewrite module requires the PCRE library.………………………………

7.  完成验证

操作如图:

byea6nJ.jpg!web

二、  修改 nginx 配置文件添加 rtmp 服务

1.  配置文件目录

/usr/local/dev_workspace/nginx /nginx.conf

2.  添加以下内容

rtmp {      

server {    

listen 1935; # 监听的端口

chunk_size 4000;     

application hls {

live on;     

}   

}   

}

注意: 直接配置文件增加   http 协议同级

②修改前先将原文件 .bak 备份

至此,nginx 及 nginx-rtmp-module 部分配置完成 。

三、安装Strobe Media Playback

1. 下载网址 https://sourceforge.net/projects/smp.adobe/

/usr/local/dev_workspace/nginx /html 下新建 rtmp 文件夹

解压好后将for Flash Player 10.1复制到 rtmp 文件夹下并重命名为 strobe

cp -r for Flash Player 10.1/  /usr/local/ dev_workspace/nginx /html/rtmp/strobe

2. /usr/local/ dev_workspace/nginx /html/rtmp 下新建一个 video.html

程序如下:

<!DOCTYPE html>

<html>

<head>

<title>Live Streaming</title>

<!-- strobe -->

<script type="text/javascript" src="strobe/lib/swfobject.js"></script>

<script type="text/javascript">

var parameters = {

//src: "rtmp://{pi_address}/rtmp/live",

src: "rtmp://192.168.15.129:1935/hls/video",

autoPlay: false,

controlBarAutoHide: false,

playButtonOverlay: true,

showVideoInfoOverlayOnStartUp: true,

optimizeBuffering : false,

initialBufferTime : 0.1,

expandedBufferTime : 0.1,

minContinuousPlayback : 0.1,

poster: "images/poster.png"

};

swfobject.embedSWF(

"strobe/StrobeMediaPlayback.swf"

, "StrobeMediaPlayback"

, 1024

, 768

, "10.1.0"

, "strobe/expressInstall.swf"

, parameters

, {

allowFullScreen: "true"

}

, {

name: "StrobeMediaPlayback"

}

);

</script>

</head>

<body>

<div id="StrobeMediaPlayback"></div>

</body>

</html>

注意: "rtmp://192.168.15.129:1935/hls/ video " 该地址是 ffmpeg 推流

到的虚拟目录,

, 1024, 768   这两个参数是视频流的长和宽,根据 Qt 设置的

                WebView 进行调整。 否则只调整WebView是没有用的。

至此, nginx+rtmp 以及 Strobe Media Playback 安装并且配置完成了。

下次将根据项目需要,给ffmpeg安装一些其他库,并且使用 qtwebview 通过 Url 显示视频流 .

最后附上经典参考文献连接:

https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/

欢迎大家关注公众号:

eIZJ3iQ.jpg!web


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK