2012-05-23 115 views
1

Iam使用ffmpeg和php爲動態視頻創建縮略圖。它將縮略圖保存到特定文件,然後使用php檢索它。我想爲所有類型的視頻創建縮略圖。 iam面臨的ffmpeg問題是iam無法爲帶有.mp4擴展名的視頻創建縮略圖。 ?使用ffmpeg創建mp4的縮略圖

<? 
$ffmpeg = '/usr/bin/ffmpeg/ffmpeg'; //to load the extension ffmpeg 

$video = '/path/to/video'.$file_thumb; //path to the video 

$image = '/store/it/here'; //path to store the thumbnail 

$interval = 5; 
$size = '640x480'; 

//It runs with the below command  
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size 
$image 2>&1"; 

>

回答

0

試試這個:

<?php 
    exec("$ffmpeg -itsoffset -105 -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image"); 
?> 

希望這有助於。

+0

上述命令做工精細。但我仍然無法創建MP4視頻的縮略圖。除mp4外,還爲所有其他視頻創建縮略圖。 – user1411837

0

試試這個:

的ffmpeg在Apache配置文件需要safe_mode Off

則需要代碼:

// where ffmpeg is located, such as /usr/sbin/ffmpeg 
$ffmpeg = 'ffmpeg'; 

// the input video file 
$video = 'videos/'.$file_thumb; 

// where you'll save the image 
$image = 'uploads/videothumb/'.strtotime("now").'.jpg'; 

// default time to get the image 
$second = 1; 

// get the duration and a random place within that 
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1"; 

shell_exec($cmd); 

我希望它的工作原理..

+0

對不起..上述作品爲所有視頻,但MP4。 – user1411837

0

驗證的ffmpeg安裝支持你要求的視頻。如果它運行獨立的PHP表單,請在計算機上的shell中嘗試。如果無法創建圖像,請先修復ffmpeg安裝。

ffmpeg的是一個免費的軟件項目,以及許多的它的相關人士都可以在協商的情況下你不能夠建立自己的副本:http://ffmpeg.org/consulting.html

2

您可以使用此。

$in = root/path/to/video/filename/with/extension 
$out = root/path/to/video/filename/with extension .jpg // always use jpg as image extension 

exec("/PATH/TO/FFMPEG -itsoffset -4 -i ".$in." -vcodec mjpeg -vframes 1 -an -f rawvideo -s 120x100 ".$out); 

它會在$ out位置創建120x100尺寸圖像的縮略圖併爲我工作。

-2

ffmpeg的是棄用現在你可以使用 「avconv」

這裏是樣品的例子。

avconv -itsoffset -4 -i VIDEO0001_8265186396728169230.mp4 -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg 
+0

它不被棄用。看到這篇文章:http://stackoverflow.com/questions/9477115/what-are-the-differences-and-similarities-between-ffmpeg-libav-and-avconv –

0

試試這個

$ffmpeg = '/usr/bin/ffmpeg/ffmpeg'; 
$video = '/path/to/video'.$file_thumb; //path to the video 
$image = '/store/it/here'; //path to store the thumbnail 
$interval = 1; 
$size = '640x480'; 
shell_exec($ffmpeg.' -i '. $video.' -deinterlace -an -ss $interval -t 00:00:01 -r 1 -y -s 1242x400 -vcodec mjpeg -f mjpeg '. $thumbnail.' 2>&1');