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 isasync. - Real-time Monitoring: Subscribe to a stream of structured events for progress, logs, and job completion.
- Process Control: Gracefully
cancel()or forcefullykill()a running encoding job. - Flexible Setup: Automatically finds
HandBrakeCLIin the systemPATHor 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§
- Audio
Config - Details about the audio tracks from the job configuration.
- Audio
Track Config - Details for a single audio track.
- Config
- The full job configuration as reported by
HandBrakeCLI. - Destination
Config - Details about the output destination from the job configuration.
- Hand
Brake - The main entry point for the
handbrake-rscrate. - JobBuilder
- A fluent builder for configuring a
HandBrakeCLIencoding job. - JobFailure
- Details of a job failure.
- JobHandle
- A handle to a running
HandBrakeCLIjob. - Log
- A log message from the
HandBrakeCLIprocess. - Progress
- A progress update from an ongoing
HandBrakeCLIjob. - Source
Config - Details about the input source from the job configuration.
- Video
Config - Details about the video encoding from the job configuration.
Enums§
- Error
- The primary error type for the
handbrake-rscrate. - Input
Source - Represents the input source for a
HandBrakeCLIjob. - JobEvent
- An event emitted by a monitored
HandBrakeCLIjob. - Output
Destination - Represents the output destination for a
HandBrakeCLIjob.