Skip to main content

Crate ff_probe

Crate ff_probe 

Source
Expand description

§ff-probe

Media file metadata extraction - the Rust way.

This crate provides functionality for extracting metadata from media files, including video streams, audio streams, and container information. It serves as the Rust equivalent of ffprobe with a clean, idiomatic API.

§Module Structure

  • error - Error types (ProbeError)
  • info - Media info extraction (open)

§Quick Start

use ff_probe::open;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let info = open("video.mp4")?;

    println!("Format: {}", info.format());
    println!("Duration: {:?}", info.duration());

    // Check for video stream
    if let Some(video) = info.primary_video() {
        println!("Video: {}x{} @ {:.2} fps",
            video.width(),
            video.height(),
            video.fps()
        );
    }

    // Check for audio stream
    if let Some(audio) = info.primary_audio() {
        println!("Audio: {} Hz, {} channels",
            audio.sample_rate(),
            audio.channels()
        );
    }

    Ok(())
}

§Extracting Detailed Information

use ff_probe::{open, ColorSpace, ColorPrimaries};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let info = open("hdr_video.mp4")?;

    // Enumerate all video streams
    for (i, stream) in info.video_streams().iter().enumerate() {
        println!("Video stream {}: {} {}x{}",
            i, stream.codec_name(), stream.width(), stream.height());
        println!("  Color space: {:?}", stream.color_space());
        println!("  Color range: {:?}", stream.color_range());

        // Check for HDR content
        if stream.color_primaries() == ColorPrimaries::Bt2020 {
            println!("  HDR content detected!");
        }

        if let Some(bitrate) = stream.bitrate() {
            println!("  Bitrate: {} kbps", bitrate / 1000);
        }
    }

    // Enumerate all audio streams
    for (i, stream) in info.audio_streams().iter().enumerate() {
        println!("Audio stream {}: {} {} Hz, {} ch",
            i, stream.codec_name(), stream.sample_rate(), stream.channels());
        if let Some(lang) = stream.language() {
            println!("  Language: {}", lang);
        }
    }

    // Access container metadata
    if let Some(title) = info.title() {
        println!("Title: {}", title);
    }
    if let Some(artist) = info.artist() {
        println!("Artist: {}", artist);
    }

    Ok(())
}

§Error Handling

The crate provides detailed error types through ProbeError:

use ff_probe::{open, ProbeError};

let result = open("/nonexistent/path.mp4");

match result {
    Err(ProbeError::FileNotFound { path }) => {
        println!("File not found: {}", path.display());
    }
    Err(ProbeError::CannotOpen { path, reason }) => {
        println!("Cannot open {}: {}", path.display(), reason);
    }
    Err(ProbeError::InvalidMedia { path, reason }) => {
        println!("Invalid media {}: {}", path.display(), reason);
    }
    Err(e) => println!("Other error: {}", e),
    Ok(info) => println!("Opened: {}", info.format()),
}

§Features

  • Extract container format information (MP4, MKV, AVI, etc.)
  • List all video and audio streams with detailed properties
  • Get codec parameters (codec type, pixel format, sample format)
  • Read container and stream metadata (title, artist, etc.)
  • Color space and HDR information (BT.709, BT.2020, etc.)
  • Bitrate extraction and calculation
  • Duration and frame count information

Modules§

prelude
Prelude module for convenient imports.

Structs§

AudioStreamInfo
Information about an audio stream within a media file.
ChapterInfo
Information about a chapter within a media file.
ChapterInfoBuilder
Builder for constructing ChapterInfo.
MediaInfo
Information about a media file.
Rational
A rational number represented as a fraction (numerator / denominator).
SubtitleStreamInfo
Information about a subtitle stream within a media file.
SubtitleStreamInfoBuilder
Builder for constructing SubtitleStreamInfo.
Timestamp
A timestamp representing a point in time within a media stream.
VideoStreamInfo
Information about a video stream within a media file.

Enums§

AudioCodec
Audio codec identifier.
ChannelLayout
Audio channel layout representing the speaker configuration.
ColorPrimaries
Color primaries defining the color gamut (the range of colors that can be represented).
ColorRange
Color range defining the valid range of color values.
ColorSpace
Color space (matrix coefficients) for YUV to RGB conversion.
PixelFormat
Pixel format for video frames.
ProbeError
Error type for media probing operations.
SampleFormat
Audio sample format for audio frames.
SubtitleCodec
Subtitle codec identifier.
VideoCodec
Video codec identifier.

Functions§

open
Opens a media file and extracts its metadata.