用 lighttpd 建立 FLV 影片網站
- 影片轉 FLV 檔, 並製作影片截圖
- 在 lighttpd web server 使用加密網址, 隱藏實際影片路徑
- 免費的 Flash FLV Player
影片轉檔
安裝 flvtool2
影片轉 FLV 檔
ffmpeg -i myvideo.wmv -s 320×240 -r 15 -b 128k -ar 22050 -ab 32k -ac 2 -f flv myvideo.flv
參數說明
-i input file name -s set video frame size -r set video frame rate -b set video bit rate -ar set audio sampling rate -ab set audio bit rate -ac set number of audio channels -f force format 加入 metadata
flvtool2 -U myvideo.flv myvideo.flv
製作影片截圖
#截錄第一個畫面 (frame)
ffmpeg -i myvideo.mpg -vframes 1 -s 320×240 -f image2 myvideo.jpg#截錄第 18.5 秒的畫面
ffmpeg -i myvideo.mpg -ss 18.5 -vframes 1 -s 320×240 -f image2 myvideo.jpg參數說明
-i input file name -vframes set the number of video frames to record -s set frame size -ss set the start time offset -f force format -y overwrite output files
建置影片播放平台
環境:
- lighttpd 1.4.11 以上
- DocumentRoot: /var/www/html
lighttpd 環境設定
vi lighttpd.conf
#注意順序: mod_secdownload 須在 mod_flv_streaming 之上
server.modules = (
…
“mod_secdownload”,
“mod_flv_streaming”,
…
)flv-streaming.extensions = ( “.flv” )
secdownload.secret = “your_secret”
secdownload.document-root = “/var/www/videos/” #.flv 存放的位置
secdownload.uri-prefix = “/dl/” #編碼後的虛擬路徑
secdownload.timeout = 120mkdir /var/www/videos :: 將 .flv 檔案置入 /var/www/videos
/etc/init.d/lighttpd restart :: 重新啟動 lighttpd
取用加密路徑
#前置作業
<?php$secret = “your_secret”;
$uri_prefix = “/dl/”;# filename
$f = “/test.flv”;# current timestamp
$t = time();$t_hex = sprintf(“%08x”, $t);
$m = md5($secret.$f.$t_hex);?>
#輸出加密路徑 (output: /dl/xxxxxxxx…)
<?php printf(‘%s%s/%s%s’, $uri_prefix, $m, $t_hex, $f, $f); ?>JW FLV Player 使用範例
<?php
$secret = “your_secret”;
$uri_prefix = “/dl/”;
$f = “/myvideo.flv”;
$t = time();
$t_hex = sprintf(“%08x”, $t);
$m = md5($secret.$f.$t_hex);
?>
<html>
<head>
<script type=”text/javascript” src=”swfobject.js”></script>
</head>
<body><p id=”player1″><a href=”http://www.adobe.com/go/getflashplayer”>Get the Flash Player</a> to see this player.</p>
<script type=”text/javascript”>
var s1 = new SWFObject(“flvplayer.swf”,”single”,”300″,”240″,”7″);
s1.addParam(“allowfullscreen”,”true”);
s1.addVariable(“file”,”<?php printf(‘%s%s/%s%s’, $uri_prefix, $m, $t_hex, $f, $f); ?>”);
s1.addVariable(“image”,”myvideo.jpg”);
s1.addVariable(“displayheight”,”240″);
s1.write(“player1″);
</script></body>
</html>JW FLV Player 相關網頁
Free Flash Video Players
參考資料
相關網頁
没有评论▼