【发布时间】:2021-04-23 00:24:00
【问题描述】:
我正在使用 ffmpeg 组合音频/视频 2 流并通过管道将它们表达出来。这是我的代码:
var ffmpeg = cp.spawn('ffmpeg', [
// Set inputs
'-i', 'pipe:4',
'-i', 'pipe:5',
// Map audio & video from streams
'-map', '0:v',
'-map', '1:a',
// Keep encoding
'-c', 'copy',
'-movflags', 'frag_keyframe+empty_moov',
'-f', 'mp4',
// Define output file
'pipe:1',
], {
stdio: [
/* Standard: stdin, stdout, stderr */
'inherit', 'inherit', 'inherit',
/* Custom: pipe:3, pipe:4, pipe:5 */
'pipe', 'pipe', 'pipe',
],
});
video.pipe(ffmpeg.stdio[4]);
audio.pipe(ffmpeg.stdio[5]);
res.header('Content-Disposition', 'attachment; filename="video.mp4"');
ffmpeg.stdout.pipe(res);
但是代码给出了一个错误,指出ffmpeg.stout 为空。经过一番研究,我发现你不能拥有 stdio 选项数组,否则 stout 将为空。有什么办法解决这个问题?
【问题讨论】:
标签: node.js ffmpeg stream pipe child-process