Skip to content

Instantly share code, notes, and snippets.

@chulini
Last active November 18, 2019 08:09
Show Gist options
  • Save chulini/484aaf19312b1aa1bc1a891ace3bd57d to your computer and use it in GitHub Desktop.
Save chulini/484aaf19312b1aa1bc1a891ace3bd57d to your computer and use it in GitHub Desktop.
mp4 to webm video converter using ffmpeg
// How to use:
// 1.- Install node and ffmpeg
// 2.- node convert.js yourfilename.mp4
// (Will generate yourfilename.webm. Process is slow but works. Just be patient.)
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const args = process.argv.slice(2);
let filename = args[0].split(".")[0];
console.log(`Converting ${filename}.mp4 to ${filename}.webm`);
console.log(`yes | ffmpeg -i ${filename}.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -an -f webm /dev/null && ffmpeg -i ${filename}.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 -c:a libopus ${filename}.webm`)
async function convert() {
try{
const { stdout, stderr } = await exec(`yes | ffmpeg -i ${filename}.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -an -f webm /dev/null && ffmpeg -i ${filename}.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 -c:a libopus ${filename}.webm`);
console.log('stdout:', stdout);
console.log('stderr:', stderr);
}catch (e){
console.log('stdout:', e.stdout);
console.log('stderr:', e.stderr);
}
}
convert();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment