crates/media-info/README.md
A Rust crate providing information structures for audio and video processing, designed to bridge FFmpeg and CPAL libraries for media capture and encoding applications.
This crate defines core data structures (AudioInfo and VideoInfo) that encapsulate media stream parameters and provide utilities for converting between different media processing libraries. It's particularly useful for applications that need to capture audio/video data and encode it using FFmpeg.
Represents audio stream parameters and provides conversion utilities between CPAL (Cross-Platform Audio Library) and FFmpeg formats.
Fields:
sample_format: FFmpeg sample formatsample_rate: Audio sample rate in Hzchannels: Number of audio channels (currently limited to 1-2)time_base: FFmpeg time base for timestampsbuffer_size: Audio buffer size in samplesKey Methods:
new(): Create with basic parameters and validationfrom_stream_config(): Create from CPAL's SupportedStreamConfigfrom_decoder(): Create from FFmpeg's audio decoderempty_frame(): Generate empty audio frameswrap_frame(): Wrap raw audio data into FFmpeg frames with automatic deinterleavingLimitations:
MAX_AUDIO_CHANNELS = 2Represents video stream parameters for various pixel formats and provides frame manipulation utilities.
Fields:
pixel_format: FFmpeg pixel formatwidth: Video width in pixelsheight: Video height in pixelstime_base: FFmpeg time base for timestampsframe_rate: Video frame rateKey Methods:
from_raw(): Create from RawVideoFormat enumfrom_raw_ffmpeg(): Create directly from FFmpeg pixel formatscaled(): Create scaled version with proportional resizingwrap_frame(): Wrap raw video data into FFmpeg frames with stride handlingEnum mapping common video formats to FFmpeg pixel formats:
Bgra → BGRAMjpeg → YUVJ422PUyvy → UYVY422RawRgb → RGB24Nv12 → NV12Gray → GRAY8YUYV420 → YUV420PRgba → RGBAProvides safe access to planar audio data, fixing issues with FFmpeg's audio frame data access for multi-channel audio processing.
AudioInfoError: Handles validation errors, particularly for unsupported channel configurationsffmpeg: Core FFmpeg bindings for media processingcpal: Cross-platform audio library for audio I/Othiserror: Error handling utilitiesThis crate is designed for applications that need to:
The crate serves as a compatibility layer between:
This makes it particularly suitable for screen recording, video conferencing, and media streaming applications.