目的:使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. 库函数的使用:sscanf的使用方法

    先贴代码,可以看懂代码的直接看代码: /***************************************************** ** Name : sscanf.c ** Auth ...

  2. rope(转载)

    谈c++ pb_ds库(一)rope大法好 (转载)原文链接 https://www.cnblogs.com/keshuqi/p/6257642.html 参考资料 1)官方说明 支持 sorry,c ...

  3. 版本控制之GitHub — — 第一步的理解

    GitHub是时下最流行的版本控制的一门“技术”,此之前svn(subversion)也是同样的作用. 至于版本控制:Git是分布式的,而svn是中心式的(或者叫集中式的)版本控制系统,这是两者之间理 ...

  4. Python及其常用模块库下载及安装

    一.Python下载:https://www.python.org/downloads/ 二.Python模块下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...

  5. 求 1 到 n 的所有数的约数和

    求 1 到 n 的所有数的约数和 暴力方法就是枚举每个数,算出他的约数和即可,这样有点慢. 另一种思路,枚举约数,判断他是谁的约数,并记录(即他的倍数有多少个),在乘以他自己. n/i求的是n以内,i ...

  6. P2485 [SDOI2011]计算器

    P2485 [SDOI2011]计算器 题目描述 你被要求设计一个计算器完成以下三项任务: 1.给定y.z.p,计算y^z mod p 的值: 2.给定y.z.p,计算满足xy ≡z(mod p)的最 ...

  7. loj2537 「PKUWC 2018」Minimax

    pkusc 快到了--做点题涨涨 rp. 初见时 yy 了一个类似于归并的东西,\(O(n^2)\),50 分. 50 分 yy 做法 对于一个点,枚举他能到达的权值(假设这个权值在左子树,在右子树是 ...

  8. Windows网络编程笔记3 ---- 邮槽和命名管道

    邮槽和命名管道的使用方法也很简单,只需几个有限的函数就可以实现双方的通信. 第三.邮槽 邮槽----进程间通信机制. 通过邮槽客户进程可以将消息通过广播给一个或多个服务进程.这是一个单向通信机制,缺点 ...

  9. 第一章:前端布局之display属性

    css布局学习网站:http://zh.learnlayout.com

  10. day05_09 列表内置方法

    1.0 count(计算元素出现的次数) t = ['to','be','or','not','to','be'].count('to') print(t) #>>>2 2.0 ex ...