1

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 />';
Wiggler Jtag
  • 669
  • 8
  • 23

1 Answers1

5

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.
Omega
  • 1,101
  • 9
  • 14
  • Yes I was using FFmpeg-php that old one, in dotdeb package it was called php5-ffmpeg .... It took me 51 seconds to generate 200k th frame, now installed ffmpeg and done exec(), image was saved in 0.08s, which is impressive! thanks a lot - upvote! one question: where can I find some list of variables for ffmpeg? If I would like to reduce image quality to 80 or extract some info about video file - like frame count, length and so on? thanks :] – Wiggler Jtag Apr 25 '13 at 12:39
  • That 51 seconds explain how terribly slow it was, good job for updating! Try reading the [FFmpeg CLI documentation](http://www.ffmpeg.org/ffmpeg.html), it describes almost everything you just asked for. Also the internet is full of tutorials. – Omega Apr 25 '13 at 12:45