微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在同一个子进程中同时使用 stdio 和 Stout

如何解决在同一个子进程中同时使用 stdio 和 Stout

我正在使用 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',/* Custom: pipe:3,pipe:4,pipe:5 */
          '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 将为空。有什么办法可以解决这个问题?

解决方法

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

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

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

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

还是谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。