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


Create thumbnail image from video in server in php

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

你可以使用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 创建视频缩略图

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

如果您在共享虚拟主机上,您可能需要查看像zencoder这样的服务,它可以生成转换后的视频流,包括缩略图:

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