Skip to content

Instantly share code, notes, and snippets.

@ThunderWiring
Created September 14, 2018 21:54
Show Gist options
  • Save ThunderWiring/87c9a81f4ebd57f9e2f8ac3ee7e95dd9 to your computer and use it in GitHub Desktop.
Save ThunderWiring/87c9a81f4ebd57f9e2f8ac3ee7e95dd9 to your computer and use it in GitHub Desktop.
extract audio in MP3 format from an MP4 file.
/**
* @private
*/
extractAudioFromMP4_(paths) {
return new Promise((resolve, reject) => {
/*
for some reason, this did not work:
const binaries = require('ffmpeg-binaries');
const ffmpegPath = binaries.ffmpegPath(); <-- throws an exception
so i had to assign the path explicitly..
*/
const ffmpegPath = 'C:\\Projects\\mp3converterNodeJs\\node_modules\\ffmpeg-binaries\\bin\\ffmpeg.exe';
ffmpeg(paths.filePath)
.setFfmpegPath(ffmpegPath)
.format('mp3')
.audioBitrate(160)
.on('progress', (progress) => {
})
.output(
fs.createWriteStream(
path.join(paths.folderPath, sanitize(paths.fileTitle))))
.on('end', () => {
resolve();
})
.run();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment