通过php从管道发送图像时ffmpeg中的错误

时间:2013-12-10 10:04:55

标签: php ffmpeg pipe

使用以下教程通过管道从php发送上传的图像到ffmpeg。

Image pipe from php to ffmpeg

然而,它引发了一个错误,说管道中有无效数据。

pipe:: Invalid data found when processing input

以下是用于上传图像文件的php代码

$tempPath = $_FILES['vdofile']['tmp_name'];

print_r($tempPath);

$descriptorspec = array(
    0 => array("pipe", "r"), // stdin is a pipe that the child will read from
    1 => array("pipe", "w"), // stdout is a pipe that the child will write to
    2 => array("file", "error-output.txt", "a") // stderr is a file to write to
    );

$img = imagecreatefromjpeg($tempPath);

 $proc = proc_open("ffmpeg image2pipe -i - -y image.jpg", $descriptorspec, $pipes);

 if (is_resource($proc)) {     
     /*
      * $pipes[0] = write something to command being run
      * $pipes[1] = read something from command
      * $pipes[2] = error from command 
      */
       fwrite($pipes[0], $_FILES['vdofile']['tmp_name']);
       fclose($pipes[0]);
 }
 proc_close($proc);
?>

和简单的html上传代码如下:

 <form action="upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="vdofile" />

        <input type="submit" value="Upload" />
    </form>

生成的错误文件如下:

    ffmpeg version N-58485-ga12b4bd Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 26 2013 22:07:02 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 55.100 / 52. 55.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.102 / 55. 21.102
  libavdevice    55.  5.101 / 55.  5.101
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
pipe:: Invalid data found when processing input

任何帮助将不胜感激。

**

修改

**

代码仍会产生错误:

    ffmpeg version N-58485-ga12b4bd Copyright (c) 2000-2013 the FFmpeg developers
  built on Nov 26 2013 22:07:02 with gcc 4.8.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 55.100 / 52. 55.100
  libavcodec     55. 44.100 / 55. 44.100
  libavformat    55. 21.102 / 55. 21.102
  libavdevice    55.  5.101 / 55.  5.101
  libavfilter     3. 91.100 /  3. 91.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
[image2pipe @ 00000000029ee0a0] Could not find codec parameters for stream 0 (Video: none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
pipe:: could not find codec parameters

从上面的php中调用以下ffmpeg命令:

ffmpeg -f image2pipe -i - -vcodec mjpeg -vframes 1 -an -f mjpeg image.mp4

1 个答案:

答案 0 :(得分:0)

你有一个拼写错误,你需要告诉ffmpeg管道图像是什么格式:

变化:

ffmpeg image2pipe -i - -y image.jpg

要:

ffmpeg -y -f image2pipe -codec:v mjpeg -i - image.jpg

此示例会将输入管道图像重新编码为image.jpg

ffmpeg -y -f image2pipe -codec:v mjpeg -i - -codec copy image.jpg

这只是stream copy(重新多路复用)而不是重新编码。可以将其视为将管道图像复制并粘贴到输出中。


您仍然可以获得pipe:: Input/output error,但您可以忽略它,因为流复制的图像与我的测试中的输入具有相同的md5哈希值。

我认为没有理由将单个图像传输到ffmpeg以重新编码它,但我发现你的代码只是用于测试管道。