我正在使用 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 将为空。有任何解决这个问题的方法吗?
最佳答案
差不多两周后,我找到了答案。当我查看文档时,它说:
If the child was not spawned with stdio[1] set to 'pipe', then this will not be set.
我意识到我所要做的就是改变中间
inherit
至pipe
: stdio: [
/* Standard: stdin, stdout, stderr */
'inherit', 'pipe', 'inherit',
/* Custom: pipe:3, pipe:4, pipe:5 */
'pipe', 'pipe', 'pipe',
],
不管怎么说,多谢拉。
关于node.js - 在同一个子进程中同时使用 stdio 和 stout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65779026/