使用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模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...
随机推荐
- [Uva623]500!(高精)
Description 求N! \(N \leq 1000\) Sample Input 10 30 50 100 Sample Output 10! 3628800 30! 265252859812 ...
- loj2042 「CQOI2016」不同的最小割
分治+最小割 看到题解的第一句话是这个就秒懂了,然后乱七八糟的错误.越界.RE-- #include <algorithm> #include <iostream> #incl ...
- IOS开发学习笔记022-imageView实现动画
这里要播放的动画是很多张连续的动画,连续播放就会显示出动画效果. 大概过程是: 新建一个single view application ,然后添加一个image View控件到视图.给image vi ...
- python2.7运行报警告:UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal解决办法
1. 程序源代码报错部分: #选择年级if grade == '幼升小': outline.nianji().pop(0).click()elif grade == "一年级": ...
- 学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用利用条件运算符的嵌套来完成此题:C表示。
# -*- coding: utf8 -*- # Author:wxq #python 2.7 #题目:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用利用条件运算符 ...
- C++字符串高效查找替换,有空分析分析
void CWebTransfer::Substitute(char *pInput, char *pOutput, char *pSrc, char *pDst) { char *pi, *po, ...
- Corrupt block relative dba: 0x04c20df1
alert日志报以下提示: Corrupt block relative dba: , block ) Fractured block found during backing up datafile ...
- css对html中表格单元格td文本过长的处理
参考 http://www.cnblogs.com/lekko/archive/2013/04/30/3051638.html http://www.zhangxinxu.com/wordpress/ ...
- 【SPOJ694】Distinct Substrings (SA)
求不相同子串个数 该问题等价于求所有后缀间不相同前缀的个数..也就是对于每个后缀suffix(sa[i]),将贡献出n-sa[i]+1个,但同时,要减去那些重复的,即为height[i],故答案 ...
- [AHOI2014&&JSOI2014][bzoj3876] 支线剧情 [上下界费用流]
题面 传送门 思路 转化模型:给一张有向无环图,每次你可以选择一条路径走,花费的时间为路径上边权的总和,问要使所有边都被走至少一遍(可以重复),至少需要花费多久 走至少一遍,等价于覆盖这条边 也就是说 ...