Skip to main content

Crate ff_decode

Crate ff_decode 

Source
Expand description

§ff-decode

Video and audio decoding - the Rust way.

This crate provides frame-by-frame video/audio decoding, efficient seeking, and thumbnail generation. It completely hides FFmpeg internals and provides a safe, ergonomic Rust API.

§Features

  • Video Decoding: Frame-by-frame decoding with Iterator pattern
  • Audio Decoding: Sample-level audio extraction
  • Seeking: Fast keyframe and exact seeking without file re-open
  • Thumbnails: Efficient thumbnail generation for timelines
  • Hardware Acceleration: Optional NVDEC, QSV, AMF, VideoToolbox, VAAPI support
  • Frame Pooling: Memory reuse for reduced allocation overhead

§Usage

§Video Decoding

use ff_decode::{VideoDecoder, SeekMode};
use ff_format::PixelFormat;
use std::time::Duration;

// Open a video file and create decoder
let mut decoder = VideoDecoder::open("video.mp4")?
    .output_format(PixelFormat::Rgba)
    .build()?;

// Get basic info
println!("Duration: {:?}", decoder.duration());
println!("Resolution: {}x{}", decoder.width(), decoder.height());

// Decode frames sequentially
for frame in decoder.frames().take(100) {
    let frame = frame?;
    println!("Frame at {:?}", frame.timestamp().as_duration());
}

// Seek to specific position
decoder.seek(Duration::from_secs(30), SeekMode::Keyframe)?;

§Audio Decoding

use ff_decode::AudioDecoder;
use ff_format::SampleFormat;

let mut decoder = AudioDecoder::open("audio.mp3")?
    .output_format(SampleFormat::F32)
    .output_sample_rate(48000)
    .build()?;

// Decode all audio samples
for frame in decoder.frames().take(100) {
    let frame = frame?;
    println!("Audio frame with {} samples", frame.samples());
}

§Hardware Acceleration (Video)

use ff_decode::{VideoDecoder, HardwareAccel};

let decoder = VideoDecoder::open("video.mp4")?
    .hardware_accel(HardwareAccel::Auto)  // Auto-detect GPU
    .build()?;

§Frame Pooling (Video)

use ff_decode::{VideoDecoder, FramePool};
use std::sync::Arc;

// Use a frame pool for memory reuse
let pool: Arc<dyn FramePool> = create_frame_pool(32);
let decoder = VideoDecoder::open("video.mp4")?
    .frame_pool(pool)
    .build()?;

§Module Structure

  • audio - Audio decoder for extracting audio frames
  • video - Video decoder for extracting video frames
  • error - Error types for decoding operations
  • Frame pool types (FramePool, PooledBuffer, SimpleFramePool) are provided by ff-common

§Re-exports

This crate re-exports commonly used types from ff-format for convenience.

Re-exports§

pub use audio::AudioDecoder;
pub use audio::AudioDecoderBuilder;
pub use audio::AudioFrameIterator;
pub use error::DecodeError;
pub use image::ImageDecoder;
pub use image::ImageDecoderBuilder;
pub use image::ImageFrameIterator;
pub use video::VideoDecoder;
pub use video::VideoDecoderBuilder;
pub use video::VideoFrameIterator;

Modules§

audio
Audio decoding module.
error
Error types for decoding operations.
image
Image decoding module.
prelude
Prelude module for convenient imports.
video
Video decoding module.

Structs§

PooledBuffer
A buffer acquired from a FramePool.

Enums§

HardwareAccel
Hardware acceleration configuration.
SeekMode
Seek mode for positioning the decoder.

Traits§

FramePool
A trait for frame buffer pooling.

Type Aliases§

SimpleFramePool
Alias for VecPool kept for backwards compatibility with ff-decode.