使用管道字符| with child_process spawn

时间:2015-03-10 16:11:01

标签: node.js ffmpeg child-process

我在树莓派上运行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 (|)

如何将此竖线字符用作参数?

1 个答案:

答案 0 :(得分:10)

另一个问题已回答:Using two commands (using pipe |) with spawn

总之,对于child.spawnargs中的所有内容都应该是您的' raspivid'命令。在您的情况下,管道及其后面的所有内容实际上是sh的参数。

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

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