Skip to content

Instantly share code, notes, and snippets.

@chulini
Last active Nov 18, 2019
Embed
What would you like to do?
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