Module core

Source
Expand description

The core module provides the foundational building blocks for configuring and running FFmpeg pipelines. It encompasses:

  • Input & Output Handling (in context): Structures and logic (Input, Output) for specifying where media data originates and where it should be written.
  • Filter Descriptions: Define filter graphs with FilterComplex or attach custom FrameFilter implementations at the input/output stage.
  • Stream and Device Queries (in stream_info and device): Utilities for retrieving information about media streams and available input devices.
  • Hardware Acceleration (in hwaccel): Enumerate/configure GPU-accelerated codecs (CUDA, VAAPI, etc.).
  • Codec Discovery (in codec): List encoders/decoders supported by FFmpeg.
  • Custom Filters (in filter): Implement user-defined FrameFilter logic for frames.
  • Lifecycle Orchestration (in scheduler): FfmpegScheduler that runs the configured pipeline (synchronously or asynchronously if the async feature is enabled).

§Submodules

  • context: Houses FfmpegContext—the central struct for assembling inputs, outputs, and filters.
  • scheduler: Defines FfmpegScheduler, managing the execution of an FfmpegContext pipeline.
  • container_info: Utilities to extract information about the container, such as duration and format details.
  • stream_info: Inspect media streams (e.g., find video/audio streams in a file).
  • device: Query audio/video input devices (cameras, microphones, etc.) on various platforms.
  • hwaccel: Helpers for hardware-accelerated encoding/decoding setup.
  • codec: Tools to discover which encoders/decoders your FFmpeg build supports.
  • filter: Query FFmpeg’s built-in filters and infrastructure for building custom frame-processing filters.

§Example Workflow

  1. Build a context using FfmpegContext::builder() specifying your input, any filters, and your output.
  2. Create a scheduler with FfmpegScheduler::new, then call .start() to begin processing.
  3. Wait (or .await if async feature is enabled) for the job to complete. Use the returned Result to detect success or failure.

§Example


fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Build an FfmpegContext with an input, a simple filter, and an output
    let context = FfmpegContext::builder()
        .input("test.mp4")
        .filter_desc("hue=s=0") // Example: desaturate video
        .output("output.mp4")
        .build()?;

    // 2. Create a scheduler and start the job
    let scheduler = FfmpegScheduler::new(context).start()?;

    // 3. Block until it's finished
    scheduler.wait()?;
    Ok(())
}

Modules§

codec
The codec module provides helpers for enumerating and querying FFmpeg’s available audio/video encoders and decoders. This can be useful for discovering which codecs are supported in your current FFmpeg build, along with their core attributes.
container_info
The container_info module provides utilities for retrieving metadata related to the media container, such as duration, format, and other general properties of the media file.
context
The context module provides tools for assembling an entire FFmpeg pipeline, culminating in the FfmpegContext. This includes:
device
The device module provides cross-platform methods to query available audio and video input devices on the system. Depending on the target operating system, it internally delegates to different platform APIs or FFmpeg’s device capabilities:
filter
The filter module provides a flexible framework for custom frame processing within the FFmpeg pipeline, along with the ability to query FFmpeg’s built-in filters. It introduces the FrameFilter trait, which defines how to apply transformations (e.g., scaling, color adjustments, GPU-accelerated effects) to decoded frames. You can attach these filters to either the input or the output side (depending on your desired pipeline design) so that frames are automatically processed in your FFmpeg workflow.
hwaccel
The hwaccel module provides functionality for working with hardware-accelerated codecs in FFmpeg. It allows you to detect and configure various hardware devices (like NVENC, VAAPI, DXVA2, or VideoToolbox) so that FFmpeg can offload encoding or decoding tasks to GPU or specialized hardware.
scheduler
The scheduler module orchestrates the execution of a configured FfmpegContext. It provides the FfmpegScheduler struct, which:
stream_info
The stream_info module provides utilities to retrieve detailed information about media streams (video, audio, and more) from an input source (e.g., a local file path, an RTMP URL, etc.). It queries FFmpeg for metadata regarding stream types, codec parameters, duration, and other relevant details.