Skip to content
/ mfx Public

In-browser video editing using WebCodec and WebGL → mfxlib.com

License

Notifications You must be signed in to change notification settings

schahriar/mfx

Repository files navigation

MFX

In-browser video editing using WebCodecs, WebStreams, and WebGL → mfxlib.com


Usage

Decode MP4 Video -> zoom out -> encode to WebM keeping original Audio (vp8):

import {
  decode,
  encode,
  effect,
  visual,
  writeToFile,
} from "mfx";

// Files can be fetched locally
const file = await fetch("https://example.com/myvideo.mp4");

// Decode video container, returns each track as a WebStream
const { video, audio } = await decode(file, "video/mp4", {
  // Addresses Chromium WebCodecs bug, Set to true for HEVC or if "Can't readback frame textures" is thrown. Has ~10% performance impact.
  forceDecodeToSoftware: false,
});

// Hardware accelerated (WebGL2) effect pipeline
const videoOutput = effect(video, [
  // Apply zoom out effect
  visual.zoom({ factor: 0.5, x: 0.5, y: 0.25 })
]);

// Readable WebStream
const outputStream = encode({
  mimeType: `video/webm; codecs="vp8,opus"`, // Transcode to WebM VP8 (video) and Opus (audio)
  video: {
    ...video.track.config, // Inherit configuration from input video
    stream: videoOutput,
    width: 640,
    height: 360,
    bitrate: 1e6,
    framerate: 30,
  },
  audio: {
    ...audio.track.config, // Inherit configuration from input audio
    stream: audio
  }
});

// Opens a save dialog in the browser
await writeToFile(outputStream, "output.webm");

// Alternatively you can pipeTo a fetch POST request
await fetch("example.com/save", {
  method: "POST",
  body: outputStream
});

Support Table

While codec support heavily depends on the browser, mfx aims to provide support for the following container / codec pairs:

Container Codec Encode / Decode
MP4 H.264/AVC Both
MP4 H.265/HEVC Decode
MP4 VP8 Both
MP4 VP9 Both
WebM VP8 Both
WebM VP9 Both
GIF LZW Encode

Audio
MP4 Opus Both
MP4 AAC Both
WebM Opus Both
WebM Vorbis Both

Roadmap

Soon

  • Fix Audio trimming to include subframes
  • Regional effects
  • GIF decoder
  • Optimization Pipeline
    • Frame delta GPU pipeline
      • To remove duplicated or near-identical frames based on controllable parameters
      • Auto-quantization based on frame hints
    • RGB -> YUV conversion for better compatibility and output size
    • Multi-pass adaptive bitrate
    • Frame rate pinning to auto-adjust timestamps
      • Optionally disable VFR
    • Temporal Noise Reduction
  • API Documentation
    • Add note on VP9 probe
  • Testing: Source videos with frame duration > fps to showcase frameRate
  • Run tests on Github actions
  • Contribution Guide

Later


Contributing

Install git-lfs to pull sample files:

brew install git-lfs
npm install
npm start

License

MIT License

Disclaimer on Sample Videos

Some test videos are sourced from coverr.co yet they are only used for testing and will not be built into the MFX package. These videos are under a permissive license (https://coverr.co/license).

About

In-browser video editing using WebCodec and WebGL → mfxlib.com

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published