Tit*_*tan 4 ffmpeg child-process node.js
我在树莓派上运行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 (|)
如何将此管道字符用作参数?
小智 11
这已在另一个问题中得到解答:使用两个命令(使用pipe |)和spawn
总之,child.spawn一切都args应该是你的'raspivid'命令的参数.在您的情况下,管道及其后的所有内容实际上都是参数sh.
解决方法是调用child.spawn('sh', args)args所在的位置:
var args = ['-c', <the entire command you want to run as a string>];
Run Code Online (Sandbox Code Playgroud)