首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >视频缩略图

视频缩略图
EN

Stack Overflow用户
提问于 2009-09-25 09:07:43
回答 1查看 7.3K关注 0票数 3

我在一个网站上工作,人们可以提交视频的链接。然后我就把它嵌入进去。但是,我希望获得视频的缩略图,而不将视频保存在我的服务器中。因此,当我列出视频时,我可以使用缩略图,而不是嵌入所有视频。

我的发球使用PHP。假设视频是SWF格式的。

或标签中是否有我可以“抓取”缩略图的内容?或者在PHP中,有什么东西可以远程获取远程视频的缩略图(或帧)?

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2012-08-16 08:21:49

我使用上面的一些代码片段和一些其他来源让它工作,下面是我的一些代码:

代码语言:javascript
复制
    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;
    }

显然,如果您要在自己的类中使用这些函数,则需要替换这些行

代码语言:javascript
复制
    $config = Nutshell::getInstance()->config;
    $ffmpeg_dir = $config->plugin->Plupload->ffmpeg_dir;

具有您自己的配置选项。

github上提供了完整的pluginframework,此代码片段来自here

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1474957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档