Commit b47a8221 authored by Yoann HOUPERT's avatar Yoann HOUPERT

add merge conf audio

parent ce8a1172
Pipeline #13579 canceled with stage
......@@ -51,7 +51,7 @@
"offline": {
"folder": {
"audioRaw": "audio_raw",
"audio": "audio_wav",
"audioWav": "audio_wav",
"audioMerged" : "audio_merged"
},
"audio":{
......
......@@ -23,7 +23,6 @@ const uuidv1 = require('uuid/v1');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffprobeInstaller = require('@ffprobe-installer/ffprobe');
const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
......@@ -34,14 +33,31 @@ module.exports = ffmpeg;
module.exports = config => {
let timestamp = undefined;
let userConf = 0;
function resumeGenerator(){
let nbFile = 0;
let cmd = ffmpeg()
fs.readdirSync(config.folder.audioMerged).forEach(file => {
cmd.input(file)
nbFile++;
})
cmd.complexFilter('amix=inputs='+nbFile+':duration=first:dropout_transition=3')
.save(config.folder.audioWav+"/merged.wav")
}
return {
createFolder : () => {
if (!fs.existsSync(config.folder.audioRaw)) {
fs.mkdirSync(config.folder.audioRaw);
}
if (!fs.existsSync(config.folder.audio)) {
fs.mkdirSync(config.folder.audio);
if (!fs.existsSync(config.folder.audioWav)) {
fs.mkdirSync(config.folder.audioWav);
}
if (!fs.existsSync(config.folder.audioMerged)) {
fs.mkdirSync(config.folder.audioMerged);
}
},
generateStream : () => {
......@@ -56,6 +72,7 @@ module.exports = config => {
"fileName": name,
"timestamp" : new Date().getTime()
}
userConf++
return streamData
},
......@@ -64,14 +81,11 @@ module.exports = config => {
streamData.wstream.close();
let delay = ((timestamp - streamData.timestamp) / toSecond) * -1;
try{
//var silence = ffmpeg().input('anullsrc=sample_rate=16000').inputFormat('lavfi').duration(delay).output(config.folder.audio+"/silence_"+streamData.fileName+".wav").run();
//var stream = ffmpeg(streamData.pathFile).toFormat(config.audio.format).noVideo().audioBitrate(config.audio.bitrate).audioChannels(config.audio.channels).audioFrequency(config.audio.srate).save(config.folder.audio+"/"+streamData.fileName+".wav")
ffmpeg()
.input('anullsrc=sample_rate='+config.audio.srate)
.inputFormat('lavfi')
.duration(delay)
.output(config.folder.audio+"/silence_"+streamData.fileName+".wav")
.output(config.folder.audioWav+"/silence_"+streamData.fileName+".wav")
.on('end', function() {
ffmpeg(streamData.pathFile)
......@@ -80,34 +94,26 @@ module.exports = config => {
.audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels)
.audioFrequency(config.audio.srate)
.save(config.folder.audio+"/"+streamData.fileName+".wav")
.save(config.folder.audioWav+"/"+streamData.fileName+".wav")
.on('end', function() {
ffmpeg()
.input(config.folder.audio+"/silence_"+streamData.fileName+".wav")
.input(config.folder.audio+"/"+streamData.fileName+".wav")
.input(config.folder.audioWav+"/silence_"+streamData.fileName+".wav")
.input(config.folder.audioWav+"/"+streamData.fileName+".wav")
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Merging finished !');
console.log('Merging finished !'+streamData.fileName);
if(--userConf === 0){
console.log('generate room audio')
resumeGenerator(config)
}
})
.mergeToFile(config.folder.audioMerged+"/"+streamData.fileName+".wav", config.folder.audio)
})
})
.run()
/*
ffmpeg(streamData.pathFile)
.toFormat(config.audio.format)
.noVideo()
.audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels)
.audioFrequency(config.audio.srate)
.save(config.folder.audio+"/"+streamData.fileName+".wav")*/
} catch(err){
// Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment