0

在此处输入图像描述如何创建类似 youtube 的视频预览?那是在youtube中,当我们将鼠标悬停在进度条上时,它正在显示视频的预览?如何使用 ffmpeg 或 mencoder 进行这种预览,或者有没有其他方法可以做到这一点?看看这张图片。请到这里进行实时预览。

http://www.youtube.com/watch?v=yto4_QFoLdA&feature=watch-now-button&wide=1

4

1 回答 1

3

您可以使用ffmpeg扩展程序。下面是我编写的一些古老代码,用于从视频中选择六个缩略图。

值得注意的部分是:

$frame = $vid->getFrame(); // pull a frame from the video
$gd = $frame->toGDImage(); // turn the frame into a GD image
imagejpeg($gd, "filename.jpg", 70); // save jpeg of the frame using 70% quality

$vid = new ffmpeg_movie ( $fileName );
$frameRate = $vid->getFrameRate ();
$gapSize = max(10,$vid->getDuration()-10) * $frameRate / 6;
$n = 0; $curFrame = 5 * $frameRate;
while ( $n != 6 ) {
    $f = $vid->getFrame ( $curFrame );
    if ((1==$curFrame && false!==$f) || false !== ($f = $vid->getNextKeyFrame ())) {
        $thumbnails [$n] = array (
            'path' => "muveethumb-$muveeId-$n.jpg", 
            'time' => ceil ( ($vid->getFrameNumber () - 1) * 1000 / $frameRate ) 
        );
        $gd = $f->toGDImage ();
        imagejpeg ( $gd, $targetFolder.$thumbnails [$n] ['path'], 70 );
        ++ $n;
        $curFrame += $gapSize;
    } elseif ($n > 0) {
        while ( $n != 6 ) {
            $thumbnails [] = $thumbnails [$n - 1];
            ++ $n;
        }
    } else {
        if ($curFrame!=1) {
            // attempt to get first frame as a last resort
            $curFrame = 1;
        } else {
            // unless we already tried that
            throw new Exception ( "Could not create thumbnails" );
        }
    }
}
于 2012-06-11T04:55:27.107 回答