Crate ffmpeg_light

Crate ffmpeg_light 

Source
Expand description

§ffmpeg-light

A small Rust crate that wraps a few common FFmpeg tasks without asking you to memorize the entire CLI.

§Why this exists

When you just want to probe a file, transcode it to H.264, or grab a thumbnail, the full FFmpeg CLI can feel like overkill. On the other hand, pulling in a massive set of raw bindings is equally daunting. ffmpeg-light sits in the middle: it spawns the ffmpeg/ffprobe binaries you already have installed and gives you a tidy Rust API for the 80% use cases.

This crate is young. Expect the API to move a bit until we get feedback from real projects.

§Installation

[dependencies]
ffmpeg-light = "0.1"

You’ll also need the ffmpeg and ffprobe binaries available on your PATH. On macOS that might be brew install ffmpeg; on Windows, grab the latest build and add it to your environment variables.

§Quick start

§Probe a media file

use ffmpeg_light::probe;

fn main() -> ffmpeg_light::Result<()> {
    let info = probe("input.mp4")?;
    if let Some(duration) = info.duration() {
        println!("duration: {:?}", duration);
    }
    Ok(())
}

§Transcode to H.264 MP4

use ffmpeg_light::transcode::TranscodeBuilder;

fn main() -> ffmpeg_light::Result<()> {
    TranscodeBuilder::new()
        .input("input.avi")
        .output("output.mp4")
        .video_codec("libx264")
        .audio_codec("aac")
        .video_bitrate(2_500)
        .size(1280, 720)
        .run()?;
    Ok(())
}

§Grab a thumbnail

use ffmpeg_light::{thumbnail::ThumbnailOptions, types::Time};

fn main() -> ffmpeg_light::Result<()> {
    let options = ThumbnailOptions::new(Time::from_seconds_f64(12.5));
    ffmpeg_light::generate_thumbnail("input.mp4", "thumb.png", &options)?;
    Ok(())
}

§Features

  • Media probing built on ffprobe JSON output.
  • A TranscodeBuilder that covers basic codecs, bitrates, presets, filters, and custom args.
  • Thumbnail generation with timestamp/size/format controls.
  • Simple filter enum so you don’t have to concat raw filter strings.
  • Optional logging via the tracing feature.
  • Optional async command execution via the tokio feature (roadmap).

§Design notes

  • The crate shells out to ffmpeg/ffprobe. That keeps builds fast, works anywhere binaries exist, and avoids shipping unsafe bindings.
  • We never hand your input to a shell. Every argument is passed directly to std::process::Command.
  • If you need the full FFmpeg surface area, you can still drop down to the CLI; this crate is for the frequent, boring chores.

§Platform notes

The library is tested on Linux, macOS, and Windows as long as FFmpeg is on PATH. Windows users should prefer paths without spaces or wrap them in PathBuf to avoid quoting issues (the builder handles the quoting, but FFmpeg can still trip over exotic characters).

§Roadmap

  • Async command helpers behind a tokio feature gate.
  • More preset filters (denoise, deinterlace, etc.).
  • Higher-level profiles for “transcode for web” or “extract audio only”.
  • Better integration tests once we ship sample fixtures.

§License

Licensed under the Apache License, Version 2.0. ffmpeg-light is a small Rust crate that wraps a few common FFmpeg tasks.

It focuses on the “80% use cases” like probing media, transcoding, and generating thumbnails, without exposing the full complexity of FFmpeg.

§Quick Start

Add to your Cargo.toml:

[dependencies]
ffmpeg-light = "0.1"

Note: This crate requires ffmpeg and ffprobe binaries to be installed and available on PATH.

§Example: Probe a video file

use ffmpeg_light::probe;

let result = probe("input.mp4")?;
println!("Duration: {:?}", result.duration());

§Example: Transcode to H.264 MP4

use ffmpeg_light::transcode::TranscodeBuilder;

TranscodeBuilder::new()
    .input("input.avi")
    .output("output.mp4")
    .video_codec("libx264")
    .run()?;

Re-exports§

pub use error::Error;
pub use error::Result;
pub use probe::probe;
pub use thumbnail::generate as generate_thumbnail;
pub use transcode::TranscodeBuilder;
pub use types::*;

Modules§

command
Low-level process helpers for interacting with ffmpeg and ffprobe. Low-level helpers for invoking the ffmpeg and ffprobe binaries.
config
Configuration helpers for locating ffmpeg binaries. Configuration helpers for locating FFmpeg binaries.
error
Shared error type and Result alias used by the crate.
filter
Small collection of filter helpers used by transcoding. Helper types for common FFmpeg video filters.
probe
Media probing API built on top of ffprobe JSON output. Media probing utilities built on top of ffprobe.
thumbnail
Thumbnail generation helpers. Thumbnail generation helpers.
transcode
Builder API around common transcoding flows. Transcoding helpers built on top of the CLI ffmpeg binary.
types
Shared domain types (timecodes, codecs, stream metadata). Common domain types shared across the crate.