5

FFMPEG.WASM

 2 years ago
source link: https://ffmpegwasm.netlify.app/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

FFMPEG.WASM

ffmpeg.wasm is a pure WebAssembly / JavaScript port of FFmpeg. It enables video & audio record, convert and stream right inside browsers.

External Libraries

ffmpeg.wasm is built with common external libraries, and more of libraries to be added! (You can request them HERE)

H.264 codec

H.265 codec

libvpx

VP8/VP9 codec

theora

OGV codec

wavpack

WAV/WV codec

MP3 codec

fdk-aac

AAC codec

vorbis

OGG codec

OPUS codec

freetype2

Font file renderer

libass

subtitle renderer

libwebp

WEBP codec

Installation

Install ffmpeg.wasm:
# Use npm
$ npm install @ffmpeg/ffmpeg @ffmpeg/core
# Use yarn
$ yarn add @ffmpeg/ffmpeg @ffmpeg/core

Usage

With few lines of code you can use ffmpeg.wasmBrowser
<body>
<video id="player" controls></video>
<input type="file" id="uploader">
<script src="ffmpeg.min.js"></script>
<script>
const { createFFmpeg, fetchFile } = FFmpeg;
const ffmpeg = createFFmpeg({ log: true });
const transcode = async ({ target: { files } }) => {
const { name } = files[0];
await ffmpeg.load();
ffmpeg.FS('writeFile', name, await fetchFile(files[0]));
await ffmpeg.run('-i', name, 'output.mp4');
const data = ffmpeg.FS('readFile', 'output.mp4');
const video = document.getElementById('player');
video.src = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' }));
document
.getElementById('uploader').addEventListener('change', transcode);
</script>
</body>
Node.JS
const fs = require('fs');
const { createFFmpeg, fetchFile } = require('@ffmpeg/ffmpeg');
const ffmpeg = createFFmpeg({ log: true });
(async () => {
await ffmpeg.load();
ffmpeg.FS('writeFile', 'test.avi', await fetchFile('./test.avi'));
await ffmpeg.run('-i', 'test.avi', 'test.mp4');
await fs.promises.writeFile('./test.mp4', ffmpeg.FS('readFile', 'test.mp4'));
process.exit(0);
})();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK