你好,我想链接一些fileReadStreams,我目前的用法是这样的
我正在尝试使用管道向ffmpeg发送一些mp3文件,以便它可以输出基于hls&mpeg-dash的无限流。
PS:我尝试了writableStream的finished
事件,但是如果完成则触发被writableStream关闭的child.stdin触发。如果我通过了不关闭标志,就永远不会完成事件。
答案 0 :(得分:0)
我使用了PassThrough流,结果并不完美,但就我而言还是可以的。如果有人需要这样的东西,这就是我的处理方式;
const {PassThrough} = require('stream');
const pt = new PassThrough();
/* spawn child process */
/* PS: I do not know why direct pipe to ffmpeg does not work in my case throws pipe: Permission denied */
const child = spawn(
'cat',
['|', 'ffmpeg', ...],
{
stdio: ['pipe', 'inherit', 'inherit'],
shell: true
});
pt.pipe(child.stdin);
/* pass streams to pt stream with end false parameter */
stream1.pipe(pt, { end: false }); /* This also prevents stream1 finished event, but otherwise it would close the pt stream. */
stream2.pipe(pt, { end: false }); /* Or you can handle this part programmatically(loops, generators etc) */