Skip to content

Instantly share code, notes, and snippets.

@elie222
Created February 17, 2020 17:28
Show Gist options
  • Save elie222/bf99c425858ccf0d524c3533560c481b to your computer and use it in GitHub Desktop.
Save elie222/bf99c425858ccf0d524c3533560c481b to your computer and use it in GitHub Desktop.
@ffmpeg/ffmpeg compress video example in browser
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FFMPEGJS Core Page</title>
<script src="https://unpkg.com/@ffmpeg/ffmpeg@0.6.1/dist/ffmpeg.min.js"></script>
<script>
const { createWorker } = FFmpeg;
(async () => {
const worker = createWorker({
logger: m => console.log(m)
});
await worker.load();
console.log('loaded')
await worker.write('sample.mp4', 'http://127.0.0.1:8080/video/sample.mp4');
console.log('write complete')
await worker.run("-i sample.mp4 -c:v libx264 -preset slow -crf 25 -vf scale=720:-2 -x264-params keyint=25:keyint_min=25 -an -f mp4 output.mp4");
console.log('finished')
const { data } = await worker.read('output.mp4');
console.log(data)
})();
</script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
@elie222
Copy link
Author

elie222 commented Feb 17, 2020

You can run this as follows:

npm i -g http-server
http-server .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment