Created
February 17, 2020 17:28
-
-
Save elie222/bf99c425858ccf0d524c3533560c481b to your computer and use it in GitHub Desktop.
@ffmpeg/ffmpeg compress video example in browser
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
<!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/[email protected]/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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run this as follows:
npm i -g http-server http-server .