nginx搭建支持http和rtmp协议的流媒体服务器之一

实验目的:
让Nginx支持flv和mp4格式文件,支持RTMP协议的直播和点播;
同时打开RTMP的HLS功能

资料:
HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议。
HLS只请求基本的HTTP报文,与实时传输协议(RTP)不同,HLS可以穿过任何允许HTTP数据通过的防火墙或者代理服务器。
它也很容易使用内容分发网络来传输媒体流。
使用ffmpeg来完成对flv、mp4、mp3等格式的转化(点播实验暂时不测试)

一、准备工作
Nginx:
模块:nginx_mod_h264_streaming(支持h264编码的视频)
模块:http_flv_module 支持flv
模块:http_mp4_module 支持mp4
下载地址:

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

1、安装依赖包:
#yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64

2、安装相关工具包
1). git
# mkdir soft-source
# cd soft-source
# wget
# xz -d git-latest.tar.xz
# tar xzvf git-latest.tar 
# cd git-2014-06-27
# autoconf
# ./configure
# make && make install
# git --version
git version 2.0.0.GIT
# cd ..

2). zlib
# wget
# tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
# ./configure
# make
# make install
# cd ..

3). pcre
# wget
# tar zxvf pcre-8.12.tar.gz
# cd pcre-8.12
# ./configure
# make && make install
# cd ..

4). yadmi
yadmi的作用是为flv文件添加关键帧,才能实现拖动播放
# wget  
# tar xzvf yamdi-1.4.tar.gz
# cd yamdi-1.4
# make && make install
# cd ..
 
使用方法:
# yamdi -i input.flv -o out.flv
给input.flv文件 添加关键帧,输出为out.flv文件

5). OpenSSL
# wget
# tar -zxvf openssl-1.0.1c.tar.gz
# ./config
# make
# make install

3、安装ffmpeg及其依赖包:
1). Yasm
# wget
# tar xzvf yasm-1.2.0.tar.gz
# cd yasm-1.2.0
# ./configure
# make
# make install
# cd ..

2). x264
# git clone git://git.videolan.org/x264
# cd x264
# ./configure --enable-shared 
# make
# make install
# cd ..

3). LAME
# wget
# tar xzvf lame-3.99.5.tar.gz
# cd lame-3.99.5
#./configure --enable-nasm
# make
# make install
# cd ..

4). libogg
# wget
# tar xzvf libogg-1.3.0.tar.gz
# cd libogg-1.3.0
# ./configure
# make
# make install
# cd ..

5). libvorbis
# wget
# tar xzvf libvorbis-1.3.3.tar.gz
# cd libvorbis-1.3.3
# ./configure
# make
# make install
# cd ..

6). libvpx
# git clone
# cd libvpx
# ./configure  --enable-shared
# make
# make install
# cd ..

7). FAAD2
# wget
# tar zxvf faad2-2.7.tar.gz
# cd faad2-2.7
# ./configure
# make
# make install
# cd ..

8). FAAC
# wget
# tar zxvf faac-1.28.tar.gz
# cd faac-1.28
# ./configure
# make
# make install
# cd ..

9). Xvid
# wget
# tar zxvf xvidcore-1.3.2.tar.gz
# cd xvidcore/build/generic
# ./configure
# make
# make install
# cd ..

10). ffmpeg
# git clone git://source.ffmpeg.org/ffmpeg
# cd ffmpeg
# ./configure  --prefix=http://www.likecs.com/opt/ffmpeg/ --enable-version3  
--enable-libvpx --enable-libfaac --enable-libmp3lame  
--enable-libvorbis --enable-libx264 --enable-libxvid 
--enable-shared --enable-gpl --enable-postproc --enable-nonfree  
--enable-avfilter --enable-pthreads
# make && make install
# cd ..

修改/etc/ld.so.conf如下:
include ld.so.conf.d/*.conf
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/ffmpeg/lib
# ldconfig

二、安装Nginx相关模块
1. 模块安装
# wget
# tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
# git clone git://github.com/arut/nginx-rtmp-module.git

2. 创建用户和组
# groupadd www
# useradd -g www www

3. nginx安装
# wget
# tar zxvf nginx-1.6.0.tar.gz
# cd nginx-1.6.0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzpgsp.html