目的:使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直播转码服务器的更多相关文章

  1. 使用ffmpeg搭建HLS直播系统

    [时间:2018-04] [状态:Open] [关键词:流媒体,stream,HLS, ffmpeg,live,直播,点播, nginx, ssegment] 0 引言 本文作为HLS综述的后续文章. ...

  2. Nginx+ffmpeg的HLS开源服务器搭建配置及开发详

    本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 ,真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋 ...

  3. Nginx+ffmpeg的HLS开源server搭建配置及开发具体解释

    本文概述: 至眼下为止.HLS 是移动平台上很重要并十分流行的流媒体传输协议.做移动平台的流媒体开发,不知道它不掌握它 .真是一大遗憾.而HLS的平台搭建有一定的难度,本文针对对该方向有一定了解的朋友 ...

  4. nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器

    本文概要: nginx是非常优秀的开源服务器,用它来做hls或者rtmp流媒体服务器是非常不错的选择.本文介绍了一种简易方法快速搭建rtmp流媒体服务器,也叫rtsp转播,数据源不是读取文件,而是采用 ...

  5. 收藏:视频网站(JavaEE+FFmpeg)/Nginx+ffmpeg实现流媒体直播点播系统

    FFmpeg安装(windows环境)http://www.cnblogs.com/xiezhidong/p/6924775.html 最简单的视频网站(JavaEE+FFmpeg)http://bl ...

  6. 用lua nginx module搭建一个二维码

    用lua nginx module搭建一个二维码(qr code)生成器 作者 vinoca 發布於 2014年10月31日 如果有VPS,或者开源的路由器,安装一个nginx,添加lua-nginx ...

  7. 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解

    转:http://itindex.net/detail/51186-nginx-ffmpeg-hls 本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体 ...

  8. 【原创+史上最全】Nginx+ffmpeg实现流媒体直播点播系统

    #centos6.6安装搭建nginx+ffmpeg流媒体服务器 #此系统实现了视频文件的直播及缓存点播,并支持移动端播放(支持Apple和Android端) #系统需要自行安装,流媒体服务器配置完成 ...

  9. Ubuntu中使用Nginx+rtmp搭建流媒体直播服务

    一.背景 本篇文章是继上一篇文章<Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...

随机推荐

  1. ActiveMQ发布-订阅消息模式(同点对点模式的区别)

    点对点与发布订阅最初是由JMS定义的.这两种模式主要区别或解决的问题就是发送到队列的消息能否重复消费(多订阅) 点对点: 消息生产者生产消息发送到queue中,然后消息消费者从queue中取出并且消费 ...

  2. vscode添加Astyle

    1.安装astyle插件,在应用商城里面一键安装即可.2.下载astyle的bin文件,并添加到系统环境变量.3.打开vscode的settings.json,添加以下代码. { "edit ...

  3. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  4. uva1422 二分法+优先队列贪心

    题意:有n个任务,每个任务必须在在时刻[r, d]之内执行w的工作量(三个变量都是整数).处理器执行的速度可以变化,当速度为s时,一个工作量为w的任务需要 执行的时间为w/s个单位时间.另外不一定要连 ...

  5. (PowerDesigner&Sqlite)PD中设计完表后,将其导入数据库中

    本人连接过SQLServer跟SQLite Ⅰ.SQLServer,百度,转一下:http://jingyan.baidu.com/article/7f766daf465e9c4101e1d0d5.h ...

  6. [转]Git for windows 下vim解决中文乱码的有关问题

    Git for windows 下vim解决中文乱码的问题 原文链接:Git for windows 下vim解决中文乱码的有关问题 1.右键打开Git bash: 2.cd ~ 3.vim .vim ...

  7. Asp.net自定义控件开发任我行(8)-数据集绑定

    摘要 已经有好几天没有写博客了,今天继续,前几天写到了注册自定义事件,今天我们来讲数据集绑定. 先把运行效果截个图给大家看,让大家心里也有个底.(大家要从第一章开始看起,我们每一章都是接着前面没做完的 ...

  8. 递归查询子类sql

    --通过父节点查询子节点 WITH TREE AS( SELECT * FROM Role WHERE RoleID = 4 -- 要查询的父 id UNION ALL SELECT Role.* F ...

  9. linux环境搭建系列之maven

    前提: jdk1.7 Linux centOS 64位 安装包从官网获取地址:http://maven.apache.org/download.cgi Jdk1.7对应apache-maven-3.3 ...

  10. [python][django学习篇][15]博客侧栏--自定义模板标签

    我们的博客侧边栏有四项内容:最新文章.归档.分类和标签云. 这些内容相对比较固定,且在各个页面都会显示,如果像文章列表或者文章详情一样,从视图函数中获取然后传递给模板,则每个页面对应的视图函数里都要写 ...