ff-stream
Produce HLS and DASH adaptive bitrate output from any video source. Define a rendition ladder, point it at an input file, and receive a package ready for CDN delivery.
ff-stream is a safe, ergonomic wrapper over FFmpeg's adaptive-streaming muxers (the HLS and DASH segmenters in libavformat), driving the encode-and-mux loop from a rendition ladder. Errors are typed and chain their source (StreamError), so a failure reads as an actionable message rather than a raw FFmpeg return code.
It is an independent crate: use it on its own, or combine it with the other ff-* crates to assemble whatever media application, or editing model, you need. The ff-* crates are purified, model-free primitives, so none imposes an editing model on you; avio is one editing engine built on top of them. Each crate is versioned independently; see crates.io for current versions.
Installation
[]
= "0.16"
HLS Output
HlsOutput is a consuming builder. Setters take self and return Self; validation is
deferred to build(), and write() performs the encode-and-mux.
use HlsOutput;
use Duration;
new
.input
.segment_duration
.keyframe_interval
.build?
.write?;
// Writes hls_output/playlist.m3u8 and numbered segments (segment000.ts, …).
DASH Output
use DashOutput;
use Duration;
new
.input
.segment_duration
.build?
.write?;
// Writes dash_output/manifest.mpd and the corresponding segments.
Rendition Ladder
AbrLadder produces multi-rendition HLS or DASH output from a single input. Each Rendition
specifies the output resolution and target bitrate. The ladder owns its own terminal methods:
hls(output_dir) and dash(output_dir).
use ;
new
.add_rendition
.add_rendition
.add_rendition
.hls?;
// Writes hls_output/master.m3u8 plus a numbered sub-directory per rendition.
| Field | Type | Description |
|---|---|---|
width |
u32 |
Output frame width in pixels |
height |
u32 |
Output frame height in pixels |
bitrate |
u64 |
Target video bitrate in bits per second |
Error Handling
| Variant | When it occurs |
|---|---|
StreamError::InvalidConfig |
Missing input, empty ladder, or conflicting options |
StreamError::Encode |
Wrapped EncodeError from a rendition encode stage |
StreamError::Io |
Write failure on the output directory |
MSRV
Rust 1.93.0 (edition 2024).
License
MIT OR Apache-2.0