apache支持mp4的流播放
apache可以通过配置模块支持MP4和flv格式的视频流。Mod_h264 and mod_FLV Streaming for Apache 如果需要更多的视频流支持,建议使用 ffserver
下面以在centeros的apache上配置MP4模块的支持为例,首先是在apache端的配置
安装mod_h264_streaming
安装apache httpd的apxs:
1 | yum install httpd-devel |
如果apache是通过yum安装在系统中的话, 需要root权限:
1 | cd ~/download |
配置apache, 在httpd.conf中添加配置, mod_h264_streaming.so的路径可能不一样:
1 | AddType video/mp4 .mp4 .m4v |
重启apache. 然后可以在httpd的根目录下放入一个mp4的文件
编写一个html文件
例子如下:
1 | <!DOCTYPE html> |
pitfall
During I test using the html5 vedio tag to display the mp4 vedio, I only got the audio and no image at all when I open the html file with Chrome. And I tried with firefox, and got this error: “No video with supported format and MIME type found”.
I googled this error message, and didn’t get a direct answer about how to fix it.
And luckly, I found the reason. It turns out the html5 vedio tag support the vedio coded with H.264, and my mp4 file is coded with MPEG-4. So I used another mp4 file with coding format h.264, and it works well.
(As I googled, but failed to find the solution, I wrote this solution in English, so everyone can get help from my contribution,if he saw this on google).
关于MP4的一些知识
当前,html5的video 元素支持三种视频格式:
- Ogg = 带有 Theora 视频编码和 Vorbis 音频编码的 Ogg 文件
- MPEG4 = 带有 H.264 视频编码和 AAC 音频编码的 MPEG 4 文件
- WebM = 带有 VP8 视频编码和 Vorbis 音频编码的 WebM 文件
MP4只是一种封装而已, 能封装H264, XVID, VC-1等编码进去。MPEG-4是一种编码。
MP4现在常用的只有 H264 和 MPEG4格式, H263 和VP6格式 已淘汰。Xvid.Divx 不是什么格式. Xvid.Divx是MPEG4的编码器 X264是H264的编码器
reference
- http://g33kinfo.com/info/archives/4305
- http://universvideo.com/installing-apache-mod-h264/
- http://voice.firefallpro.com/2012/03/html5-audio-video-mime-types.html
查看模块加载状态
1 | apachectl -t -D DUMP_MODULES | grep h264_streaming_module |