Last active
November 18, 2019 08:09
-
-
Save chulini/484aaf19312b1aa1bc1a891ace3bd57d to your computer and use it in GitHub Desktop.
mp4 to webm video converter using ffmpeg
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
// 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