ffmpeg
拡張機能を使用できます。以下は、ビデオから 6 つのサムネイルを選択するために私が書いた古いコードです。
注目すべき部分は次のとおりです。
$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" );
}
}
}