直播流 nginx+ffmpeg搭建流媒体服务器

这里实现了简单Nginx+ffmpeg 推本地mp4视频文件的功能,以后将会继续更新
环境系统环境:centos release 6.7 (Final)
需求利用nginx和ffmpeg搭建流媒体服务器
利用nginx和ffmpeg搭建流媒体服务器(直播流),其他流后续会有所更新
关于用Nginx搭建flv,mp4,hls流媒体服务器的技术干货!
模块:nginx_mod_h264_streaming(支持h264编码MP4格式的视频)
模块:http_flv_module (支持flv)
模块:http_mp4_module (支持mp4)
模块: nginx-rtmp-module (支持rtmp协议,也支持HLS)
步骤(1)模块下载和解压

wget http://nginx.org/download/nginx-1.6.0.tar.gz
wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
wget -O nginx-rtmp-module.ziphttps://github.com/arut/nginx-rtmp-module/archive/master.zip
将所有模块统一放置在/usr/local/nginx_sources目录下,方便管理
安装步骤:openssl-->zlib-->pcre
1.openssl
./config --prefix=/usr/local/openssl -->make -->make install
2. zlib
./configure --prefix=/usr/local/zlib-->make -->make install
3.pcre
./configure ==prefix=/usr/local/pcre -->make -->make install
(2)配置命令,会生成makefile文件
cd /usr/local/nginx-1.6.0
./configure
--prefix=/usr/local/nginx
--add-module=/usr/tmp/nginx_mod_h264_streaming-2.2.7
--add-module=/usr/tmp/nginx-rtmp-module-master
--with-http_flv_module
--with-http_mp4_module
--with-http_stub_status_module
--with-http_ssl_module
--with-pcre=/usr/tmp/pcre-8.35
--with-zlib=/usr/tmp/zlib-1.2.8
--with-debug
--with-openssl=/usr/tmp/openssl-1.0.1g
错误提示:如果在configure过程中出现以下错误:
/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: In function ‘ngx_streaming_handler’:
/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ‘ngx_http_request_t’ has no member named ‘zero_in_uri’
make[1]: *** [objs/addon/src/ngx_http_h264_streaming_module.o] Error 1
make[1]: Leaving directory `/root/nginx-0.8.54'
make: *** [build] Error 2
那么将src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了:
/* TODO: Win32 */
if (r->zero_in_uri)
{
return NGX_DECLINED;
}
如果你没有对这个文件做个更改,那么应该在源码的第157-161行 。
cd /usr/local/nginx/sbin--> ./nginx ( 启动nginx) -->netstat -nltp(如果80端口启动就说明安装成功)
-->在浏览器输入http://172.19.197.244:80
(3)开始安装ffmpeg,参考安装文档http://www.voidcn.com/blog/yangguangmeng/article/p-4881242.html(转载)
安装ffmpeg:(如果系统不支持上网功能,可以自行从网下先下载,再上传到服务器)
下载FFmpeg和libx264的包
ffmpeg-3.2.4.tar.bz2 last_x264.tar.bz2
libx264需要yasm,所以先安装yasm
zypper install yasm
然后安装libx264
zypper install libx264-dev
解压缩libx264
tar -xzvf last_x264.tar.bz2
安装libx264
./configure --enable-shared --enable-pthread --enable-pic
make
make install
然后安装ffmpeg,ffmpeg有许多依赖包,需要一个一个先安装,可能安装过程中还需要下载其他依赖包,这个安装过程依照提示进行下载安装即可
1. libfaac
zypper install libfaac-dev
2. libmp3lame
zypper install libmp3lame-dev
3. libtheora
zypper install libtheora-dev
4. libvorbis
zypper install libvorbis-dev
5. libxvid
zypper install libxvidcore-dev
6. libxext
zypper install libxext-dev
7. libxfixeszypper install libxfixes-dev
依赖包安装完后,安装ffmpeg
先解压缩ffmpeg
tar -xzvf ffmpeg-3.2.4.tar.bz2
cd /usr/local/ffmpeg_sources #我把它统一放在/usr/local/ffmpeg_sources目录
cd ffmpeg ffmpeg-3.2.4
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-pthreads --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab
make && make install
cd /usr/local/nginx/conf -->vi nginx.conf
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" '


推荐阅读