Skip to content

Instantly share code, notes, and snippets.

@lcssanches
Created January 24, 2024 10:42
Show Gist options
  • Save lcssanches/ac151f9a78e4066a97eb2ae9e16b994e to your computer and use it in GitHub Desktop.
Save lcssanches/ac151f9a78e4066a97eb2ae9e16b994e to your computer and use it in GitHub Desktop.
export async function convertAudioToOgg(input: stream.Readable, output: string) {
return new Promise<void>((res, rej) => {
ffmpeg()
.input(input)
.audioChannels(1)
.audioCodec('opus')
.toFormat('ogg')
.addOutputOptions('-avoid_negative_ts make_zero')
.output(output)
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done');
})
.on('error', function (err) {
console.log('An error occurred: ' + err.message);
})
.on('end', (err, stdout, stderr) => {
console.log(err, stdout, stderr);
if (err) {
rej();
}
res();
})
.run();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment