🚧 The Shelby Explorer is currently in beta and is under active development

Shelby SymbolMedia Kit

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-prepare

Requires 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:

transcode.ts
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:

RungResolutionBitrate
1080p1920Γ—10805 Mbps
720p1280Γ—7203 Mbps
480p854Γ—4801.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

Documentation


On this page