我在树莓派上运行 nodejs,我想运行一个子进程来生成网络摄像头流。
在 Node 外我的命令是:
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 (|)
如何使用这个管道字符作为参数?
最佳答案
这已在另一个问题中得到回答: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>];
关于node.js - 使用管道字符 |与 child_process 产卵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968662/