« Vtiger CRM 客戶關係管理系統安裝實錄 | 首頁 | 在 Acer Aspire 5920G 安裝 XP »

2007年08月22日

用 lighttpd 建立 FLV 影片網站

影片轉檔

安裝 ffmpeg

安裝 flvtool2

影片轉 FLV 檔

ffmpeg -i myvideo.wmv -s 320x240 -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 320x240 -f image2 myvideo.jpg

#截錄第 18.5 秒的畫面
ffmpeg -i myvideo.mpg -ss 18.5 -vframes 1 -s 320x240 -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

Ref: [DB75]: Using FFmpeg to Extract PNG Files

建置影片播放平台

環境:

  • lighttpd 1.4.11 以上
  • DocumentRoot: /var/www/html

lighttpd 環境設定

安裝 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 = 120

#Ref: LightTPD Docs -- Module: mod_secdownload

mkdir /var/www/videos :: 將 .flv 檔案置入 /var/www/videos

/etc/init.d/lighttpd restart :: 重新啟動 lighttpd

取用加密路徑

JW FLV Player 使用範例

JW FLV Player 播放實例

備註: 以上影片係用 Nikon Coolpix 4300 攝錄, 只有畫面沒有聲音

JW FLV Player 相關網頁


Free Flash Video Players

參考資料

相關網頁

Posted by Jamyy at 2007年08月22日 12:04

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/301

Comments

對外只有256kbps?真的嗎!
每次看你的blog開網頁的速度都滿快的

Posted by: solong at 2007年08月23日 11:27

真的只有 256kbps
自從改用 lighttpd 之後, 覺得速度又更快了些 :)

Posted by: Jamyy at 2007年08月23日 13:14

請問如何用 ffmpeg 取得一個影片的總時間長度,
我看了他所有的參數 似乎沒有

Posted by: paza at 2007年10月23日 19:35

用 ffplay 的 stats 參數即可查出影片總時間長度 (Duration)

可自行撰寫一個 shell script 來取出 Duration 的值:

vi get_duration.sh

內容:

#!/bin/bash

tmp="/tmp/tempfile"
ffplay -stats -nodisp -an -vn $1 &> $tmp
grep Duration $tmp | awk '{ print $2 }' | cut -d ',' -f 1

賦予執行權限: chmod +x get_duration.sh

執行範例: ./get_duration.sh myfile.wmv

回傳: 00:01:39.8

Posted by: Jamyy at 2007年10月24日 10:05

請問一下能不能說明一下flvtool2 能不能不裝押@@?
不做轉檔純粹把自己抓下來的flv檔案放到網頁上撥的話~
flvtool2不裝會怎麼樣嗎?

Posted by: zac at 2008年01月05日 16:48

flvtool2 是針對自己轉檔的 flv 檔案加入 metadata
這樣才能讓 user 用滑鼠控制影片播放 (快轉 / 倒退)
若是從 youtube 這種網站下載的 flv 檔, 是可以不用再經過 flvtool2 處理的, 因為檔案裡面已經有 metadata 了

Posted by: Jamyy at 2008年01月05日 17:13

不好意思要再請問一下^^"
那如果這段都不加上的話
secdownload.secret = "your_secret"
secdownload.document-root = "/var/www/videos/" #.flv 存放的位置
secdownload.uri-prefix = "/dl/" #編碼後的虛擬路徑
secdownload.timeout = 120
會怎樣嗎@@? 因為我還把secdownload.uri-prefix這段拿掉了一樣能跑耶@@"~

Posted by: zac at 2008年01月06日 17:29

secdownload 的作用是隱藏原始檔案的檔名與路徑, 讓 client 無法直接連結目的檔案, 達到保護原始檔案的目的.
這個部份和 FLV Streaming 沒有關係, 所以就算省略也不會影響播放功能.

Posted by: Jamyy at 2008年01月06日 23:34

所以如果我只是要讓他能撥放FLV 的話~
就是把"mod_flv_streaming" 的#拿掉
然後這個也要加上
flv-streaming.extensions = ( ".flv" )
這樣就行了嗎!? 其他都不用碰嗎@@? 只做這兩個步驟~

Posted by: ajneok at 2008年01月07日 00:22

是的, 剩下的就是 Flash FLV Player 的工作了

Posted by: Jamyy at 2008年01月07日 13:13

最近try了一個動作~我發現我什麼事情都不做的話,純粹用Flash FLV Player一樣可以撥flv檔案耶@@"~ why ?

Posted by: ajneok at 2008年01月18日 18:46

哈~ 真的耶! 而且不只是 lighttpd 可以, 在 apache http server 一樣只要那個 flash 就可以播放耶 ^^'

今天研究這個問題的時候, 找到了以下的應用實例:

Step 1. 啟用 lighttpd 的 mod_flv_streaming
Step 2. 把 http://tinyurl.com/cpcma 裡面所提供的 php 程式和 .flv 檔案放在 lighttpd server 上
Step 3. 於另外一台 apache http server 主機安裝 flash flv player (如: http://tinyurl.com/2cyjss)
Step 4. 把 mediaplayer.html 裡的 "file" 改成剛剛放進 lighttpd 裡的 .flv 檔名, 並新增一個變數: "streamscript", 內容為 "http://lighttpd/flvprovider.php"
Step 5. 瀏覽器連入 mediaplayer.html 所在的 web server, 此時所播放的 flv 影片是來自 lighttpd 那台 server

原本以為這就是 mod_flv_streaming 的效果, 可是當我把 flvprovider.php 放到 apache http server 之後 (角色置換), 發現一樣可以播放...

文件說 mod_flv_streaming 可以在 .flv 之後加上 ?start= 的參數來直接控制 flv 影片, 可是我試不出來有什麼效果 = ="

Posted by: Jamyy at 2008年01月24日 13:45

Jamyy 方便交換msn嗎 :)

Posted by: ajneok at 2008年01月24日 15:10

您好,
我大不懂您說保護原始檔的意思???
透過URL還是一樣下載的到.flv不是嗎???

Posted by: WayneSan at 2008年02月15日 18:04

WayneSan 您好,

透過那個保護機制所產生的網址是暫時性的
過了指定的秒數後, 那個 URL 就失效了
必須重新連入伺服器, 取得新的隨機編碼 URL
才能再連到那個影片檔

在暫時性的 URL 還有效的時候, 檔案一樣是可以被下載的
所以這種保護機制只能用來防止檔案被盜連、大量下載而已
您可以參考:
http://hc.gh1220.idv.tw/simple/index.php?t186.html

Posted by: Jamyy at 2008年02月19日 09:34