【问题标题】:Using a pipe character | with child_process spawn使用管道字符 |与 child_process spawn
【发布时间】:2023-03-19 22:51:01
【问题描述】:

我在树莓派上运行 nodejs,我想运行一个子进程来生成一个网络摄像头流。

在节点之外我的命令是:

raspivid -n -mm matrix -w 320 -h 240 -fps 18 -g 100 -t 0 -b 5000000 -o - | ffmpeg -y -f h264 -i - -c:v copy -map 0:0 -f flv -rtmp_buffer 100 -rtmp_live live "rtmp://example.com/big/test"

对于child_process,我必须分解每个论点

var args = ["-n", "-mm", "matrix", "-w", "320", "-h", "240", "-fps", "18", "-g", "100", "-t", "0", "-b", "5000000", "-o", "-", "|", "ffmpeg", "-y", "-f", "h264", "-i", "-", "-c:v", "copy", "-map", "0:0", "-f", "flv", "-rtmp_buffer", "100", "-rtmp_live", "live", "rtmp://example.com/big/test"];
camera.proc = child.spawn('raspivid', args);

但是它在| 字符上卡住了:

error, exit code 64
Invalid command line option (|)

如何使用这个管道字符作为参数?

【问题讨论】:

    标签: node.js ffmpeg child-process


    【解决方案1】:

    这已在另一个问题中得到解答:Using two commands (using pipe |) with spawn

    总之,child.spawn args 中的所有内容都应该是您的“raspivid”命令的参数。在您的情况下,管道及其之后的所有内容实际上都是 sh 的参数。

    一种解决方法是调用 child.spawn('sh', args),其中 args 是:

     var args = ['-c', <the entire command you want to run as a string>];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      • 2019-06-05
      • 2016-09-21
      • 2020-09-10
      • 2023-01-25
      • 2016-09-01
      • 2021-11-27
      相关资源
      最近更新 更多