Rouge
Rouge

Reputation: 4239

PHP FFmpeg conversion issues for mp4 files

I want to get the images out of a mp4 file by using ffmpeg-php.

I have

 $str_command= '/usr/bin/ffmpeg -i /test/ts.mp4 -r 1 -ss 00:00:10 -t 00:00:01 -s 300x300 -f image2 /test/images/';
 shell_exec($str_command);

However, I got an error message saying

 Buffering several frames is not supported. Please consume all available frames before adding a new one.

I have spent hours on web but couldn't find the answer for this. Can anyone help me about this? Thanks so much!

Upvotes: 1

Views: 879

Answers (1)

jraede
jraede

Reputation: 6896

Have you checked out the ffmpeg library for PHP? I've worked with it before and it abstracts away all of the complicated command line calls like the one you're trying to run. You can use $movie->getFrame($n) to get the frame object, and $frame->toGDImage() to output it as an image.

For example,

$movie = new ffmpeg('/path/to/movie.mp4');
$frame10 = $movie->getFrame(10);
$image = $frame10->toGDImage();

// Now display the image
header('Content-Type: image/jpeg');
imagejpeg($image);

// Or save it to a file
$saved = imagejpeg($image, '/path/to/new/file.jpg');

Check out the documentation at http://ffmpeg-php.sourceforge.net/doc/api/

Upvotes: 3

Related Questions