转 做自己的m3u8点播系统使用HTTP Live Streaming HLS技术)

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               




[FMS]使用ffmpeg来完成对flv、mp4、mp3等格式的转化,使用ffmpeg或segmenter完成对视频/音频格式文件的切割,切割为m3u8格式及ts文件

1、 为何要使用HTTP Live Streaming

可以参考wikipedia

HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体 网络传输协议。是苹果公司QuickTime X和iPhone软件系统的一部分。它的工作原理是把整个流分成一个个小的基于HTTP的文件来下载,每次只下载一些。当媒体流正在播放时,客户端可以选择从许多不同的备用源中以不同的速率下载同样的资源,允许流媒体会话适应不同的数据速率。在开始一个流媒体会话时,客户端会下载一个包含元数据的extended M3U (m3u8) playlist文件,用于寻找可用的媒体流。

HLS只请求基本的HTTP报文,与实时传输协议(RTP)不同,HLS可以穿过任何允许HTTP数据通过的防火墙或者代理服务器。它也很容易使用内容分发网络来传输媒体流。

2、 HTTP Live Streaming技术方案

HTTP服务:使用Nginx提供HTTP服务,通过使用nginx-rtmp-module https://github.com/arut/nginx-rtmp-module 来增加对HLS的支持

使用ffmpeg来完成对flv、mp4、mp3等格式的转化,使用ffmpeg或segmenter完成对视频/音频格式文件的切割,切割为m3u8格式及ts文件

3、 准备工作

操作系统CentOS

3.1、准备安装删除已安装包

yum erase ffmpeg x264 x264-devel

3.2、安装各种依赖包

yum install gcc make nasm pkgconfig wget curl curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 pcre.i386 pcre.x86_64 pcre-devel.i386 pcre-devel.x86_64

3.3、安装git

wget -O git-devel.zip https://github.com/msysgit/git/archive/devel.zip

unzip git-devel.zip

cd git-devel/

autoconf

./configure

make

make install

3.4、创建安装包目录

mkdir ~/ffmpeg-source

4、 安装ffmpeg及其依赖包

4.1、Yasm

cd ~/ffmpeg-source

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

4.2、x264

cd ~/ffmpeg-source

git clone git://git.videolan.org/x264

cd x264

./configure –enable-shared

make

make install

4.3、LAME

cd ~/ffmpeg-source

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

4.4、libogg

cd ~/ffmpeg-source

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

4.5、libvorbis

cd ~/ffmpeg-source

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

4.6、libvpx

cd ~/ffmpeg-source

git clone http://git.chromium.org/webm/libvpx.git

cd libvpx

./configure –enable-shared

make

make install

4.7、 FAAD2

cd ~/ffmpeg-source

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

4.8、FAAC

cd ~/ffmpeg-source

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

./configure

make

make install

4.9、Xvid

cd ~/ffmpeg-source

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

4.10、FFmpeg

cd ~/ffmpeg-source

git clone git://source.ffmpeg.org/ffmpeg

cd ffmpeg

./configure –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

ldconfig –v



5、 安装nginx及nginx-rtmp-module

  
  
  1. mkdir ~/nginx-source 
  2.  
  3. cd  ~/nginx-source 
  4.  
  5. wget http://nginx.org/download/nginx-1.2.4.tar.gz 
  6.  
  7. tar zxvf nginx-1.2.4.tar.gz 
  8.  
  9. wget -O nginx-rtmp-module.zip  https://github.com/arut/nginx-rtmp-module/archive/master.zip 
  10.  
  11. unzip nginx-rtmp-module.zip 
  12.  
  13. wget -O ngx_cache_purge.zip https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip 
  14.  
  15. unzip ngx_cache_purge.zip 
  16.  
  17. cd nginx-1.2.4 
  18.  
  19. ./configure –user=daemon –group=daemon –prefix=/usr/local/nginx-1.2.4/ –add-module=../nginx-rtmp-module-master –add-module=../nginx-rtmp-module-master/hls –add-module=../ngx_cache_purge-master  –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-md5=/usr/lib –with-sha1=/usr/lib –with-http_gzip_static_module 
  20.  
  21. 在nginx.conf中增加rtmp模块的相关配置,配置例子 
  22.  
  23. rtmp { 
  24.  
  25. server { 
  26.  
  27. listen 1935; 
  28.  
  29. chunk_size 4000; 
  30.  
  31. # TV mode: one publisher, many subscribers 
  32.  
  33. application mytv { 
  34.  
  35. # enable live streaming 
  36.  
  37. live on; 
  38.  
  39. # record first 1K of stream 
  40.  
  41. record all; 
  42.  
  43. record_path /tmp/av; 
  44.  
  45. record_max_size 1K; 
  46.  
  47. # append current timestamp to each flv 
  48.  
  49. record_unique on; 
  50.  
  51. # publish only from localhost 
  52.  
  53. allow publish 127.0.0.1; 
  54.  
  55. deny publish all; 
  56.  
  57. #allow play all; 
  58.  
  59.  
  60. # Transcoding (ffmpeg needed) 
  61.  
  62. application big { 
  63.  
  64. live on; 
  65.  
  66. # On every pusblished stream run this command (ffmpeg) 
  67.  
  68. # with substitutions: $app/${app}, $name/${name} for application & stream name. 
  69.  
  70.  
  71. # This ffmpeg call receives stream from this application & 
  72.  
  73. # reduces the resolution down to 32×32. The stream is the published to 
  74.  
  75. # ‘small’ application (see below) under the same name. 
  76.  
  77.  
  78. # ffmpeg can do anything with the stream like video/audio 
  79.  
  80. # transcoding, resizing, altering container/codec params etc 
  81.  
  82.  
  83. # Multiple exec lines can be specified. 
  84.  
  85. exec /usr/local/bin/ffmpeg -re -i rtmp://localhost:1935/$app/$name -vcodec flv -acodec copy -s 32×32 -f flv rtmp://localhost:1935/small/${name}; 
  86.  
  87.  
  88. application small { 
  89.  
  90. live on; 
  91.  
  92. # Video with reduced resolution comes here from ffmpeg 
  93.  
  94.  
  95. application mypush { 
  96.  
  97. live on; 
  98.  
  99. # Every stream published here 
  100.  
  101. # is automatically pushed to 
  102.  
  103. # these two machines 
  104.  
  105. #push rtmp1.example.com; 
  106.  
  107. #push rtmp2.example.com:1934; 
  108.  
  109.  
  110. application mypull { 
  111.  
  112. live on; 
  113.  
  114. # Pull all streams from remote machine 
  115.  
  116. # and play locally 
  117.  
  118. #pull rtmp://rtmp3.example.com pageUrl=www.example.com/index.html; 
  119.  
  120.  
  121. # video on demand 
  122.  
  123. application vod { 
  124.  
  125. play /var/flvs; 
  126.  
  127.  
  128. application vod2 { 
  129.  
  130. play /var/mp4s; 
  131.  
  132.  
  133. # Many publishers, many subscribers 
  134.  
  135. # no checks, no recording 
  136.  
  137. application videochat { 
  138.  
  139. live on; 
  140.  
  141. # The following notifications receive all 
  142.  
  143. # the session variables as well as 
  144.  
  145. # particular call arguments in HTTP POST 
  146.  
  147. # request 
  148.  
  149. # Make HTTP request & use HTTP retcode 
  150.  
  151. # to decide whether to allow publishing 
  152.  
  153. # from this connection or not 
  154.  
  155. on_publish http://localhost:8080/publish; 
  156.  
  157. # Same with playing 
  158.  
  159. on_play http://localhost:8080/play; 
  160.  
  161. # Publish/play end (repeats on disconnect) 
  162.  
  163. on_done http://localhost:8080/done; 
  164.  
  165. # All above mentioned notifications receive 
  166.  
  167. # standard connect() arguments as well as 
  168.  
  169. # play/publish ones. If any arguments are sent 
  170.  
  171. # with GET-style syntax to play & publish 
  172.  
  173. # these are also included. 
  174.  
  175. # Example URL: 
  176.  
  177. #   rtmp://localhost/myapp/mystream?a=b&c=d 
  178.  
  179. # record 10 video keyframes (no audio) every 2 minutes 
  180.  
  181. record keyframes; 
  182.  
  183. record_path /var/vc; 
  184.  
  185. record_max_frames 10; 
  186.  
  187. record_interval 2m; 
  188.  
  189. # Async notify about an flv recorded 
  190.  
  191. on_record_done http://localhost:8080/record_done; 
  192.  
  193.  
  194. # HLS 
  195.  
  196. # HLS requires libavformat & should be configured as&nbs

    给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
    这里写图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值