2012-04-20 125 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