最近研究了一下Http Live Streaming机制,顺便搭建了一个测试环境。
参考:http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/comment-page-1/
Step 1: 编译ffmpeg
这个就不多讲了,先要编译facc和x264
a)编译faac和faad b)编译x264 c)编译ffmpeg configure --enable-gpl --enable-nonfree --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264 Step2: 视频文件编码使用:Step3: 下载和编译Segmenter http://svn.assembla.com/svn/legend/segmenter/ 需要修改一下Makefile
- configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libx264
- all:
- gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad
- clean:
- rm segmenter
例如: segmenter sample_low.ts 10 sample_low stream_low.m3u8 http://www.ioncannon.net/ Step4:搭建HTTP Server 以Tomcat为例,修改conf/web.xml文件,增加
- segmenter <input MPEG-TS file> <segment duration in seconds> <output MPEG-TS file prefix> <output m3u8 index file> <http prefix>
指定.m3u8和.ts的MIME类型 .m3u8 application/x-mpegURL .ts video/MP2T Step5: 测试流媒体服务器 a)用iPhone的Safari浏览器,注意访问的地址是服务器上以.m3u8后缀的文件 b)用支持html5的浏览器,我还没有试验
- <mime-mapping>
- <extension>m3u</extension>
- <mime-type>audio/x-mpegurl</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>m3u8</extension>
- <mime-type>application/x-mpegurl</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>ts</extension>
- <mime-type>video/MP2T</mime-type>
- </mime-mapping>
这样在iPhone上就可以播放流媒体了。
- <html>
- <head>
- <title>Video Test</title>
- <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
- </head>
- <body style="background-color:#FFFFFF; " mce_style="background-color:#FFFFFF; ">
- <center>
- <video width='150' height='150' src="stream-128k.m3u8" mce_src="stream-128k.m3u8" />
- </center>
- </body>
- </html>