2014年11月24日

Apache mod_h264 影片串流模組

Apache2 加上 H264 streaming module 後,就能支援影片串流的功能,安裝方式也相當容易。但特別注意到授權部份,非商業使用是採 Creative Commons 授權可免費使用,而商業用途則是要付費的,費用我覺得還滿便宜的,一台伺服器才39歐元,詳細資訊請參閱官方網站說明 

安裝程序 

首先到首頁下載tarball安裝檔並解壓縮
shell># wget http://h264.code-shop.com/download/apache_mod_h264_streaming-2.2.7.tar.gz
shell># tar xzvf apache_mod_h264_streaming-2.2.7.tar.gz

確認系統是否有安裝apxs套件,沒有的話自行用yum安裝
shell># rpm -q httpd-devel
shell># yum -y install httpd-devel

編譯安裝
shell># cd apache_mod_h264_streaming-2.2.7
shell># ./configue --with-apxs=/usr/sbin/apxs
shell># make && make install
shell># ls /etc/httpd/modules/mod_h264_streaming.so
/etc/httpd/modules/mod_h264_streaming.so

設定 httpd.conf
shell># vim /etc/httpd/conf/httpd.conf
加上以下兩行
LoadModule h264_streaming_module modules/mod_h264_streaming.so
AddHandler h264-streaming.extensions .mp4
__儲存離開__

重啟httpd完成安裝
shell># service httpd restart

測試

下載完整影片
shell># wget -O sample.mp4 "http://1.2.3.4/sample.mp4"

給予影片起始時間
shell># wget -O 500_sample.mp4 "http://1.2.3.4/sample.mp4?start=500"

比較下載的兩個檔案大小,若有不一樣代表設定成功

除錯


若無法正常播放影片時,請先確認 Apache access_log,http status code是否為 415,若是可能是影片編碼格式問題導致無法播放,可以用ffmpeg確認問題
1.2.3.4 - - [24/Nov/2014:11:01:38 +0800] "GET /content/1080p.mp4 HTTP/1.1" 415 263 "http://1.2.3.4/player.php?file=/content/1080p.mp4" "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36"

編碼

若需要自己處理轉碼,可以參考官網 wiki 採用的參數
How to convert video in H264 format

另外FFMPEG有份值得參考的文件
https://trac.ffmpeg.org/wiki/Encode/H.264

沒有留言:

張貼留言