Crate handbrake

Crate handbrake 

Source
Expand description

A safe, ergonomic, and asynchronous Rust crate for controlling the HandBrakeCLI video transcoder.

handbrake-rs allows Rust applications to programmatically start, configure, monitor, and control HandBrake encoding jobs without needing to manually handle command-line arguments or parse raw text output.

§Features

  • Fluent Job Configuration: Use a builder pattern to easily configure encoding jobs.
  • Asynchronous API: Built on tokio, the entire API is async.
  • Real-time Monitoring: Subscribe to a stream of structured events for progress, logs, and job completion.
  • Process Control: Gracefully cancel() or forcefully kill() a running encoding job.
  • Flexible Setup: Automatically finds HandBrakeCLI in the system PATH or allows specifying a direct path.

§Quick Start

use handbrake::{HandBrake, JobEvent};
use futures::StreamExt;
use std::path::PathBuf;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Find HandBrakeCLI in the system PATH
    let hb = HandBrake::new().await?;

    let input = PathBuf::from("path/to/your/video.mkv");
    let output = PathBuf::from("path/to/your/output.mp4");

    // Configure and start the encoding job
    let mut job_handle = hb
        .job(input.into(), output.into())
        .preset("Fast 1080p30")
        .quality(22.0)
        .start()?;

    // Listen for events
    while let Some(event) = job_handle.events().next().await {
        match event {
            JobEvent::Progress(p) => {
                println!("Encoding: {:.2}% complete", p.percentage);
            }
            JobEvent::Done(result) => {
                if result.is_ok() {
                    println!("Done!");
                } else {
                    eprintln!("Encoding failed.");
                }
                break;
            }
            _ => {}
        }
    }

    Ok(())
}

Structs§

AudioConfig
Details about the audio tracks from the job configuration.
AudioTrackConfig
Details for a single audio track.
Config
The full job configuration as reported by HandBrakeCLI.
DestinationConfig
Details about the output destination from the job configuration.
HandBrake
The main entry point for the handbrake-rs crate.
JobBuilder
A fluent builder for configuring a HandBrakeCLI encoding job.
JobFailure
Details of a job failure.
JobHandle
A handle to a running HandBrakeCLI job.
Log
A log message from the HandBrakeCLI process.
Progress
A progress update from an ongoing HandBrakeCLI job.
SourceConfig
Details about the input source from the job configuration.
VideoConfig
Details about the video encoding from the job configuration.

Enums§

Error
The primary error type for the handbrake-rs crate.
InputSource
Represents the input source for a HandBrakeCLI job.
JobEvent
An event emitted by a monitored HandBrakeCLI job.
OutputDestination
Represents the output destination for a HandBrakeCLI job.