mp4文件的PHP FFmpeg转换问题


PHP FFmpeg conversion issues for mp4 files

我想通过使用ffmpeg-phpmp4文件中获取图像。

 $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);

然而,我得到一个错误消息说

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

我花了几个小时上网,但找不到这个问题的答案。有人能帮我一下吗?非常感谢!

您检查过PHP的ffmpeg库吗?我以前用过它,它抽象了所有复杂的命令行调用,比如你正在尝试运行的这个。您可以使用$movie->getFrame($n)来获取帧对象,并使用$frame->toGDImage()将其作为图像输出。

例如,

$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');

在http://ffmpeg-php.sourceforge.net/doc/api/查看文档