【史上最全】Nginx+ffmpeg实现流媒体系统

来源:互联网 发布:服装数据分析表格 编辑:程序博客网 时间:2024/05/18 02:02
#centos6.6安装搭建nginx+ffmpeg流媒体服务器#此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端)#系统需要自行安装,流媒体服务器配置完成之后桌面可能挂掉,以后维护需要进命令行进行操作#必须按照以下步骤配置流媒体服务器,每一步必须要完成才可以配置成功# "#"是文档注释内容 "--"也是注释内容# 1.首先设置服务器IP地址,并更改为自动连接# 2.修改系统时间和时区为当前时间# 3.关闭防火墙#在控制台进行如下操作(需要登录root账号): 安装所有的依赖包: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#在usr/local/目录下面新建nginx文件夹#打开命令窗口#输入:mkdir soft-sourcecd soft-source#安装gitwget http://codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xzxz -d git-latest.tar.xztar xf git-latest.tar #cd进入的是当前安装的日期cd git-2014-12-29autoconf ./configuremakemake installgit --version      --查看git的版本cd ..#安装zlibwget http://zlib.net/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configuremakemake installcd ..#安装pcrewget http://exim.mirror.fr/pcre/pcre-8.12.tar.gztar zxvf pcre-8.12.tar.gzcd pcre-8.12./configuremake#make的时候如果出现错误:#libtool: compile: unrecognized option `-DHAVE_CONFIG_H' #libtool: compile: Try `libtool --help' for more information. #make[1]: *** [pcrecpp.lo] Error 1 #make[1]: Leaving directory `/home/mfcai/pcre-8.10' #make: *** [all] Error 2 #make install执行:yum install gcc gcc-c++ kernel-devel然后:./configuremakemake installcd ..#安装yadmi给flv视频添加关键帧wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gztar xzvf yamdi-1.4.tar.gzcd yamdi-1.4makemake installcd ..#安装OpenSSLwget http://www.openssl.org/source/openssl-1.0.1c.tar.gztar -zxvf openssl-1.0.1c.tar.gzcd openssl-1.0.1c./configmakemake installcd ..#安装ffmpeg及其依赖包:yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel安装Yasmcd /usr/local/nginxmkdir ffmpeg_sourcescd ffmpeg_sourceswget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gztar xzvf yasm-1.3.0.tar.gzcd yasm-1.3.0 ./configuremakemake installcd ..#安装ffmpegcd /ffmpeg_sourcesgit clone --depth 1 git://source.ffmpeg.org/ffmpegcd ffmpegPKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configuremake install#ffmpeg正常安装后执行ffmpeg时出现如下错误:#  ffmpeg: error while loading shared libraries: libavdevice.so.53: cannot open shared object file: No such file or directory#解决办法:vi /etc/ld.so.conf#加入:/usr/local/lib#执行ldconfig#安装nginx模块cd /usr/local/nginx/soft-sourcewget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gztar zxvf nginx_mod_h264_streaming-2.2.7.tar.gzgit clone git://github.com/arut/nginx-rtmp-module.git#nginx安装wget http://nginx.org/download/nginx-1.6.0.tar.gztar zxvf nginx-1.6.0.tar.gzcd nginx-1.6.0#编译安装nginx(直接复制nginx_configure.sh至nginx-1.6.0目录,文件在附件中) cp nginx_configure.sh /usr/local/nginx/soft-source/nginx-1.6.0chmod +x nginx_configure.sh./nginx_configure.shmake #在执行make的时候可能出现错误#/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#解决方法:#将/usr/local/nginx/soft-source/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了:大概在157行#/* TODO: Win32 */#if (r->zero_in_uri)#{#return NGX_DECLINED;#}##在执行make的时候可能出现错误#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c: 在函数‘esds_read’中:#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:377:16: 错误: 变量‘stream_priority’被设定但未被使用 [-Werror=unused-but-set-variable]#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:376:12: 错误: 变量‘stream_id’被设定但未被使用 [-Werror=unused-but-set-variable]#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c: 在函数‘stsd_parse_vide’中:#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:529:22: 错误: 变量‘level_indication’被设定但未被使用 [-Werror=unused-but-set-variable]#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:528:22: 错误: 变量‘profile_compatibility’被设定但未被使用 [-Werror=unused-but-set-variable]#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:527:22: 错误: 变量‘profile_indication’被设定但未被使用 [-Werror=unused-but-set-variable]#../nginx_mod_h264_streaming-2.2.7/src/mp4_reader.c:526:22: 错误: 变量‘configuration_version’被设定但未被使用 [-Werror=unused-but-set-variable]#cc1: all warnings being treated as errors#make[1]: *** [objs/addon/src/mp4_reader.o] 错误 1#解决方法:# vi objs/Makefile (修改nginx-1.6.0/objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.# 然后再make就能过了。vi objs/Makefilemake install#开放80和1935端口 关闭防火墙/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   写入修改/sbin/iptables -I INPUT -p tcp --dport 1935 -j ACCEPT   写入修改 /etc/init.d/iptables save   保存修改#关闭防火墙service iptables stop#查看端口状态 /etc/init.d/iptables status
端口映射映射流媒体服务器的 80  1935  22 端口到外网#配置Nginx相关模块 进入到nginx文件夹!执行./nginx启动nginx然后进行推送到nginxrtmp://x.x.x.x/hls/ch68h播放rtmp://x.x.x.x.:1935/hls/ch68hhttp://x.x.x.x/hls/ch68h.m3u8

以上内容为流媒体服务器的基本配置说明,根据项目不同可配置不同的配置文件,因Nginx配置文件为核心文件,所以暂不公开,如有需要的可与我沟通联系,此系统已经完善部署到几十个项目中,运行状况良好,同时也有少许bug,并在不断更新中.


1 0