使用Nginx+FFMPEG搭建HLS直播转码服务器
目的:使Nginx支持Rtmp协议推流,并支持hls分发功能及FFMPEG转码多码率功能。
一、准备工作
模块:nginx-rtmp-module-master(支持rtmp协议)
下载地址:
http://nginx.org
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 gcc-c++ wget xz perl-ExtUtils-MakeMaker package libcurl-devel unzip
2、安装Git工具:
#mkdir soft-source
#cd soft-source
#wget http://codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.xz
#xz -d git-latest.tar.xz
#tar xvf git-latest.tar
#cd git-2016-06-20/
#autoconf
#./configure
#make && make install
# git --version
git version 2.9.0
#cd ..
3、安装ffmpeg及其依赖包:
++++++++Yasm+++++++++++
#wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
#tar xzvf yasm-1.2.0.tar.gz
#cd yasm-1.2.0
#./configure
#make
#make install
#cd ..
++++++++x264+++++++++++
#git clone git://git.videolan.org/x264
#cd x264
#./configure --enable-shared
#make
#make install
#cd ..
++++++++LAME+++++++++++
#wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
#tar xzvf lame-3.99.5.tar.gz
#cd lame-3.99.5
#./configure --enable-nasm
#make
#make install
#cd ..
++++++++libogg+++++++++++
#wget http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
#tar xzvf libogg-1.3.0.tar.gz
#cd libogg-1.3.0
#./configure
#make
#make install
#cd ..
++++++++libvorbis+++++++++++
echo /usr/local/lib >> /etc/ld.so.conf; ldconfig
#wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
#tar xzvf libvorbis-1.3.3.tar.gz
#cd libvorbis-1.3.3
#./configure
#make
#make install
#cd ..
++++++++libvpx+++++++++++
git clone https://github.com/webmproject/libvpx
cd libvpx
./configure --enable-shared
make
make install
cd ..
++++++++FAAD2+++++++++++
#wget http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
#tar zxvf faad2-2.7.tar.gz
#cd faad2-2.7
#./configure
#make
#make install
#cd ..
++++++++FAAC+++++++++++
#wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
#tar zxvf faac-1.28.tar.gz
#cd faac-1.28
# sed -i 's@^char \*strcasestr@//char *strcasestr@' ./common/mp4v2/mpeg4ip.h
#./configure
#make
#make install
#cd ..
++++++++Xvid+++++++++++
#wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
#tar zxvf xvidcore-1.3.2.tar.gz
#cd xvidcore/build/generic
#./configure
#make
#make install
cd ../../../
++++++++ffmpeg+++++++++++
#git clone git://source.ffmpeg.org/ffmpeg
#cd ffmpeg
#./configure --prefix=/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
【说明】
动态装入器找到共享库要依靠两个文件 — /etc/ld.so.conf 和 /etc/ld.so.cache。
安装完成后,ffmpeg位于/opt/ffmpeg/bin目录下。
二、安装Nginx相关模块
1.环境准备
yum install pcre pcre-devel -y
yum install zlib zlib-devel -y
2.下载nginx及rtmp模块
#cd /root/soft-source/
#wget http://nginx.org/download/nginx-1.6.3.tar.gz
#tar xzvf nginx-1.6.3.tar.gz
#git clone git://github.com/arut/nginx-rtmp-module.git
3.编译nginx-rtmp
cd nginx-1.6.3
yum -y install libxml2-devel libxslt-devel
./configure --prefix=/usr/local/nginx --add-module=/root/soft-source/nginx-rtmp-module --with-http_stub_status_module --with-http_xslt_module
make
make install
安装完成后,nginx位于/usr/local/nginx/sbin目录下,配置文件nginx.conf在/usr/local/nginx/conf目录下
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容

#!/bin/bash
# Tengine Startup script# processname: nginx
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;; status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL

保存退出
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig --level 012345 nginx on #设置开机启动
/etc/rc.d/init.d/nginx start
关闭软件防火墙:
chkconfig iptables off iptables
service iptables stop
打开网页http://localhost,如果显示Welcome表示安装下正确,如果没有显示,请查看一下nginx的日志。
++++++++测试RTMP+++++++++++
修改/usr/local/nginx/conf/nginx.conf的内容如下:
#debug
daemon off;
master_process off;
error_log ./error.log debug;
events{
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#live
application myapp {
live on;
}
}
}
模拟测试:
用ffmpeg产生一个模拟直播源,向rtmp服务器推送
/opt/ffmpeg/bin/ffmpeg -i /root/fenxiang.mp4 -c:a libfaac -ar 44100 -ab 48k -c:v libx264 -f flv rtmp://10.10.6.237/myapp/test
注意,源文件必须是H.+AAC编码的。
10.10.6.237是运行nginx的服务器IP
下载这个软件进行测试:
VLC media player
进行打开串流播放尝试。
++++++++测试HLS切片功能+++++++++++
修改/usr/local/nginx/conf/nginx.conf的内容如下:
#debug
daemon off;
master_process off;
error_log ./error.log debug;
events{
worker_connections 1024;
}
rtmp{
server {
listen 1935;
chunk_size 4000;
#live
application myapp {
live on;
hls on;
hls_path /tmp/hls;
hls_fragment 2s;
hls_playlist_length 6s;
}
}
}
#HTTP
http{
server {
listen 80;
#welcome
location / {
root html;
index index.html index.htm;
}
#hls
location /hls {
types {
application/vnd.apple.mpegusr m3u8;
video/mp2t ts;
}
root /tmp;
add_header Cache-Control no-cache;
}
location /stat {
rtmp_stat all;
allow 127.0.0.1;
}
location /nclients
{
proxy_pass http://127.0.0.1/stat;
xslt_stylesheet /root/soft-source/nginx-rtmp-module/stat.xsl app='$arg_app' name='$arg_name';
add_header Refresh "3; $request_uri";
}
}
}
使用VLC或iPAD上的播放器进行查看 http://10.10.6.237/hls/test.m3u8。 打完,收工!
http://10.10.6.237/stat
根据直播频道访问以下地址:
http://10.10.6.237/nclients?app=myapp&name=channel1
使用Nginx+FFMPEG搭建HLS直播转码服务器的更多相关文章
- 使用ffmpeg搭建HLS直播系统
[时间:2018-04] [状态:Open] [关键词:流媒体,stream,HLS, ffmpeg,live,直播,点播, nginx, ssegment] 0 引言 本文作为HLS综述的后续文章. ...
- Nginx+ffmpeg的HLS开源服务器搭建配置及开发详
本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 ,真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋 ...
- Nginx+ffmpeg的HLS开源server搭建配置及开发具体解释
本文概述: 至眼下为止.HLS 是移动平台上很重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 .真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋友 ...
- nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器
本文概要: nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择.本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也叫rtsp转播,数据源不是读取文件,而是采用 ...
- 收藏:视频网站(JavaEE+FFmpeg)/Nginx+ffmpeg实现流媒体直播点播系统
FFmpeg安装(windows环境)http://www.cnblogs.com/xiezhidong/p/6924775.html 最简单的视频网站(JavaEE+FFmpeg)http://bl ...
- 用lua nginx module搭建一个二维码
用lua nginx module搭建一个二维码(qr code)生成器 作者 vinoca 發布於 2014年10月31日 如果有VPS,或者开源的路由器,安装一个nginx,添加lua-nginx ...
- 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解
转:http://itindex.net/detail/51186-nginx-ffmpeg-hls 本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体 ...
- 【原创+史上最全】Nginx+ffmpeg实现流媒体直播点播系统
#centos6.6安装搭建nginx+ffmpeg流媒体服务器 #此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端) #系统需要自行安装,流媒体服务器配置完成 ...
- Ubuntu中使用Nginx+rtmp搭建流媒体直播服务
一.背景 本篇文章是继上一篇文章<Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...
随机推荐
- 4 Values whose Sum is 0 POJ - 2785
4 Values whose Sum is 0 Time Limit: 15000MS Memory Limit: 228000K Total Submissions: 29243 Accep ...
- 【Umezawa's Jitte】真正用起来svn来管理版本
之前用过一次 但是没有真正的用起来 只是知道了一些基本概念 好了 决定开始真正的用这个svn了 参考大神http://www.cnblogs.com/wrmfw/archive/2011/09/08/ ...
- Spring Boot 开发系列一 开发环境的一些九九
从今天开始写这个Spring Boot 开发系列,我是第二周学习JAVA的,公司号称springboot把JAVA的开发提升到填空的能力,本人是NET转JAVA的,想看看这个填空的东西到底有多强.废话 ...
- laravel5.2总结--本地化以及常量的使用
1.本地化 Laravel 的本地化功能提供方便的方法来获取多语言的字符串,让你的网站可以简单的支持多语言. 语言包存放在 resources/lang 文件夹的文件里.每一个子目录应该对应一种语言 ...
- MFC深入浅出读书笔记第三部分1
第八章 Document-View 深入探讨(总结) 1.Document Document 在MFC 的CDocument 里头被具体化.CDocument 本身并无任何具体数据,它只是提供一个空壳 ...
- 直接选择排序(java)
直接选择排序的逻辑非常简单,数组{A1.......An} 先在{A1........An}去获取最小的 与A1交换位置 然后在{A2..........An}中取出最小的 与A2交换位置. ...
- 【两种方式 Service References和 web References 】手把手教你引入webservice 服务
1.对于一个webservie服务我们如何引入到自己的项目中去呢 第一种方法[Service References]:鼠标移到属性上 右键添加服务引用 然后在地址栏输入webservice 地址 点击 ...
- Linux主机系统目录误操作权限修改为777修复方法
ECS Linux中,如果意外误操作将/目录权限批量设置,比如chmod -R 777 / ,系统中的大部分服务以及命令将无法使用,这时候可以通过系统自带的getfacl命令来拷贝和还原系统权限,修复 ...
- Php中常见的4种随机密码生成方法详解
使用PHP开发应用程序,尤其是网站程序,常常需要生成随机密码,如用户注册生成随机密码,用户重置密码也需要生成一个随机的密码.随机密码也就是一串固定长度的字符串,这里我收集整理了几种生成随机字符串的方法 ...
- Java注解解析-搭建自己的注解处理器(CLASS注解使用篇)
该文章是继Java注解解析-基础+运行时注解(RUNTIME)之后,使用注解处理器处理CLASS注解的文章.通过完整的Demo例子介绍整个注解处理器的搭建流程以及注意事项,你将知道如何去搭建自己的注解 ...