2012-05-23 157 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');