From 2f6e0175a5227dd234e03ee9181601c44f485ecc Mon Sep 17 00:00:00 2001 From: Zen Date: Sat, 16 Dec 2023 02:52:12 +0200 Subject: [PATCH] move ignore frame mismatch to chunk --- av1an-core/src/broker.rs | 26 ++++++-------------------- av1an-core/src/chunk.rs | 4 ++++ av1an-core/src/context.rs | 15 ++++++--------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/av1an-core/src/broker.rs b/av1an-core/src/broker.rs index 014cc4bb..7fc2eeca 100644 --- a/av1an-core/src/broker.rs +++ b/av1an-core/src/broker.rs @@ -96,12 +96,7 @@ impl Display for EncoderCrash { impl<'a> Broker<'a> { /// Main encoding loop. set_thread_affinity may be ignored if the value is invalid. - pub fn encoding_loop( - self, - tx: Sender<()>, - mut set_thread_affinity: Option, - ignore_frame_mismatch: bool, - ) { + pub fn encoding_loop(self, tx: Sender<()>, mut set_thread_affinity: Option) { assert!(!self.chunk_queue.is_empty()); if !self.chunk_queue.is_empty() { @@ -154,7 +149,7 @@ impl<'a> Broker<'a> { } while let Ok(mut chunk) = rx.recv() { - if let Err(e) = queue.encode_chunk(&mut chunk, worker_id, ignore_frame_mismatch) { + if let Err(e) = queue.encode_chunk(&mut chunk, worker_id) { error!("[chunk {}] {}", chunk.index, e); tx.send(()).unwrap(); @@ -175,12 +170,7 @@ impl<'a> Broker<'a> { } } - fn encode_chunk( - &self, - chunk: &mut Chunk, - worker_id: usize, - ignore_frame_mismatch: bool, - ) -> Result<(), Box> { + fn encode_chunk(&self, chunk: &mut Chunk, worker_id: usize) -> Result<(), Box> { let st_time = Instant::now(); if let Some(ref tq) = self.project.args.target_quality { @@ -200,13 +190,9 @@ impl<'a> Broker<'a> { let passes = chunk.passes; for current_pass in 1..=passes { for r#try in 1..=self.project.args.max_tries { - let res = self.project.create_pipes( - chunk, - current_pass, - worker_id, - padding, - ignore_frame_mismatch, - ); + let res = self + .project + .create_pipes(chunk, current_pass, worker_id, padding); if let Err((e, frames)) = res { dec_bar(frames); diff --git a/av1an-core/src/chunk.rs b/av1an-core/src/chunk.rs index 63ae10f8..04c306ef 100644 --- a/av1an-core/src/chunk.rs +++ b/av1an-core/src/chunk.rs @@ -27,6 +27,7 @@ pub struct Chunk { /// Optional target quality CQ level #[serde(rename = "per_shot_target_quality_cq")] pub tq_cq: Option, + pub ignore_frame_mismatch: bool, } impl Chunk { @@ -110,6 +111,7 @@ mod tests { video_params: vec![], encoder: Encoder::x264, noise_size: (None, None), + ignore_frame_mismatch: false, }; assert_eq!("00001", ch.name()); } @@ -129,6 +131,7 @@ mod tests { video_params: vec![], encoder: Encoder::x264, noise_size: (None, None), + ignore_frame_mismatch: false, }; assert_eq!("10000", ch.name()); } @@ -149,6 +152,7 @@ mod tests { video_params: vec![], encoder: Encoder::x264, noise_size: (None, None), + ignore_frame_mismatch: false, }; assert_eq!("d/encode/00001.ivf", ch.output()); } diff --git a/av1an-core/src/context.rs b/av1an-core/src/context.rs index e5ad45bd..f7576a97 100644 --- a/av1an-core/src/context.rs +++ b/av1an-core/src/context.rs @@ -35,10 +35,9 @@ use crate::scenes::{Scene, ZoneOptions}; use crate::settings::{EncodeArgs, InputPixelFormat}; use crate::split::{extra_splits, segment, write_scenes_to_file}; use crate::vapoursynth::create_vs_file; -use crate::vmaf; use crate::{ create_dir, determine_workers, get_done, init_done, into_vec, read_chunk_queue, save_chunk_queue, - ChunkMethod, ChunkOrdering, DashMap, DoneJson, Input, SplitMethod, Verbosity, + vmaf, ChunkMethod, ChunkOrdering, DashMap, DoneJson, Input, SplitMethod, Verbosity, }; pub struct Av1anContext { @@ -308,11 +307,7 @@ impl Av1anContext { let (tx, rx) = mpsc::channel(); let handle = s.spawn(|_| { - broker.encoding_loop( - tx, - self.args.set_thread_affinity, - self.args.ignore_frame_mismatch, - ); + broker.encoding_loop(tx, self.args.set_thread_affinity); }); // Queue::encoding_loop only sends a message if there was an error (meaning a chunk crashed) @@ -418,7 +413,6 @@ impl Av1anContext { current_pass: u8, worker_id: usize, padding: usize, - ignore_frame_mismatch: bool, ) -> Result<(), (Box, u64)> { update_mp_chunk(worker_id, chunk.index, padding); @@ -637,7 +631,7 @@ impl Av1anContext { let encoded_frames = num_frames(chunk.output().as_ref()); let err_str = match encoded_frames { - Ok(encoded_frames) if !ignore_frame_mismatch && encoded_frames != chunk.frames() => { + Ok(encoded_frames) if !chunk.ignore_frame_mismatch && encoded_frames != chunk.frames() => { Some(format!( "FRAME MISMATCH: chunk {}: {encoded_frames}/{} (actual/expected frames)", chunk.index, @@ -896,6 +890,7 @@ impl Av1anContext { encoder: self.args.encoder, noise_size: self.args.photon_noise_size, tq_cq: None, + ignore_frame_mismatch: self.args.ignore_frame_mismatch, }; chunk.apply_photon_noise_args( overrides.map_or(self.args.photon_noise, |ovr| ovr.photon_noise), @@ -948,6 +943,7 @@ impl Av1anContext { encoder: self.args.encoder, noise_size: self.args.photon_noise_size, tq_cq: None, + ignore_frame_mismatch: self.args.ignore_frame_mismatch, }; chunk.apply_photon_noise_args( scene @@ -1147,6 +1143,7 @@ impl Av1anContext { encoder: self.args.encoder, noise_size: self.args.photon_noise_size, tq_cq: None, + ignore_frame_mismatch: self.args.ignore_frame_mismatch, }; chunk.apply_photon_noise_args( overrides.map_or(self.args.photon_noise, |ovr| ovr.photon_noise),