缓冲在node.js / express中通过管道传输的流

时间:2015-05-12 16:49:41

标签: node.js ffmpeg streaming

我有一个命令,我正在通过ffmpeg运行视频流,它基本上将响应传递给快递中的res

例如:

var args = ['-re','-i','/video.mkv','-loglevel','quiet','-r',24,'-threads',7,'-b:v','512k','-b:a','96k','-c:v','libx264','-c:a','libfdk_aac','-ar',22050,'-f','flv','pipe:1']
  , command = spawn('ffmpeg', args);

command.stdout.pipe(res);

我想做的是"缓冲"在将输出通过管道传输到res之前的几秒钟。我尝试创建new stream.Writeable(),其中包含stdout,然后使用setTimeout 3秒,但这似乎无法正常工作。

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

只要你是节点>=0.10,你就可以做到

var args = ['-re','-i','/video.mkv','-loglevel','quiet','-r',24,'-threads',7,'-b:v','512k','-b:a','96k','-c:v','libx264','-c:a','libfdk_aac','-ar',22050,'-f','flv','pipe:1']
    , command = spawn('ffmpeg', args);

setTimeout(function(){
    command.stdout.pipe(res);
}, 3000);
默认情况下,

Streams缓冲区,因此您只需等待管道直到稍后。