我在一个网站上工作,人们可以提交视频的链接。然后我就把它嵌入进去。但是,我希望获得视频的缩略图,而不将视频保存在我的服务器中。因此,当我列出视频时,我可以使用缩略图,而不是嵌入所有视频。
我的发球使用PHP。假设视频是SWF格式的。
或标签中是否有我可以“抓取”缩略图的内容?或者在PHP中,有什么东西可以远程获取远程视频的缩略图(或帧)?
有什么想法吗?
发布于 2012-08-16 08:21:49
我使用上面的一些代码片段和一些其他来源让它工作,下面是我的一些代码:
private function videoScreenshot($originalFile, $newFile, $percentage = 10)
{
// Check ffmpeg is configured
$config = Nutshell::getInstance()->config;
$ffmpeg_dir = $config->plugin->Plupload->ffmpeg_dir;
if(!$ffmpeg_dir) return;
// Get the potision a percentage of the way in the video
$duration = $this->getVideoDuration($originalFile);
$position = ($duration * ($percentage / 100));
// save the screenshot
$command = "\"{$ffmpeg_dir}ffmpeg\" -i \"$originalFile\" -ss $position -f image2 \"$newFile\"";
shell_exec($command);
}
private function getVideoDuration($filename, $seconds = true)
{
$config = Nutshell::getInstance()->config;
$ffmpeg_dir = $config->plugin->Plupload->ffmpeg_dir;
if(!$ffmpeg_dir) return;
ob_start();
$command = "\"{$ffmpeg_dir}ffmpeg\" -i \"$filename\" 2>&1";
passthru($command);
$result = ob_get_contents();
ob_end_clean();
preg_match('/Duration: (.*?),/', $result, $matches);
$duration = $matches[1];
if($seconds)
{
$duration_array = explode(':', $duration);
$duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
}
return $duration;
}显然,如果您要在自己的类中使用这些函数,则需要替换这些行
$config = Nutshell::getInstance()->config;
$ffmpeg_dir = $config->plugin->Plupload->ffmpeg_dir;具有您自己的配置选项。
https://stackoverflow.com/questions/1474957
复制相似问题