网易视频云用Nginx搭建flv,mp4,hls流媒体服务器
网易视频云是网易倾力打造的一款基于云计算的分布式多媒体处理集群和专业音视频技术提供稳定流畅、低时延、高并发的视频直播、录制、存储、转码及点播等音视频的PAAS服务在线教育、远程医疗、娱乐秀场、在线金融等各行业及企业用户只需经过简单的开发即可打造在线音视频平台。今天网易视频云就给大家分享关于用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.gzwg e thttp://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gzwget http://sourceforge.net/projects/pcre/fi les/pcre/8.35/pcre-8.35.tar.gzwget http://zl ib.net/zl ib-1 .2.8.tar.gz
wget http://www.openssl .org/source/openssl-1 .0. 1g.tar.gzwget -O nginx-rtmp-module.ziphttps://github.com/arut/nginx-rtmp-module/archive/master.zipunzip nginx-rtmp-module.ziptar -zxvf nginx-1 .6.0.tar.gztar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gztar -zxvf pcre-8.35.tar.gztar -zxvf zl ib-1 .2.8.tar.gztar -zxvf openssl-1 .0.1g.tar.gz
2 配置命令会生成makefile文件
./configure\
--prefix=/usr/local/nginx\
--add-module=. ./nginx_mod_h264_streaming-2.2.7\--add-module=. ./nginx-rtmp-module\
--with-http_flv_module\
--with-http_mp4_module\
--with-http_stub_status_module\
--with-http_ssl_module\
--with-pcre=. ./pcre-8.35\
--with-zl ib=. ./zl ib-1 .2.8\
--with-debug
3 编译和安装ma kemake instal l
4问题解决
【1 】 如果在configure过程中出现以下错误
/root/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c: Infunction ‘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 membernamed ‘zero_in_uri ’make[1 ]: *** [objs/addon/src/ngx_http_h264_streaming_module.o]Error 1make[1 ]: Leaving directory`/root/nginx-0.8.54'make: *** [bui ld]Error 2
那么将src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了
/*TODO:Win32*/if (r->zero_in_uri)
{return NGX_DECLINED;
}
如果你没有对这个文件做个更改那么应该在源码的第157-161行。这个问题是由于版本原因引起在此不再讨论。
修改完之后记得先执行make clean 然后再进行重新执行configure、 ma ke 最后make instal l。
【2】 如果在编译过程中出现以下错误cc1 :warnings being treated as errors
那么修改/nginx-1 .6.0/objs/Makefi le文件
CFLAGS= -pipe -O-W-Wal l -Wpointer-arith -Wno-unused-parameter-Werror -g -D_LARGEFILE_SOURCE-DBUILDING_NGINX
-I . ./nginx-rtmp-module-master
把上面的-Werror去掉不把warn ning当作error处理
5Nginx的配置
#user nobody;worker_processes 1 ;
#error_log logs/error. log;
#error_log logs/error. log notice;
#error_log logs/error. log info;
#pid logs/nginx.pid;events{worker_connections 1024;
}rtmp{server {l isten 1935;chunk_size4000;
#video on demand forflvfi lesappl ication vod {play/usr/local/nginx/html/flv;
}
#video on demand for mp4 fi les
appl ication vod2{play/usr/local/nginx/html/mp4;
}appl ication hls{l ive on;hlson;hls_path /tmp/hls;
}
#MPEG-DASHissimi lar toHLSappl ication dash{l ive on;dashon;dash_path /tmp/dash;
}
}
}http{include mime.types;
default_type appl ication/octet-stream;
#log_format main '$remote_addr -$remote_user [$time_local] "$request" '# '$status$body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"' ;
#access_log logs/access. log main;sendfi le on;
#tcp_nopush on;
#keepal ive_timeout 0;keepal ive_timeout 65;
#gzip on;server {
#in case we have anotherweb server on port 80l isten 8080;server_name localhost;
#charset koi8-r;
#access_log logs/host.access. log main;location/ {root html ;
index index.html index.htm;
}
#error_page 404 /404.html ;
#redirect server error pages to the static page/50x.html#error_page 500502503504 /50x.html ;location =/50x.html {root html ;
}location~\.mp4${mp4;
}location~\.flv${flv;
}
#This URL provides RTMP statistics in XMLlocation/stat {rtmp_stat al l ;
rtmp_stat_stylesheet stat.xsl ;
}location/stat.xsl {
#XML stylesheet to view RTMP stats.#Copy stat.xsl wherever you want
#and put the ful l directory path herer o o t /va r/www/;
}location/hls{
#Serve HLS fragmentstypes{appl ication/vnd.apple.mpegurl m3u8;video/mp2t ts;
}
#where the m3u8 andtsfi les areal ias/usr/local/nginx/html/hls;
#l ive streaming setting
#root /tmp;
HostNamaste是一家成立于2016年3月的印度IDC商家,目前有美国洛杉矶、达拉斯、杰克逊维尔、法国鲁贝、俄罗斯莫斯科、印度孟买、加拿大魁北克机房。其中洛杉矶是Quadranet也就是我们常说的QN机房(也有CC机房,可发工单让客服改机房);达拉斯是ColoCrossing也就是我们常说的CC机房;杰克逊维尔和法国鲁贝是OVH的高防机房。采用主流的OpenVZ和KVM架构,支持ipv6,免...
LOCVPS怎么样?LOCVPS是一家成立于2011年的稳定老牌国人商家,目前提供中国香港、韩国、美国、日本、新加坡、德国、荷兰等区域VPS服务器,所有机房Ping延迟低,国内速度优秀,非常适合建站和远程办公,所有机房Ping延迟低,国内速度优秀,非常适合做站。XEN架构产品的特点是小带宽无限流量、不超售!KVM架构是目前比较流行的虚拟化技术,大带宽,生态发展比较全面!所有大家可以根据自己业务需求...
进入6月,各大网络平台都开启了618促销,腾讯云目前也正在开展618云上Go活动,上海/北京/广州/成都/香港/新加坡/硅谷等多个地区云服务器及轻量服务器秒杀,最低年付95元起,参与活动的产品还包括短信包、CDN流量包、MySQL数据库、云存储(标准存储)、直播/点播流量包等等,本轮秒杀活动每天5场,一直持续到7月中旬,感兴趣的朋友可以关注本页。活动页面:https://cloud.tencent...