dongyue0225 2014-02-17 19:06
浏览 55

剪切视频缩略图在PHP中

I have found a code that pull out a thumbnail from a video and its work! but when I trying to make the php file to print the image with the Content-Type its return an error, when i tried to save it to the server its work fine!

the code:

<?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");
?>

the file in convert to UTF8 without bom.

thx!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算