使用 PHP 处理时 FFmpeg“无法打开文件”错误消息

Fly*_*Cat 2 php ffmpeg

我正在使用ffmpeg从几个视频文件中获取图像。我ffmpeg准备好了代码,但是当我exec编写代码时出现以下错误。

ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
built on Apr  2 2013 17:02:36 with gcc 4.6.3

*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
//files info...
//files info...
Incompatible pixel format 'yuv420p' for codec 'mjpeg', auto-selecting format 'yuvj420p'
//file info...
[buffer @ 0x1513c40] Buffering several frames is not supported. Please consume all available frames before adding a new one.
 Last message repeated 75 times
[image2 @ 0x1513460] Could not open file : /test/project
av_interleaved_write_frame(): Input/output error
Run Code Online (Sandbox Code Playgroud)

我只显示突出显示颜色的错误消息。我的代码:

 $ffmpeg ="/usr/bin/ffmpeg";

 $image_source_path = '/test/project/test.mp4';
 $ALL_PLACE_WIDTH = 300;
 $ALL_PLACE_HEIGHT = 300;

 $image_cmd = " -r 1 -ss 00:00:10 -t 00:00:01 -s ".$ALL_PLACE_WIDTH."x".$ALL_PLACE_HEIGHT."   -f image2 " ;

 $dest_image_path = '/test/project';

 $str_command= $ffmpeg  ." -i " . $image_source_path . $image_cmd .$dest_image_path;
 shell_exec($str_command);
Run Code Online (Sandbox Code Playgroud)

看来我的 Linux 想让我切换到avconv. 我不确定如何修复这些错误。有人可以给我一个提示吗?

slh*_*hck 6

您应该始终显示完整的输出,而不是剪掉部分。在您的示例中,如果您显示的是实际ffmpeg执行的命令行而不是其周围的整个 PHP 代码,则错误会更加明显。

在你的情况下,你的问题是命令看起来像:

ffmpeg -i /test/project/test.mp4 -r 1 -ss 00:00:10 -t 00:00:01 -f image2 /test/project
Run Code Online (Sandbox Code Playgroud)

但是,/test/project是文件夹,而不是有效的输出图像路径。/text/project/image%04d.jpg如果您想从image0001.jpg以后创建图像,您可以使用。

如果您的真正目标只是导出一个缩略图,请使用以下vframes选项:

ffmpeg -i /test/project/test.mp4 -r 1 -ss 00:00:10 -vframes 1 /test/project/image.jpg
Run Code Online (Sandbox Code Playgroud)

在 newer 中ffmpeg,您也可以使用-frames:v


您可以ffmpeg在 Ubuntu 中使用,但它是旧版本。您可以使用avconv来自Libavffmpeg来自FFmpeg的原始文件- 我建议从 source 编译它