【问题标题】:Create thumbnail image from video in server in php在php中从服务器中的视频创建缩略图
【发布时间】:2012-04-20 05:52:31
【问题描述】:

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

【问题讨论】:

标签: php ffmpeg


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    如果您使用的是共享虚拟主机,您可能需要研究 zencoder 之类的服务,它可以为您生成转换后的视频流,包括缩略图:

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

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 1970-01-01
      • 2021-04-24
      • 2017-12-10
      • 2011-04-17
      • 2014-02-06
      • 2011-04-24
      • 2011-09-03
      相关资源
      最近更新 更多