Media Preparation
Prepare media for streaming
@shelby-protocol/media-prepare transcodes video into adaptive streaming formats like HLS and DASH. It handles multi-quality encoding, segment generation, and manifest creationβeverything needed to prepare video for delivery from Shelby's decentralized storage.
Installation
npm install @shelby-protocol/media-prepareRequires FFmpeg 7.0+ with libx264 support. Install via brew install ffmpeg (macOS) or your system package manager.
Quick Example
Create a transcoding plan and execute it:
import {
CmafPlanBuilder,
videoLadderPresets,
} from "@shelby-protocol/media-prepare/core";
import { NodeCmafPlanExecutor } from "@shelby-protocol/media-prepare/node";
// Define the transcoding plan
const plan = new CmafPlanBuilder()
.withInput("input.mp4")
.withOutputDir("output")
.withVideoLadder(videoLadderPresets.vodHd_1080p)
.withVideoCodec({ kind: "x264", preset: "medium" })
.addAudioTrack({
language: "eng",
bitrateBps: 128_000,
default: true,
})
.withSegmentDuration(4)
.withHlsOutput()
.build();
// Execute the plan
const executor = new NodeCmafPlanExecutor();
await executor.execute(plan);This produces HLS playlists and CMAF segments ready for upload:
output/
βββ master.m3u8 # Master playlist (entry point)
βββ 1080p/
β βββ playlist.m3u8 # Variant playlist
β βββ segment-*.m4s # Video segments
βββ 720p/
β βββ ...
βββ audio-eng/
βββ ...Built-in Presets
The vodHd_1080p preset creates a 3-rung adaptive bitrate ladder:
| Rung | Resolution | Bitrate |
|---|---|---|
| 1080p | 1920Γ1080 | 5 Mbps |
| 720p | 1280Γ720 | 3 Mbps |
| 480p | 854Γ480 | 1.2 Mbps |
Key Features
Declarative API
Fluent builder pattern for defining transcoding plans
Platform Agnostic
Works with native FFmpeg (Node.js) or FFmpeg.wasm (browser)
Adaptive Bitrate
Built-in support for multi-rung video ladders
CMAF + HLS
Generates fragmented MP4 segments with HLS playlists