JSPM

wrapbox

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1259
  • Score
    100M100P100Q107096F
  • License SEE LICENSE IN LICENSE

Video rendering and processing library

Package Exports

  • wrapbox

Readme

wrapbox

A focused library for video rendering and processing, specializing in recodemuxing and MP4 box handling using WebCodecs.

Features

  • Recodemuxing: High-performance video and audio encoding/decoding.
  • MP4 Box Handling: Deep integration with mp4box.js for structured MP4 creation.
  • WebCodecs Integration: Optimized for modern browser-based video processing.
  • Metadata Support: Easy addition of metadata tags to MOOV boxes.

Installation

npm install wrapbox

Quick Start: recodemux

The recodemux function is the core utility for handling audio and video streams simultaneously, synchronizing them into a valid MP4 file.

import { recodemux } from 'wrapbox';

const muxer = recodemux({
  video: {
    width: 1920,
    height: 1080,
    expectFPS: 30,
    codec: 'avc1.42E01E',
    bitrate: 5_000_000,
  },
  audio: {
    codec: 'aac',
    sampleRate: 44100,
    channelCount: 2,
  },
  duration: 10000, // Duration in ms
});

// To encode video (VideoFrame from WebCodecs)
muxer.encodeVideo(videoFrame, { keyFrame: true });

// To encode audio (AudioData from WebCodecs)
muxer.encodeAudio(audioData);

// Finalize the file
await muxer.flush();
muxer.close();

// Access the underlying mp4box file
const mp4 = muxer.mp4file;

Advanced MP4 Box Access

wrapbox provides direct access to mp4box.js primitives:

import { createFile } from 'wrapbox';

const mp4file = createFile();
mp4file.onReady = (info) => {
  console.log('MP4 is ready', info);
};

API Reference

recodemux(opts: RecodeMuxOpts)

  • video: Configuration for the video track (width, height, FPS, codec, bitrate).
  • audio: Configuration for the audio track (codec, sampleRate, channelCount).
  • duration: (Optional) Total duration of the media.
  • metaDataTags: (Optional) Key-value pairs to add as metadata.

Returns

  • encodeVideo(frame, options): Encodes a VideoFrame.
  • encodeAudio(data): Encodes AudioData.
  • flush(): Returns a promise that resolves when all data is processed.
  • close(): Cleans up resources.
  • mp4file: The underlying MP4File instance.

License

WrapBox is licensed under a two-tier system:

  • Free License: For individuals, small teams (up to 3 employees), and non-profits.
  • Company License: For organizations with more than 3 employees.

For detailed terms, see LICENSE.

Telemetry

To improve the library and monitor usage for licensing compliance, WrapBox includes anonymous telemetry. It sends a simple ping when the library is initialized and when video creation starts. No personal data or video content is ever transmitted.