bumblebee/src/transcode/job.rs

37 lines
1018 B
Rust
Raw Normal View History

use std::process::{Child, Command};
2023-05-08 08:07:09 +00:00
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 {
2023-05-08 08:27:06 +00:00
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()
}
2023-05-08 08:07:09 +00:00
pub fn run(&self, ffmpeg_config: &ConfigFFmpeg) -> Result<Child, error::Error> {
2023-05-08 08:27:06 +00:00
debug!("Running job: {:#?}", &self.input);
let mut command = self.build_command(ffmpeg_config);
2023-05-08 08:07:09 +00:00
match command.spawn() {
Ok(child) => Ok(child),
Err(e) => Err(error::Error::JobError(e))
}
}
}