media-pp
media-pp is a small, GStreamer-flavored media pipeline library for Rust,
built on ffmpeg-next. It provides synchronous pipeline stages by default
and explicit thread boundaries through bounded queues.
The library crate lives in lib/. Each directory below examples/ is an
independent example crate, so platform-specific dependencies do not leak into
the core library.
Quick start
FFmpeg development libraries must be installed and discoverable by
ffmpeg-sys-next.
Add the crate to your project:
[]
= "0.1"
This minimal pipeline generates video for one second and counts the frames:
use ;
use ;
To work with this repository directly:
File-based examples require a media path. No media files are checked into the repository and examples do not use a default path.
How pipelines work
A pipeline connects a source to filters and a terminal sink:
FileDemuxer → SwDecoder → Queue → Pacer → FrameCounter
The core types are deliberately small:
MediaBuffercarries packets, video, audio, and EOS.Sink::consumeis a synchronous call and may return an error.SrcPadconnects one source output to one downstream sink.Queueintroduces a bounded worker-thread boundary. Downstream errors are reported through the pipelineBus, and the worker continues.Pipelineowns source threads, control flow, the shared clock, bus, and topology graph.Teeprovides fan-out;AudioMixerand the video compositors provide fan-in.
Buffers use shared ownership, so fan-out clones references rather than media payloads. PTS, duration, packet time bases, video color information, and EOS are preserved through stages that do not intentionally create a new timeline.
Element inventory
| Kind | Elements |
|---|---|
| Sources | FileDemuxer, AppSource, RtspSource, TestVideoSource, TestAudioSource, DxgiCaptureSource, WasapiCaptureSource, AudioMixer, VideoCompositor, D3d11VideoCompositor, WebRtcTrackSource |
| Filters | SwDecoder, D3d11Decoder, D3d12vaDecoder, SwEncoder, SwAudioEncoder, AudioResampler, AudioVolume, Scaler, Pacer, VideoSynchronizer, D3d11Upload, D3d11Download, D3d12Upload, Tee |
| Sinks | FrameCounter, PacketCounter, AppSink, Mp4Muxer, SegmentedMp4Muxer, HlsMuxer, RtspSink, D3d11Renderer, D3d12Renderer, WasapiRenderer, OrtDetector, WebRtcTrackSink |
Backend-specific elements are available only on Windows and require their
corresponding Cargo feature. See each type's Rust documentation for buffer
requirements, ownership, error behavior, and runtime-control semantics.
WebRtcPeer is the WebRTC driver and creates the WebRtcHandle used to add
tracks and obtain each WebRtcTrackSink/WebRtcTrackSource pair.
Examples
The examples are grouped by purpose:
examples/core: decoding, queues, fan-out, dynamic tees, app sources/sinks, audio, muxing, HLS, and CPU compositing.examples/render: D3D11/D3D12 playback, upload, capture, synchronization, GPU compositing, and recording.examples/rtsp: publishing, seeking, and receiving RTSP streams.examples/vision: scaling and ONNX object detection.examples/webrtc: data and encoded A/V loopback pipelines.
Useful starting points:
Windows rendering and capture examples enable their required library features
in their own Cargo.toml files. Run an example without arguments to see its
usage line.
Feature flags
The library has no default features.
| Feature | Adds | Platform |
|---|---|---|
d3d11-renderer |
D3D11 decode, upload/download, rendering, and GPU compositing | Windows |
d3d12-renderer |
D3D12VA decode, upload, and rendering interfaces | Windows |
dxgi-capture |
Desktop capture; also enables d3d11-renderer |
Windows |
wasapi-capture |
System-audio and microphone capture | Windows |
wasapi-renderer |
Shared-mode audio playback | Windows |
ort |
ONNX Runtime object detection | All supported targets |
webrtc |
str0m-based WebRTC peer and track elements |
All supported targets |
For example, build all Windows API documentation locally. Nightly rustdoc is what labels each item with the feature that enables it:
$env:RUSTDOCFLAGS = "--cfg docsrs"
cargo +nightly doc -p media-pp --open --features d3d11-renderer,d3d12-renderer,dxgi-capture,wasapi-capture,wasapi-renderer,webrtc
docs.rs builds this crate for Linux, so it documents only the backend-independent API and omits Windows-only types. The complete API, including D3D11, D3D12, DXGI, and WASAPI, is available in the Windows API documentation published on GitHub Pages.
Logging
Library diagnostics use a private, opt-in logger and never install a global
log logger or tracing subscriber:
let _log_guard = init?;
Keep the returned guard alive until logging is no longer needed. Pipeline
starts and dynamic Tee changes include a stable-ID topology diagram; detailed
EOS and control propagation is available at Trace level. Ordinary media
buffers are not logged one record per buffer.
Requirements and platform notes
- Install FFmpeg development headers and libraries in a location discoverable
by
ffmpeg-sys-next. - Rust 1.88 or newer is required.
- D3D11VA/D3D12VA require compatible FFmpeg builds, Windows drivers, and GPU
hardware. Check available accelerators with
ffmpeg -hwaccels. - D3D11 elements in one pipeline must share the same
ID3D11Deviceand immediate context. D3d11Decoderuses a fixed-size FFmpeg surface pool;extra_hw_framesmust cover the deepest downstream buffering.- RTSP publishing requires an external server that accepts publishing, such as MediaMTX.
- Tests needing real media read
MEDIA_PP_TEST_VIDEO. They skip when it is unset or unreadable, so set it when testing demuxing, seeking, or decoding. - Windows-backed examples compile as unsupported stubs on other targets.
License
Licensed under either the Apache License, Version 2.0 or the MIT License, at your option.
media-pp does not bundle FFmpeg. Users are responsible for complying with
the license of their FFmpeg build and optional codecs.