ff-format
Safe, FFmpeg-agnostic type definitions for video and audio processing.
Overview
ff-format provides shared type definitions used across the ff-* crate family. All APIs are safe — no unsafe code is required. FFmpeg internals are completely hidden behind idiomatic Rust types.
Features
- Type-safe pixel formats: YUV420p, RGBA, NV12, 10-bit HDR, and more
- Audio sample formats: F32, I16, planar/packed conversion
- Precise timestamps: Rational time bases with arithmetic operations
- Video/Audio frames: Safe abstractions for frame data
- Stream metadata: Video and audio stream information with builder pattern
- Media container info: Complete file metadata including multiple streams
- Color metadata: Color space, range, and primaries for HDR workflows
Minimum Supported Rust Version
Rust 1.93.0 or later (edition 2024).
Module Structure
ff-format/src/
├── lib.rs # Crate root, prelude
├── pixel.rs # PixelFormat
├── sample.rs # SampleFormat
├── time.rs # Timestamp, Rational
├── frame/ # Frame types
│ ├── mod.rs
│ ├── video.rs # VideoFrame
│ └── audio.rs # AudioFrame
├── stream.rs # VideoStreamInfo, AudioStreamInfo
├── media.rs # MediaInfo
├── color.rs # ColorSpace, ColorRange, ColorPrimaries
├── codec.rs # VideoCodec, AudioCodec
├── channel.rs # ChannelLayout
└── error.rs # FormatError, FrameError
Usage
Basic Types
use *;
// Pixel formats
let format = Yuv420p;
assert!;
assert_eq!;
// Sample formats
let audio_fmt = F32;
assert!;
assert_eq!;
// Timestamps with time base
let time_base = new;
let ts = new;
assert!;
Stream Information
use ;
use ;
use ;
// Video stream with builder pattern
let video = builder
.index
.codec
.width
.height
.frame_rate
.pixel_format
.build;
assert_eq!;
assert!;
// Audio stream
let audio = builder
.index
.codec
.sample_rate
.channels
.sample_format
.build;
assert!;
Media Container Info
use MediaInfo;
use Duration;
let media = builder
.path
.format
.duration
.file_size
.video_stream
.audio_stream
.metadata
.build;
assert!;
assert!;
assert_eq!;
License
MIT OR Apache-2.0