some doc comments

This commit is contained in:
Zen 2021-08-07 02:40:00 +03:00
parent 213e7c8e79
commit 2980b70537
5 changed files with 22 additions and 0 deletions

View file

@ -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<String>, output: String) -> Vec<String> {
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<String>, fpf: &str) -> Vec<String> {
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<String>, fpf: &str, output: String) -> Vec<String> {
match &self {
Self::aom => chain!(
@ -278,6 +281,7 @@ impl Encoder {
}
}
/// Returns default settings for the encoder
pub fn get_default_arguments(self) -> Vec<String> {
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<String>, q: usize) -> Vec<String> {
let index = list_index_of_regex(&params, 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<usize> {
let encoder_regex = Regex::new(self.pipe_match()).unwrap();
if !encoder_regex.is_match(line) {
@ -409,6 +419,7 @@ impl Encoder {
captures.parse::<usize>().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<Cow<'static, str>> {
match &self {
Self::aom => into_vec!["aomenc", "--passes=1", format!("--cq-level={}", q)],
@ -636,6 +648,7 @@ impl Encoder {
.collect::<Vec<String>>()
}
/// Constructs tuple of commands for target quality probing
pub fn probe_cmd(
self,
temp: String,

View file

@ -75,6 +75,7 @@ pub fn get_keyframes<P: AsRef<Path>>(source: P) -> Vec<usize> {
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<S: AsRef<OsStr>>(
}
}
/// Returns list of frame types of the video
pub fn get_frame_types(file: &Path) -> Vec<String> {
let mut cmd = Command::new("ffmpeg");
@ -170,6 +172,7 @@ pub fn get_frame_types(file: &Path) -> Vec<String> {
string_vec
}
/// Escapes paths in ffmpeg filters if on windows
pub fn escape_path_in_filter(path: impl AsRef<Path>) -> String {
if cfg!(target_os = "windows") {
PathAbs::new(path.as_ref())

View file

@ -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<PathBuf> {
let valid: Vec<PathBuf> = files
.iter()

View file

@ -13,6 +13,8 @@ const INDICATIF_PROGRESS_TEMPLATE: &str = if cfg!(target_os = "windows") {
static PROGRESS_BAR: OnceCell<ProgressBar> = 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(

View file

@ -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<f64, Error> {
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<f64,
Ok(spline.sample(target).unwrap())
}
/// Use linear interpolation to get vmaf value that expected from q
pub fn interpolate_target_vmaf(scores: Vec<(f64, u32)>, q: f64) -> Result<f64, Error> {
let mut sorted = scores;
sorted.sort_by(|(a, _), (b, _)| a.partial_cmp(b).unwrap_or(Ordering::Less));