2012-04-20 124 views
3

在我的網站上,我有一個選項可以由用戶上傳視頻文件。我想創建該視頻的縮略圖。我曾嘗試在本地系統與一些編碼它工作正常。我嘗試了相同的代碼來維護它不起作用。我檢查了服務器中啓用的ffmpeg,它被禁用。他們是否有其他選擇在服務器中創建縮略圖,而不啓用ffmpeg?請幫我找到解決方案。從服務器的視頻在php中創建縮略圖圖像

+0

我不能在我的本地''EXEC創建截圖( 「ffmpeg -i $ remoteVideo -ss 00:00:01.000 -vframes 1 $ destImagePath」);' – Hitesh 2014-11-28 10:42:01

+0

可以看看我的問題嗎?請http://stackoverflow.com/questions/27189948/ffmpeg-is-not -creating-screenshot-from-video – Hitesh 2014-11-28 13:52:04

回答

1

如果你不想使用ffmpeg,你也可以使用mencoder作爲替代。但最後你需要安裝ffmpeg/mencoder,然後使用它來渲染縮略圖,因爲PHP沒有內置的功能來處理視頻。

如果你是一個共享的虛擬主機提供商,你可能想看看像zencoder服務,會爲你生成轉換後的視頻,包括縮略圖的流:

https://app.zencoder.com/docs/api/encoding/thumbnails

+0

他說的是準確的。 +1 – kingmaple 2012-04-20 06:12:01

2

可以使用ffmpeg(表格標記你我猜你知道)

你需要傳遞給ffmpeg的是什麼

-i = input file 
-deinterlace = deinterlace pictures 
-an = disable audio recording 
-ss = start time in the video (seconds) 
-t = duration of the recording (seconds) 
-r = set frame rate 
-y = overwrite existing file 
-s = resolution size 
-f = force format 

實例

// where ffmpeg is located 
$ffmpeg = '/usr/bin/ffmpeg'; 
//video dir 
$video = 'path/to/video'; 
//where to save the image 
$image = 'path/to/image.jpg'; 
//time to take screenshot at 
$interval = 5; 
//screenshot size 
$size = '640x480'; 
//ffmpeg command 
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1"; 

exec($cmd); 

或者嘗試

$second = 15; 
$cmd = "$ffmpeg -itsoffset -$second -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image"; 
exec($cmd); 

想你也應該看看細節勸阻上可能存在的問題

ffmpeg-php to create thumbnail of video