【问题标题】:Use both stdio and stout in the same child process在同一个子进程中同时使用 stdio 和 stout
【发布时间】:2021-04-23 00:24:00
【问题描述】:

我正在使用 ffmpeg 组合音频/视频 2 流并通过管道将它们表达出来。这是我的代码:

var ffmpeg = cp.spawn('ffmpeg', [
        // Set inputs
        '-i', 'pipe:4',
        '-i', 'pipe:5',
        // Map audio & video from streams
        '-map', '0:v',
        '-map', '1:a',
        // Keep encoding
        '-c', 'copy',
        '-movflags', 'frag_keyframe+empty_moov',
        '-f', 'mp4',
        // Define output file
        'pipe:1',
      ], {
        stdio: [
          /* Standard: stdin, stdout, stderr */
          'inherit', 'inherit', 'inherit',
          /* Custom: pipe:3, pipe:4, pipe:5 */
          'pipe', 'pipe', 'pipe',
        ],
      });
      video.pipe(ffmpeg.stdio[4]);
      audio.pipe(ffmpeg.stdio[5]);
      res.header('Content-Disposition', 'attachment; filename="video.mp4"');
      ffmpeg.stdout.pipe(res);

但是代码给出了一个错误,指出ffmpeg.stout 为空。经过一番研究,我发现你不能拥有 stdio 选项数组,否则 stout 将为空。有什么办法解决这个问题?

【问题讨论】:

    标签: node.js ffmpeg stream pipe child-process


    【解决方案1】:

    差不多两周后,我找到了答案。当我查看文档时,它说:

    如果子级不是在 stdio[1] 设置为“管道”的情况下生成的,则不会设置。

    我意识到我所要做的就是将中间的 inherit 更改为 pipe:

            stdio: [
              /* Standard: stdin, stdout, stderr */
              'inherit', 'pipe', 'inherit',
              /* Custom: pipe:3, pipe:4, pipe:5 */
              'pipe', 'pipe', 'pipe',
            ],
    

    还是谢谢。

    【讨论】:

      猜你喜欢
      • 2015-04-04
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      相关资源
      最近更新 更多