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 @@ ...@@ -51,7 +51,7 @@
"offline": { "offline": {
"folder": { "folder": {
"audioRaw": "audio_raw", "audioRaw": "audio_raw",
"audio": "audio_wav", "audioWav": "audio_wav",
"audioMerged" : "audio_merged" "audioMerged" : "audio_merged"
}, },
"audio":{ "audio":{
......
...@@ -23,7 +23,6 @@ const uuidv1 = require('uuid/v1'); ...@@ -23,7 +23,6 @@ const uuidv1 = require('uuid/v1');
const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg'); const ffmpegInstaller = require('@ffmpeg-installer/ffmpeg');
const ffprobeInstaller = require('@ffprobe-installer/ffprobe'); const ffprobeInstaller = require('@ffprobe-installer/ffprobe');
const ffmpeg = require('fluent-ffmpeg'); const ffmpeg = require('fluent-ffmpeg');
ffmpeg.setFfmpegPath(ffmpegInstaller.path); ffmpeg.setFfmpegPath(ffmpegInstaller.path);
...@@ -34,14 +33,31 @@ module.exports = ffmpeg; ...@@ -34,14 +33,31 @@ module.exports = ffmpeg;
module.exports = config => { module.exports = config => {
let timestamp = undefined; 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 { return {
createFolder : () => { createFolder : () => {
if (!fs.existsSync(config.folder.audioRaw)) { if (!fs.existsSync(config.folder.audioRaw)) {
fs.mkdirSync(config.folder.audioRaw); fs.mkdirSync(config.folder.audioRaw);
} }
if (!fs.existsSync(config.folder.audio)) { if (!fs.existsSync(config.folder.audioWav)) {
fs.mkdirSync(config.folder.audio); fs.mkdirSync(config.folder.audioWav);
}
if (!fs.existsSync(config.folder.audioMerged)) {
fs.mkdirSync(config.folder.audioMerged);
} }
}, },
generateStream : () => { generateStream : () => {
...@@ -56,6 +72,7 @@ module.exports = config => { ...@@ -56,6 +72,7 @@ module.exports = config => {
"fileName": name, "fileName": name,
"timestamp" : new Date().getTime() "timestamp" : new Date().getTime()
} }
userConf++
return streamData return streamData
}, },
...@@ -64,14 +81,11 @@ module.exports = config => { ...@@ -64,14 +81,11 @@ module.exports = config => {
streamData.wstream.close(); streamData.wstream.close();
let delay = ((timestamp - streamData.timestamp) / toSecond) * -1; let delay = ((timestamp - streamData.timestamp) / toSecond) * -1;
try{ 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() ffmpeg()
.input('anullsrc=sample_rate='+config.audio.srate) .input('anullsrc=sample_rate='+config.audio.srate)
.inputFormat('lavfi') .inputFormat('lavfi')
.duration(delay) .duration(delay)
.output(config.folder.audio+"/silence_"+streamData.fileName+".wav") .output(config.folder.audioWav+"/silence_"+streamData.fileName+".wav")
.on('end', function() { .on('end', function() {
ffmpeg(streamData.pathFile) ffmpeg(streamData.pathFile)
...@@ -80,34 +94,26 @@ module.exports = config => { ...@@ -80,34 +94,26 @@ module.exports = config => {
.audioBitrate(config.audio.bitrate) .audioBitrate(config.audio.bitrate)
.audioChannels(config.audio.channels) .audioChannels(config.audio.channels)
.audioFrequency(config.audio.srate) .audioFrequency(config.audio.srate)
.save(config.folder.audio+"/"+streamData.fileName+".wav") .save(config.folder.audioWav+"/"+streamData.fileName+".wav")
.on('end', function() { .on('end', function() {
ffmpeg() ffmpeg()
.input(config.folder.audio+"/silence_"+streamData.fileName+".wav") .input(config.folder.audioWav+"/silence_"+streamData.fileName+".wav")
.input(config.folder.audio+"/"+streamData.fileName+".wav") .input(config.folder.audioWav+"/"+streamData.fileName+".wav")
.on('error', function(err) { .on('error', function(err) {
console.log('An error occurred: ' + err.message); console.log('An error occurred: ' + err.message);
}) })
.on('end', function() { .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) .mergeToFile(config.folder.audioMerged+"/"+streamData.fileName+".wav", config.folder.audio)
}) })
}) })
.run() .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){ } catch(err){
// Sometimes, the client will close the connection unexpectedly // Sometimes, the client will close the connection unexpectedly
// (e.g. when stopping). This is expected // (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