bumblebee/src/transcode/job.rs

37 lines
1018 B
Rust

use std::process::{Child, Command};
use crate::configuration::ConfigFFmpeg;
use crate::error;
pub struct TranscodeJob {
pub input: String,
pub output: String
}
impl TranscodeJob {
pub fn new<S: Into<String>>(input: S, output: S) -> TranscodeJob {
TranscodeJob {
input: input.into(),
output: output.into()
}
}
pub fn build_command(&self, ffmpeg_config: &ConfigFFmpeg) -> Command {
ffmpeg_config
.build_command_options(&self.input, &self.output)
.to_command(&ffmpeg_config.path)
}
pub fn check_if_exists(&self) -> bool {
std::path::Path::new(&self.output).exists()
}
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, error::Error> {
debug!("Running job: {:#?}", &self.input);
let mut command = self.build_command(ffmpeg_config);
match command.spawn() {
Ok(child) => Ok(child),
Err(e) => Err(error::Error::JobError(e))
}
}
}