Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display chunk index instead of worker index in verbose mode #550

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions av1an-core/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use thiserror::Error;
pub struct Broker<'a> {
pub max_tries: usize,
pub chunk_queue: Vec<Chunk>,
pub total_chunks: usize,
pub project: &'a EncodeArgs,
pub target_quality: Option<TargetQuality<'a>>,
}
Expand Down Expand Up @@ -214,9 +215,13 @@ impl<'a> Broker<'a> {
let mut tpl_crash_workaround = false;
for current_pass in 1..=self.project.passes {
for r#try in 1..=self.max_tries {
let res = self
.project
.create_pipes(chunk, current_pass, worker_id, tpl_crash_workaround);
let res = self.project.create_pipes(
chunk,
current_pass,
worker_id,
self.total_chunks,
tpl_crash_workaround,
);
if let Err((e, frames)) = res {
if self.project.verbosity == Verbosity::Normal {
dec_bar(frames);
Expand Down
15 changes: 11 additions & 4 deletions av1an-core/src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,23 @@ pub fn reset_mp_bar_at(pos: u64) {
}
}

pub fn init_multi_progress_bar(len: u64, workers: usize) {
pub fn init_multi_progress_bar(len: u64, workers: usize, total_chunks: usize) {
MULTI_PROGRESS_BAR.get_or_init(|| {
let mpb = MultiProgress::new();

let mut pbs = Vec::new();

let digits = printable_base10_digits(workers) as usize;
let digits = printable_base10_digits(total_chunks) as usize;

for i in 1..=workers {
for _ in 1..=workers {
let pb = ProgressBar::hidden()
// no spinner on windows, so we remove the prefix to line up with the progress bar
.with_style(ProgressStyle::default_spinner().template(if cfg!(windows) {
"{prefix:.dim} {msg}"
} else {
" {prefix:.dim} {msg}"
}));
pb.set_prefix(format!("[Worker {:>digits$}]", i, digits = digits));
pb.set_prefix(format!("[Idle {:width$}]", width = digits));
pbs.push(mpb.add(pb));
}

Expand All @@ -180,6 +180,13 @@ pub fn init_multi_progress_bar(len: u64, workers: usize) {
});
}

pub fn update_mp_chunk(worker_idx: usize, chunk: usize, total_chunks: usize) {
let digits = printable_base10_digits(total_chunks) as usize;
if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
pbs[worker_idx].set_prefix(format!("[Chunk {:>digits$}]", chunk, digits = digits));
}
}

pub fn update_mp_msg(worker_idx: usize, msg: String) {
if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
pbs[worker_idx].set_message(msg);
Expand Down
8 changes: 6 additions & 2 deletions av1an-core/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::grain::create_film_grain_file;
use crate::parse::valid_params;
use crate::progress_bar::update_progress_bar_estimates;
use crate::progress_bar::{reset_bar_at, reset_mp_bar_at};
use crate::progress_bar::{update_mp_chunk, update_progress_bar_estimates};
use crate::vapoursynth::{is_ffms2_installed, is_lsmash_installed};
use crate::ChunkOrdering;
use crate::{
Expand Down Expand Up @@ -225,8 +225,11 @@ impl EncodeArgs {
chunk: &Chunk,
current_pass: u8,
worker_id: usize,
total_chunks: usize,
tpl_crash_workaround: bool,
) -> Result<(), (EncoderCrash, u64)> {
update_mp_chunk(worker_id, chunk.index, total_chunks);

let fpf_file = Path::new(&chunk.temp)
.join("split")
.join(format!("{}_fpf", chunk.name()));
Expand Down Expand Up @@ -1164,7 +1167,7 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin
init_progress_bar(self.frames as u64);
reset_bar_at(initial_frames as u64);
} else if self.verbosity == Verbosity::Verbose {
init_multi_progress_bar(self.frames as u64, self.workers);
init_multi_progress_bar(self.frames as u64, self.workers, total_chunks);
reset_mp_bar_at(initial_frames as u64);
}

Expand All @@ -1180,6 +1183,7 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin

let broker = Broker {
chunk_queue,
total_chunks,
project: self,
target_quality: if self.target_quality.is_some() {
Some(TargetQuality::new(self))
Expand Down