Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ pub fn run(
}
}

let sample = Sample {
crf: args.crf,
let sample = Sample::new(
args.crf,
q,
enc: sample_enc_output.context("no sample output?")?,
};
sample_enc_output.context("no sample output?")?,
);
let score = output_search_score(&sample.enc, use_xpsnr);
crf_attempts.push(sample.clone());

Expand Down Expand Up @@ -559,6 +559,10 @@ pub struct Sample {
}

impl Sample {
pub(crate) fn new(crf: f32, q: i64, enc: sample_encode::Output) -> Self {
Self { enc, crf, q }
}

pub fn print_attempt(
&self,
bar: &ProgressBar,
Expand Down
49 changes: 48 additions & 1 deletion src/command/crf_search/decision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn decide_next_transition(
if lower_score >= min_score {
Error::ensure_or_no_good_crf(
lower.enc.encode_percent <= max_encoded_percent.get(),
sample,
lower,
)?;
Ok(SearchTransition::RunResultThenDone {
run_result: sample.clone(),
Expand Down Expand Up @@ -147,3 +147,50 @@ pub fn guess_progress(run: usize, sample_progress: f32, thorough: bool) -> f64 {
let sample_progress = sample_progress.clamp(0.0, 1.0) as f64;
(((run - 1) as f64 + sample_progress) * BAR_LEN as f64 / total_runs_guess).min(BAR_LEN as f64)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::command::sample_encode;
use std::time::Duration;

fn sample(q: i64, score: f32, encode_percent: f64) -> Sample {
Sample::new(
q as f32,
q,
sample_encode::Output {
vmaf_score: Some(score),
xpsnr_score: None,
predicted_encode_size: 1_000,
encode_percent,
predicted_encode_time: Duration::from_secs(60),
from_cache: false,
},
)
}

#[test]
fn adjacent_quality_candidate_reports_the_oversized_candidate() {
let lower = sample(30, 96.0, 81.0);
let current = sample(31, 94.0, 50.0);
let decision = SearchDecision {
min_score: 95.0,
higher_tolerance: 1.0,
thorough: false,
cut_on_iter2: false,
run: 2,
min_q: 5,
max_q: 70,
use_xpsnr: false,
max_encoded_percent: MaxEncodedPercent::new(80.0).expect("valid percentage"),
};

let error = decide_next_transition(&current, 94.0, &[lower], decision)
.expect_err("the quality candidate exceeds the size limit");

assert!(matches!(
error,
Error::NoGoodCrf { last } if last.enc.encode_percent == 81.0
));
}
}
Loading