在php中的服务器中创建缩略图

时间:2012-04-20 05:52:31

标签: php ffmpeg

在我的网站上,我可以选择上传用户的视频文件。在那里我想创建该视频的缩略图。我已尝试在本地系统中使用一些编码它工作正常。我试过相同的编码服务它不起作用。我检查了服务器中启用的ffmpeg,它被禁用了。他们是否有其他选择在服务器中创建缩略图而不启用ffmpeg?请帮我找到解决方案。

2 个答案:

答案 0 :(得分:3)

你可以使用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

答案 1 :(得分:1)

如果您不想使用ffmpeg,您也可以使用mencoder作为替代方案。但最终你需要安装ffmpeg / mencoder,然后使用它来渲染缩略图,因为PHP没有处理视频的内置功能。<​​/ p>

如果您使用的是共享虚拟主机,则可能需要查看zencoder等服务,这些服务可以生成转换后的视频流,包括缩略图:

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