From 226b19a177959dad373c6696852aea97f505465b Mon Sep 17 00:00:00 2001 From: Didier Date: Mon, 8 May 2023 10:32:13 +0200 Subject: [PATCH] fix(config): moved ffmpeg configs to it's own file --- src/configuration/ffmpeg.rs | 40 ++++++++++++++++++++++++++++--- src/configuration/mod.rs | 47 +++++-------------------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/configuration/ffmpeg.rs b/src/configuration/ffmpeg.rs index 2f3a0aa..23e4f7d 100644 --- a/src/configuration/ffmpeg.rs +++ b/src/configuration/ffmpeg.rs @@ -1,6 +1,40 @@ -use crate::configuration::ConfigFFmpeg; use crate::ffmpeg::FFmpegCommandOptions; +#[derive(Serialize, Deserialize, Debug)] +pub struct ConfigFFmpegProcess { + pub threads: Option, + pub niceness: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ConfigFFmpegOutputVideo { + pub codec: String, + pub bitrate: u32, + pub crf: u8, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ConfigFFmpegOutputAudio { + pub codec: String, + pub bitrate: u32, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ConfigFFmpegOutput { + pub format: String, + pub video: ConfigFFmpegOutputVideo, + pub audio: ConfigFFmpegOutputAudio, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ConfigFFmpeg { + pub path: String, + pub extra_args: Option>, + pub overwrite: Option, + pub process: Option, + pub output: ConfigFFmpegOutput, +} + impl ConfigFFmpeg { pub fn build_command_options>(&self, input_path: S, output_path: S) -> FFmpegCommandOptions { FFmpegCommandOptions { @@ -18,8 +52,8 @@ impl ConfigFFmpeg { extra_args: if self.extra_args.is_some() { self.extra_args.clone().unwrap() } else { Vec::new() }, - threads: if self.process.threads.unwrap_or(0) > 0 { Some(self.process.threads.unwrap_or(0)) } else { None }, - niceness: if self.process.niceness.unwrap_or(0) > 0 { Some(self.process.niceness.unwrap_or(0)) } else { None }, + threads: if self.process.is_some() && self.process.as_ref().unwrap().threads.is_some() { Some(self.process.as_ref().unwrap().threads.unwrap()) } else { None }, + niceness: if self.process.is_some() && self.process.as_ref().unwrap().niceness.is_some() { Some(self.process.as_ref().unwrap().niceness.unwrap()) } else { None }, } } } \ No newline at end of file diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index 26099bb..057e130 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -36,46 +36,11 @@ pub struct ConfigFiles { pub cleanup: Option, } -#[derive(Serialize, Deserialize, Debug)] -pub struct ConfigFFmpegProcess { - pub threads: Option, - pub niceness: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ConfigFFmpegOutputVideo { - pub codec: String, - pub bitrate: u32, - pub crf: u8, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ConfigFFmpegOutputAudio { - pub codec: String, - pub bitrate: u32, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ConfigFFmpegOutput { - pub format: String, - pub video: ConfigFFmpegOutputVideo, - pub audio: ConfigFFmpegOutputAudio, -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct ConfigFFmpeg { - pub path: String, - pub extra_args: Option>, - pub overwrite: Option, - pub process: Option, - pub output: ConfigFFmpegOutput, -} - #[derive(Serialize, Deserialize, Debug)] pub struct Config { pub debug: Option, pub files: ConfigFiles, - pub ffmpeg: ConfigFFmpeg, + pub ffmpeg: ffmpeg::ConfigFFmpeg, } impl Config { @@ -88,22 +53,22 @@ impl Config { include: Vec::new(), cleanup: None, }, - ffmpeg: ConfigFFmpeg { + ffmpeg: ffmpeg::ConfigFFmpeg { path: String::from("/usr/bin/ffmpeg"), extra_args: None, overwrite: None, - process: Some(ConfigFFmpegProcess { + process: Some(ffmpeg::ConfigFFmpegProcess { threads: Some(0), niceness: Some(0), }), - output: ConfigFFmpegOutput { + output: ffmpeg::ConfigFFmpegOutput { format: String::from("webm"), - video: ConfigFFmpegOutputVideo { + video: ffmpeg::ConfigFFmpegOutputVideo { codec: String::from("libsvtav1"), bitrate: 0, crf: 0, }, - audio: ConfigFFmpegOutputAudio { + audio: ffmpeg::ConfigFFmpegOutputAudio { codec: String::from("libopus"), bitrate: 0, },