문제

first time I am trying to create thumbnail preview from video file, uploaded 700mb .avi film with 209747 frames. Now I am trying to create 1 thumbnail, but it takes 4.7 seconds, because I've set frame 10000, if I set it just to 1000, it takes only 0.4 seconds to generate thumbnail.

How could I generate like 5-10 thumbnails from different frames on-the-go in less than a second? Is it even possible? Is it different to use exec(ffmpeg) or php-ffmpeg? Using 0.6-svn ffmpeg, Debian 6.0.7, php 5.4.14 on machine 2x Xeon L5420 and still slow... Any ideas? How about to use ffmpeg + time of the video instead of frame?

$movie = 'ai.avi';
$thumbnail = 'thumbnail.jpg';

$mov = new ffmpeg_movie($movie);
$frame = 10000;
$frame = $mov->getFrame($frame);

if($frame) { 
  $gd_image = $frame->toGDImage();
  if($gd_image) {
    imagejpeg($gd_image, $thumbnail, 100);
    imagedestroy($gd_image);
  }
}
echo '<img src="'.$thumbnail.'" ><br />';
도움이 되었습니까?

해결책

First of all, you are using FFmpeg-php, not php-FFmpeg. These are two different projects, where your FFmpeg-php project is (extremely) old.

The process difference when changing the frame to the 10,000th or 1,000th frame is way too high, probably caused by the poor php-ffmpeg image-extracting function. You can try out the 200,000th frame where I expect it is taking like 80 seconds? If this is true, then the toGDImage() function is seriously way too slow!

Then you have some options to improve performance:

  1. Try to find out if you can adjust the toGDImage() function or use commands directly from FFmpeg-php, like ffmpeg -ss 00:10:00 -i input.avi -vframes 1 output.jpg
  2. Or try to implement the php-FFmpeg library, which contains a fast extractImage() function, which uses the command from above.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top