Created
September 10, 2019 16:18
-
-
Save grough/d5e559c6e54d8aad7555c0cff9df20eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const { exec } = require("child_process"); | |
const outputDir = process.env.OUTPUT_DIR; | |
const inputPath = process.argv[2]; | |
const startTime = process.argv[3]; | |
const endTime = process.argv[4]; | |
const basename = path.basename(inputPath); | |
const [filename, extension] = basename.split("."); | |
const now = new Date(); | |
const month = now.getMonth(); | |
const day = now.getDate(); | |
const year = now.getFullYear(); | |
const date = `${year}${month < 10 ? "0" + month : month}${ | |
day < 10 ? "0" + day : day | |
}`; | |
const name = `${date}-${filename}`.replace(/[\s_]/g, "-").toLowerCase(); | |
const newFile = `${outputDir}/${name}`; | |
const normalizedFile = `${outputDir}/${name}-n`; | |
const seekStart = startTime ? `-ss ${startTime}` : ""; | |
const seekEnd = endTime ? `-to ${endTime}` : ""; | |
const properties = "-ar 44100 -acodec pcm_s16le"; | |
const trim = `ffmpeg -i "${inputPath}" ${seekStart} ${seekEnd} ${properties} -y "${newFile}.${extension}"`; | |
const norm = `ffmpeg -i "${newFile}.${extension}" ${properties} -filter:a loudnorm "${normalizedFile}.${extension}"`; | |
const comp = `ffmpeg -i "${normalizedFile}.${extension}" -vn -f mp3 -ab 256k -ac 2 -ar 44100 "${normalizedFile}.mp3"`; | |
exec([trim, norm, comp].join(" && "), (err, stdout, stderr) => { | |
if (err) { | |
console.error(err); | |
} else { | |
console.log(`stdout: ${stdout}`); | |
console.log(`stderr: ${stderr}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment