node.js - 在同一个子进程中同时使用 stdio 和 stout

标签 node.js ffmpeg stream pipe child-process

我正在使用 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 将为空。有任何解决这个问题的方法吗?

最佳答案

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

If the child was not spawned with stdio[1] set to 'pipe', then this will not be set.


我意识到我所要做的就是改变中间 inheritpipe :
        stdio: [
          /* Standard: stdin, stdout, stderr */
          'inherit', 'pipe', 'inherit',
          /* Custom: pipe:3, pipe:4, pipe:5 */
          'pipe', 'pipe', 'pipe',
        ],
不管怎么说,多谢拉。

关于node.js - 在同一个子进程中同时使用 stdio 和 stout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65779026/

相关文章:

javascript - async.js 从最后一个函数返回值

bash - 使用 ffmpeg 批量降低 mp3 音频文件的比特率和大小

scala - Akka 流 : What is the difference between Unzip and Broadcast?

javascript - Node js .10 fs.createReadStream streams2 结束事件未触发

javascript - Showdown Markdown 不替换字符串

javascript - Node.js 忽略除第一个参数之外的所有查询字符串参数

ffmpeg - Windows 媒体播放器的 Wav 文件持续时间与 ffmpeg 不同

从 DTS 转码到 AAC 时音频丢失

c++ - 重新排列文本文件中的行列

javascript - GraphQL:为构建模式提供的一种类型缺少名称