From 2980b705377c5f3714391fd00ae5dabc4cfd636a Mon Sep 17 00:00:00 2001 From: Zen <46526140+master-of-zen@users.noreply.github.com> Date: Sat, 7 Aug 2021 02:40:00 +0300 Subject: [PATCH] some doc comments --- av1an-core/src/encoder.rs | 13 +++++++++++++ av1an-core/src/ffmpeg.rs | 3 +++ av1an-core/src/file_validation.rs | 1 + av1an-core/src/progress_bar.rs | 2 ++ av1an-core/src/target_quality.rs | 3 +++ 5 files changed, 22 insertions(+) diff --git a/av1an-core/src/encoder.rs b/av1an-core/src/encoder.rs index 0712fa3..9cae0c8 100644 --- a/av1an-core/src/encoder.rs +++ b/av1an-core/src/encoder.rs @@ -31,6 +31,7 @@ impl Display for Encoder { } impl Encoder { + /// Composes 1st pass command for 1 pass encoding pub fn compose_1_1_pass(self, params: Vec, output: String) -> Vec { match &self { Self::aom => chain!( @@ -79,6 +80,7 @@ impl Encoder { } } + /// Composes 1st pass command for 2 pass encoding pub fn compose_1_2_pass(self, params: Vec, fpf: &str) -> Vec { match &self { Self::aom => chain!( @@ -204,6 +206,7 @@ impl Encoder { } } + /// Composes 2st pass command for 2 pass encoding pub fn compose_2_2_pass(self, params: Vec, fpf: &str, output: String) -> Vec { match &self { Self::aom => chain!( @@ -278,6 +281,7 @@ impl Encoder { } } + /// Returns default settings for the encoder pub fn get_default_arguments(self) -> Vec { match &self { Encoder::aom => into_vec![ @@ -316,6 +320,7 @@ impl Encoder { } } + /// Return number of default passes for encoder pub const fn get_default_pass(self) -> u8 { match &self { Self::aom | Self::vpx => 2, @@ -333,6 +338,7 @@ impl Encoder { } } + /// Returns help command for encoder pub const fn help_command(self) -> [&'static str; 2] { match &self { Self::aom => ["aomenc", "--help"], @@ -364,6 +370,7 @@ impl Encoder { } } + /// Returns string used for regex matching q/crf arguments in command line const fn q_regex_str(&self) -> &str { match &self { Self::aom | Self::vpx => r"--cq-level=.+", @@ -380,6 +387,7 @@ impl Encoder { } } + /// Returns changed q/crf in command line arguments pub fn man_command(self, params: Vec, q: usize) -> Vec { let index = list_index_of_regex(¶ms, self.q_regex_str()).unwrap(); @@ -390,6 +398,7 @@ impl Encoder { new_params } + /// Retuns string for regex to matching encoder progress in cli const fn pipe_match(&self) -> &str { match &self { Self::aom | Self::vpx => r".*Pass (?:1/1|2/2) .*frame.*?/([^ ]+?) ", @@ -400,6 +409,7 @@ impl Encoder { } } + /// Returs option of q/crf value from cli encoder output pub fn match_line(self, line: &str) -> Option { let encoder_regex = Regex::new(self.pipe_match()).unwrap(); if !encoder_regex.is_match(line) { @@ -409,6 +419,7 @@ impl Encoder { captures.parse::().ok() } + /// Returns command used for target quality probing pub fn construct_target_quality_command( self, threads: usize, @@ -577,6 +588,7 @@ impl Encoder { } } + /// Returns command used for target quality probing (slow, correctness focused version) pub fn construct_target_quality_command_probe_slow(self, q: usize) -> Vec> { match &self { Self::aom => into_vec!["aomenc", "--passes=1", format!("--cq-level={}", q)], @@ -636,6 +648,7 @@ impl Encoder { .collect::>() } + /// Constructs tuple of commands for target quality probing pub fn probe_cmd( self, temp: String, diff --git a/av1an-core/src/ffmpeg.rs b/av1an-core/src/ffmpeg.rs index aa0bf54..b3709a0 100644 --- a/av1an-core/src/ffmpeg.rs +++ b/av1an-core/src/ffmpeg.rs @@ -75,6 +75,7 @@ pub fn get_keyframes>(source: P) -> Vec { kfs } +/// Returns true if input file have audio in it pub fn has_audio(file: &Path) -> bool { let mut cmd = Command::new("ffmpeg"); @@ -135,6 +136,7 @@ pub fn encode_audio>( } } +/// Returns list of frame types of the video pub fn get_frame_types(file: &Path) -> Vec { let mut cmd = Command::new("ffmpeg"); @@ -170,6 +172,7 @@ pub fn get_frame_types(file: &Path) -> Vec { string_vec } +/// Escapes paths in ffmpeg filters if on windows pub fn escape_path_in_filter(path: impl AsRef) -> String { if cfg!(target_os = "windows") { PathAbs::new(path.as_ref()) diff --git a/av1an-core/src/file_validation.rs b/av1an-core/src/file_validation.rs index 6226336..adc21e7 100644 --- a/av1an-core/src/file_validation.rs +++ b/av1an-core/src/file_validation.rs @@ -10,6 +10,7 @@ fn match_file_type(input: &Path) -> bool { .any(|&v| input.extension().map_or(false, |u| v == u)) } +/// Check if all files in files actually exists fn validate_files(files: &[PathBuf]) -> Vec { let valid: Vec = files .iter() diff --git a/av1an-core/src/progress_bar.rs b/av1an-core/src/progress_bar.rs index e0003fe..8e068d8 100644 --- a/av1an-core/src/progress_bar.rs +++ b/av1an-core/src/progress_bar.rs @@ -13,6 +13,8 @@ const INDICATIF_PROGRESS_TEMPLATE: &str = if cfg!(target_os = "windows") { static PROGRESS_BAR: OnceCell = OnceCell::new(); +/// Initialize progress bar +/// Enables steady 100 ms tick pub fn init_progress_bar(len: u64) { let pb = PROGRESS_BAR.get_or_init(|| { ProgressBar::new(len).with_style( diff --git a/av1an-core/src/target_quality.rs b/av1an-core/src/target_quality.rs index 6daba42..074d2d3 100644 --- a/av1an-core/src/target_quality.rs +++ b/av1an-core/src/target_quality.rs @@ -20,6 +20,7 @@ pub fn transform_vmaf(vmaf: f64) -> f64 { } } +/// Returns auto detected amount of threads used for vmaf calculation pub fn vmaf_auto_threads(workers: usize) -> usize { const OVER_PROVISION_FACTOR: f64 = 1.25; @@ -32,6 +33,7 @@ pub fn vmaf_auto_threads(workers: usize) -> usize { ) } +/// Use linear interpolation to get q/crf values closest to the target value pub fn interpolate_target_q(scores: Vec<(f64, u32)>, target: f64) -> Result { let mut sorted = scores; sorted.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); @@ -46,6 +48,7 @@ pub fn interpolate_target_q(scores: Vec<(f64, u32)>, target: f64) -> Result, q: f64) -> Result { let mut sorted = scores; sorted.sort_by(|(a, _), (b, _)| a.partial_cmp(b).unwrap_or(Ordering::Less));