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

move ignore frame mismatch to chunk #794

Merged
merged 1 commit into from
Dec 16, 2023
Merged
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
26 changes: 6 additions & 20 deletions av1an-core/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>,
ignore_frame_mismatch: bool,
) {
pub fn encoding_loop(self, tx: Sender<()>, mut set_thread_affinity: Option<usize>) {
assert!(!self.chunk_queue.is_empty());

if !self.chunk_queue.is_empty() {
Expand Down Expand Up @@ -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();
Expand All @@ -175,12 +170,7 @@ impl<'a> Broker<'a> {
}
}

fn encode_chunk(
&self,
chunk: &mut Chunk,
worker_id: usize,
ignore_frame_mismatch: bool,
) -> Result<(), Box<EncoderCrash>> {
fn encode_chunk(&self, chunk: &mut Chunk, worker_id: usize) -> Result<(), Box<EncoderCrash>> {
let st_time = Instant::now();

if let Some(ref tq) = self.project.args.target_quality {
Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions av1an-core/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Chunk {
/// Optional target quality CQ level
#[serde(rename = "per_shot_target_quality_cq")]
pub tq_cq: Option<u32>,
pub ignore_frame_mismatch: bool,
}

impl Chunk {
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down
15 changes: 6 additions & 9 deletions av1an-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -418,7 +413,6 @@ impl Av1anContext {
current_pass: u8,
worker_id: usize,
padding: usize,
ignore_frame_mismatch: bool,
) -> Result<(), (Box<EncoderCrash>, u64)> {
update_mp_chunk(worker_id, chunk.index, padding);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down