【问题标题】:error in ffmpeg when sending image from pipe via php通过php从管道发送图像时ffmpeg出错
【发布时间】:2013-12-10 10:04:55
【问题描述】:

使用以下教程通过管道将上传的图像从 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

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

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

【问题讨论】:

  • 您需要显示您实际的、未编写脚本的 ffmpeg 命令和完整的 ffmpeg 控制台输出。尽管出现错误,输出文件是否可以正常播放?
  • @LordNeckbeard:感谢您的评论,ffmpeg 代码是在 php 中执行的。可能无法直接运行命令(如何将上传的文件作为管道输入传递。输出文件根本不会生成。(输出预期用于单个图像中的测试目的)即正在测试将上传的图像保存为 jpg只是为了测试php-ffmpeg管道通信
  • 在尝试使用 ffmpeg 获得帮助时,ffmpeg 控制台输出始终是重要信息。
  • 传输到 ffmpeg 的图像是什么格式的?
  • 图片格式为jpg/jpeg

标签: php ffmpeg pipe


【解决方案1】:

你打错了,需要告诉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 以对其进行重新编码,但我发现您的代码只是用于测试管道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多