Add new action

This commit is contained in:
HaveAGitGat 2019-12-03 21:12:39 +00:00
parent 372f374079
commit d60e0c17ad
4 changed files with 85 additions and 21 deletions

View file

@ -0,0 +1,76 @@
module.exports = function transcodeStandardiseAudioCodecs(file, audioEncoder) {
try {
var audioIdx = -1
var hasNonSpecifiedAudioCodecStream = false
var ffmpegCommandInsert = ''
//Function required responses
// preset
// processFile
// note
var audioCodec = audioEncoder
if (audioEncoder == 'dca') {
audioCodec = 'dts'
}
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio") {
audioIdx++
}
} catch (err) { }
try {
if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio" && file.ffProbeData.streams[i].codec_name != audioCodec) {
ffmpegCommandInsert += ` -c:a:${audioIdx} ${audioEncoder}`
hasNonSpecifiedAudioCodecStream = true
}
} catch (err) { }
}
if (hasNonSpecifiedAudioCodecStream === true) {
return {
preset: `,-map 0:v -map 0:a -map 0:s? -map 0:d? -c copy ${ffmpegCommandInsert}`,
processFile: true,
note: `File has audio streams which aren't in ${audioCodec} \n`
}
}
return {
preset: '',
processFile: false,
note: `File does not have any audio streams which aren't in ${audioCodec} \n`
}
} catch (err) {
return {
preset: '',
processFile: false,
note: `library.actions.transcodeStandardiseAudioCodecs error: ${err} \n`
}
}
}