当通过php从管道发送图像时,ffmpeg中出现错误


error in ffmpeg when sending image from pipe via php

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

从php到ffmpeg 的图像管道

然而,它提出了一个eror,说管道中有无效数据。

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

下面的ffmpeg命令是从php中调用的,就像上面一样:

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

您有一个打字错误,需要告诉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

这将只是流式复制(re-mux),而不是重新编码。可以将其视为管道图像到输出的复制和粘贴。


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

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