Video rendering and processing library
npm install wrapboxA focused library for video rendering and processing, specializing in recodemuxing and MP4 box handling using WebCodecs.
- 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.
``bash`
npm install wrapbox
The recodemux function is the core utility for handling audio and video streams simultaneously, synchronizing them into a valid MP4 file.
`typescript
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;
`
wrapbox provides direct access to mp4box.js primitives:
`typescript
import { createFile } from 'wrapbox';
const mp4file = createFile();
mp4file.onReady = (info) => {
console.log('MP4 is ready', info);
};
`
- 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.
- 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.
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.
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.