Skip to content

Commit 74cf199

Browse files
committed
Bugfixes for issues introduced during re-factor, and readme update
1 parent c545d2f commit 74cf199

20 files changed

Lines changed: 261 additions & 1347 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ members = [
66
"environment",
77
"ffmpeg",
88
"permutation",
9-
"permutor",
9+
"permutor-cli",
1010
"cli"
1111
]

README.md

Lines changed: 216 additions & 111 deletions
Large diffs are not rendered by default.

docs/benchmark.png

15.8 KB
Loading

engine/src/benchmark_engine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ impl BenchmarkEngine {
2929
for i in 0..self.permutations.clone().len() {
3030
let permutation_start_time = SystemTime::now();
3131
let permutation = self.permutations[i].clone();
32+
// benchmark will not log ETA since every encode will be different
3233
log_benchmark_header(i, &self.permutations, calc_time);
3334
self.results.push(run_encode(permutation, &ctrl_channel));
3435
calc_time = Option::from(permutation_start_time.elapsed().unwrap());
3536
}
3637

3738
// produce output files and other logging here
3839
let runtime_str = format_dhms(runtime.elapsed().unwrap().as_secs());
39-
log_results_to_file(self.results.clone(), &runtime_str, Vec::new(), 0, true);
40+
log_results_to_file(self.results.clone(), &runtime_str, Vec::new(), self.permutations[0].bitrate, true);
4041
println!("Benchmark runtime: {}", runtime_str);
4142
}
4243

engine/src/engine.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,23 @@ pub fn run_encode(mut p: Permutation, ctrl_channel: &Result<Receiver<()>, Error>
4141
return result;
4242
}
4343

44+
pub fn log_permutation_header(index: usize, permutations: &Vec<Permutation>, calc_time: Option<Duration>, ignore_factor: c_float) {
45+
log_header(index, permutations, calc_time, true, ignore_factor);
46+
}
47+
4448
pub fn log_benchmark_header(index: usize, permutations: &Vec<Permutation>, calc_time: Option<Duration>) {
49+
log_header(index, permutations, calc_time, false, 1 as c_float);
50+
}
51+
52+
fn log_header(index: usize, permutations: &Vec<Permutation>, calc_time: Option<Duration>, log_eta: bool, ignore_factor: c_float) {
4553
let mut permutation = permutations[index].clone();
4654
let metadata = permutation.get_metadata();
47-
if calc_time.is_some() {
48-
println!("[ETR: {}]", format_dhms(calculate_eta(calc_time.unwrap(), index, permutations.len(), 1 as c_float)));
49-
} else {
50-
println!("[ETR: Unknown until first permutation is done]");
55+
if log_eta {
56+
if calc_time.is_some() {
57+
println!("[ETR: {}]", format_dhms(calculate_eta(calc_time.unwrap(), index, permutations.len(), ignore_factor)));
58+
} else {
59+
println!("[ETR: Unknown until first permutation is done]");
60+
}
5161
}
5262
println!("[Permutation:\t{}/{}]", index + 1, permutations.len());
5363
println!("[Resolution:\t{}x{}]", metadata.width, metadata.height);

engine/src/permutation_engine.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ffmpeg::args::FfmpegArgs;
1111
use ffmpeg::report_files::{extract_vmaf_score, get_latest_ffmpeg_report_file, read_last_line_at};
1212
use permutation::permutation::Permutation;
1313

14-
use crate::engine::{log_benchmark_header, run_encode, spawn_ffmpeg_child};
14+
use crate::engine::{log_permutation_header, run_encode, spawn_ffmpeg_child};
1515
use crate::progressbar;
1616
use crate::progressbar::draw_yellow_bar;
1717
use crate::result::{log_results_to_file, PermutationResult};
@@ -46,11 +46,20 @@ impl PermutationEngine {
4646
let ctrl_channel = setup_ctrl_channel();
4747
let mut target_quality_found = false;
4848

49+
let mut ignore_factor = 1 as c_float;
4950
let mut calc_time: Option<Duration> = None;
5051
for i in 0..self.permutations.clone().len() {
5152
let permutation_start_time = SystemTime::now();
5253
let mut permutation = self.permutations[i].clone();
53-
log_benchmark_header(i, &self.permutations, calc_time);
54+
log_permutation_header(i, &self.permutations, calc_time, ignore_factor);
55+
56+
// if this permutation was added to the list of duplicates, skip to save calculation time
57+
if will_be_duplicate(&self.dup_results, &permutation) {
58+
draw_yellow_bar(permutation.get_metadata().frames);
59+
println!("\n!!! Above encoder settings will produce identical vmaf score as other permutations, skipping... \n");
60+
continue;
61+
}
62+
5463
let mut result = run_encode(permutation.clone(), &ctrl_channel);
5564
calc_time = Option::from(permutation_start_time.elapsed().unwrap());
5665

@@ -66,28 +75,28 @@ impl PermutationEngine {
6675

6776
// take the vmaf calculation time into account for the total ETA calculation
6877
calc_time = Option::from(permutation_start_time.elapsed().unwrap());
69-
70-
// if this permutation was added to the list of duplicates, skip to save calculation time
71-
if will_be_duplicate(&self.dup_results, &result) {
72-
draw_yellow_bar(permutation.get_metadata().frames);
73-
println!("\n!!! Above encoder settings will produce identical vmaf score as other permutations, skipping... \n");
74-
continue;
75-
}
7678
}
7779

78-
let is_bitrate_permutation_over = i == self.permutations.len() - 1 || self.permutations[i + 1].clone().bitrate != permutation.bitrate;
79-
self.add_result(result, is_bitrate_permutation_over);
80+
let is_initial_bitrate_permutation_over = i == self.permutations.len() - 1 || self.permutations[i + 1].clone().bitrate != permutation.bitrate;
81+
self.add_result(result, is_initial_bitrate_permutation_over);
82+
83+
// we'll calculate the ignore factor of permutations that will be skipped
84+
if is_initial_bitrate_permutation_over {
85+
// % of permutations that we will actually permute over past the initial bitrate
86+
let perm_count = self.results.len() + self.dup_results.len();
87+
ignore_factor = self.results.len() as c_float / perm_count as c_float;
88+
}
8089

8190
// stop if we've found the target quality, and we're done permuting over the current bitrate
82-
if target_quality_found && is_bitrate_permutation_over {
91+
if target_quality_found && is_initial_bitrate_permutation_over {
8392
println!("Found VMAF score >= {}, stopping permutations...", TARGET_QUALITY);
8493
break;
8594
}
8695
}
8796

8897
// produce output files and other logging here
8998
let runtime_str = format_dhms(runtime.elapsed().unwrap().as_secs());
90-
log_results_to_file(self.results.clone(), &runtime_str, Vec::new(), 0, true);
99+
log_results_to_file(self.results.clone(), &runtime_str, self.dup_results.clone(), self.permutations[0].bitrate, false);
91100
println!("Benchmark runtime: {}", runtime_str);
92101
}
93102

@@ -156,9 +165,9 @@ fn check_encode_quality(mut p: Permutation, ctrl_channel: &Result<Receiver<()>,
156165
return vmaf_score;
157166
}
158167

159-
fn will_be_duplicate(duplicates: &Vec<PermutationResult>, result: &PermutationResult) -> bool {
168+
fn will_be_duplicate(duplicates: &Vec<PermutationResult>, next_permutation: &Permutation) -> bool {
160169
for dup in duplicates {
161-
if dup.encoder_settings == result.encoder_settings {
170+
if dup.encoder_settings == next_permutation.encoder_settings {
162171
return true;
163172
}
164173
}

engine/src/result.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ impl PermutationResult {
5555
}
5656
}
5757

58-
pub fn log_results_to_file(results: Vec<PermutationResult>, runtime_str: &String, dup_results: Vec<PermutationResult>, bitrate: u32, is_standard: bool) {
58+
pub fn log_results_to_file(results: Vec<PermutationResult>, runtime_str: &String, dup_results: Vec<PermutationResult>, bitrate: u32, is_benchmark: bool) {
5959
// might make this naming here more robust eventually
6060
let first_metadata = results.get(0).unwrap().metadata;
6161
let encoder = results.get(0).unwrap().encoder.as_str();
6262
let permute_file_name = format!("{}-{}-{}.log", encoder, first_metadata.get_res(), first_metadata.fps).to_string();
6363
let benchmark_file_name = format!("{}-benchmark.log", encoder).to_string();
64-
let file_name = if is_standard { benchmark_file_name } else { permute_file_name };
64+
let file_name = if is_benchmark { benchmark_file_name } else { permute_file_name };
6565

6666
let mut w = File::create(file_name).unwrap();
6767

@@ -74,7 +74,7 @@ pub fn log_results_to_file(results: Vec<PermutationResult>, runtime_str: &String
7474
writeln!(&mut w, "==================================================================================================================================================================").unwrap();
7575
writeln!(&mut w, "Benchmark runtime: {}\n", runtime_str).unwrap();
7676

77-
let has_logged_dup_header = false;
77+
let mut has_logged_dup_header = false;
7878

7979
// log out the duplicated results so we can keep track of them
8080
let initial_perms: Vec<PermutationResult> = results
@@ -98,6 +98,7 @@ pub fn log_results_to_file(results: Vec<PermutationResult>, runtime_str: &String
9898
if !has_logged_dup_header {
9999
writeln!(&mut w, "Encoder settings that produced identical scores:").unwrap();
100100
writeln!(&mut w, "==================================================================================================================================================================").unwrap();
101+
has_logged_dup_header = true;
101102
}
102103

103104
writeln!(&mut w, "Identical score: {}", perm.vmaf_score).unwrap();

0 commit comments

Comments
 (0)