从节点

时间:2019-06-08 20:02:39

标签: node.js ffmpeg

我正在尝试使用ffmpeg录制大量音频供稿。节点使用流URL(HLS M3U8播放列表)下载配置文件,对其进行解析并启动适当数量的ffmpeg实例。当我关闭它们时,什么也没有发生,我不得不使用任务管理器将其杀死,从而导致文件损坏。当我调试并在启动程序的一两分钟内按Ctrl-c时,它可以正常工作。当我需要记录5-10分钟以上时,我遇到了问题。

我从2013年发现了this related question,并对其进行了调整以适合我的多流情况。

记录器进程从以下代码开始(在http请求回调内部):

config.audio_config.forEach((channel,i)=>{
self.liveChannels++;

console.log(`   ${channel.number}`);
self.Channels[i] = spawn('ffmpeg', ['-i', `${channel.base_url + channel.stream_ios}`,  '-c:v', 'none', '-c:a', 'copy', `Output\\${config.folder}\\${channel.number}.m4a`]);
self.Channels[i].stdin.setEncoding('utf8');
self.Channels[i].chNum = channel.number;

self.Channels[i].on('exit',(code,sig)=>{
console.log(`   Channel ${channel.number} recorder closed.`);
self.liveChannels--;
if(self.liveChannels === 0){
    process.exit();
}
});
});
console.log('Press Ctl-C to start Shutdown');

我的关闭功能(由SIGINT触发到主进程)是:

function shutdown() {
    self.Channels.forEach((chan)=>{
        chan.stdin.write('q');
        chan.stdin.end(); //I have tried both with and without this line and chan.stdin.end('q')
    });

}

更新: 切换到AAC容器文件(只需更改输出的扩展名)就无需使用优美的FFMPEG出口。我仍然想知道为什么在开始的大约10分钟内向标准输入发送“ q”只会杀死FFMPEG过程。

0 个答案:

没有答案