Skip to content

Instantly share code, notes, and snippets.

@jeromewu
Last active May 1, 2020 10:16
Show Gist options
  • Select an option

  • Save jeromewu/7be506f80a8f9b88ce79ff3b748355b9 to your computer and use it in GitHub Desktop.

Select an option

Save jeromewu/7be506f80a8f9b88ce79ff3b748355b9 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const { getModule } = require('./util/module');
const strList2ptr = require('./util/strList2ptr');
module.exports = (inputPath, outputExt) => {
const Module = getModule();
const data = new Uint8Array(fs.readFileSync(inputPath));
const ffmpeg = Module.cwrap('ffmpeg', 'number', ['number', 'number']);
const args = ['./ffmpeg', '-i', 'input.avi', `output.${outputExt}`];
Module.FS.writeFile('input.avi', data);
ffmpeg(args.length, strList2ptr(args));
return Buffer.from(Module.FS.readFile(`output.${outputExt}`));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment