将进程的stdout传递到node.js中另一个(ffmpeg)的stdin

时间:2019-01-24 07:42:36

标签: node.js

我正在尝试使用节点重现此Shell脚本的行为:

cat frames/*.png | ffmpeg -f image2pipe -i - output.mp4

这是我的尝试,但没有成功。它显示:pipe:: End of file

const { spawn } = require("child_process");
let cat = spawn("cat", ["frames/*.png"]);
let ffmpeg = spawn("ffmpeg", ["-f", "image2pipe", "-i", "-", "output.mp4"], {stdio: ["pipe", 1, 2]});
cat.stdout.pipe(ffmpeg.stdin);

我想念什么?

1 个答案:

答案 0 :(得分:0)

这与node 8.9.4一起使用,与您的并没有太大区别,因此请检查节点版本,并最终检查您的进程的stderr,因为这可能是配置中的一些隐藏错误。

请注意,stdio的默认值为['pipe', 'pipe', 'pipe'],所以可以保留它。

const { spawn } = require("child_process");

const cat = spawn("cat", ["frames/*.png"]);
const ffmpeg = spawn("ffmpeg", ["-f", "image2pipe", "-i", "-", "output.mp4"]);

// from first process to the second
cat.stdout.pipe(ffmpeg.stdin);

// from the second process to the node run
ffmpeg.stdout.pipe(process.stdout)

// NOTE: if it doesn't works you can debug like this:
cat.stderr.pipe(process.stdout)
ffmpeg.stderr.pipe(process.stdout)

将输出:

ffmpeg version N-93005-gd92f06eb66 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181201
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfi    
...
[libx264 @ 0000020fcc3001c0] mb I  I16..4: 76.2%  0.0% 23.8%
[libx264 @ 0000020fcc3001c0] mb P  I16..4: 52.1%  0.0% 14.7%  P16..4:  2.8%  0.8
%  0.4%  0.0%  0.0%    skip:29.3%
[libx264 @ 0000020fcc3001c0] mb B  I16..4: 20.9%  0.0% 10.2%  B16..8: 11.6%  1.7
%  0.3%  direct: 0.5%  skip:54.7%  L0:40.5% L1:58.5% BI: 1.0%
[libx264 @ 0000020fcc3001c0] coded y,u,v intra: 15.7% 10.3% 10.2% inter: 2.4% 1.
0% 0.9%
[libx264 @ 0000020fcc3001c0] i16 v,h,dc,p: 76% 23%  1%  0%
[libx264 @ 0000020fcc3001c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 26% 17%  3%  4%
 4%  4%  4%  4%
[libx264 @ 0000020fcc3001c0] Weighted P-Frames: Y:21.6% UV:13.6%
[libx264 @ 0000020fcc3001c0] ref P L0: 56.2%  7.5% 14.9% 20.3%  1.2%
[libx264 @ 0000020fcc3001c0] ref B L0: 63.3% 35.1%  1.6%
[libx264 @ 0000020fcc3001c0] kb/s:8767.87