1

我找到了一个代码,可以从视频及其作品中提取缩略图!但是当我尝试使用 php 文件打印带有 Content-Type 的图像时,它返回一个错误,当我尝试将它保存到服务器时它的工作正常!

编码:

<?php 
function captureVideoPosterImg($movie_file = '')
{
    extension_loaded('ffmpeg');
    // Instantiates the class ffmpeg_movie so we can get the information you want the video
    $movie = new ffmpeg_movie($movie_file);
    // Get The duration of the video in seconds
    echo $Duration = round($movie->getDuration(), 0);
    // Get the number of frames of the video
    $TotalFrames = $movie->getFrameCount();
    // Get the height in pixels Video
    $height = $movie->getFrameHeight();
    // Get the width of the video in pixels
    $width = $movie->getFrameWidth();
    //Receiving the frame from the video and saving
    // Need to create a GD image ffmpeg-php to work on it
    $image = imagecreatetruecolor($width, $height);
    // Create an instance of the frame with the class ffmpeg_frame
    $Frame = new ffmpeg_frame($image);
    // Choose the frame you want to save as jpeg
    $thumbnailOf = (int) round($movie->getFrameCount() / 2.5);
    // Receives the frame
    $frame = $movie->GetFrame($thumbnailOf);
    // Convert to a GD image
    $image = $frame->toGDImage();
    // Save to disk.
    //echo $movie_file.'.jpg';
    header('Content-Type: image/jpeg');
    imagejpeg($image,null,100);
}   
echo captureVideoPosterImg("smovie.mp4");
?>

文件转换为 UTF8 没有 bom。

谢谢!

4

0 回答 0