bumblebee/src/ffmpeg.rs

75 lines
1.9 KiB
Rust

use std::process::Command;
pub struct FFmpegCommandOptions {
pub input: String,
pub output: String,
pub video_codec: String,
pub video_bitrate: Option<u32>,
pub video_crf: Option<u8>,
pub audio_codec: String,
pub audio_bitrate: Option<u32>,
pub overwrite: Option<bool>,
pub extra_args: Vec<String>,
pub threads: Option<u8>,
pub niceness: Option<u8>
}
impl FFmpegCommandOptions {
pub fn to_args(&self) -> Vec<String> {
let mut args = Vec::new();
args.push("-i".to_string());
args.push(self.input.clone());
args.push("-c:v".to_string());
args.push(self.video_codec.clone());
args.push("-c:a".to_string());
args.push(self.audio_codec.clone());
if let Some(bitrate) = self.video_bitrate {
args.push("-b:v".to_string());
args.push(bitrate.to_string());
}
if let Some(crf) = self.video_crf {
args.push("-crf".to_string());
args.push(crf.to_string());
}
if let Some(bitrate) = self.audio_bitrate {
args.push("-b:a".to_string());
args.push(bitrate.to_string());
}
if let Some(threads) = self.threads {
args.push("-threads".to_string());
args.push(threads.to_string());
}
if let Some(niceness) = self.niceness {
args.push("-threads".to_string());
args.push(niceness.to_string());
}
if let Some(allow_overwrite) = self.overwrite {
if allow_overwrite {
args.push("-y".to_string());
}
}
args.append(&mut self.extra_args.clone());
args.push(self.output.clone());
args
}
pub fn to_command(&self, ffmpeg_path: &str) -> Command {
let mut command = Command::new(ffmpeg_path);
command.args(self.to_args());
command
}
}