Commit baec5d30 authored by Josh Holmer's avatar Josh Holmer Committed by GitHub

Fix miscalculation of PSNR with frame reordering (#1017)

With frame reordering enabled, every other frame would be compared to a
blank frame, generating a very low PSNR calculation. Also fixes an issue
where the PlaneIter ends one pixel too early, which currently is only
used by PSNR calculation.
parent d78dc363
......@@ -559,6 +559,11 @@ impl Context {
Ok(())
}
pub fn get_frame(&self, frame_number: u64) -> Arc<Frame> {
// Clones only the arc, so low cost overhead
self.frame_q.get(&frame_number).as_ref().unwrap().as_ref().unwrap().clone()
}
pub fn get_frame_count(&self) -> u64 {
self.frame_count
}
......@@ -735,7 +740,7 @@ impl Context {
let rec = if fi.show_frame { Some(fs.rec) } else { None };
let fi = fi.clone();
self.finalize_packet(&*fs.input, rec, &fi)
self.finalize_packet(rec, &fi)
} else {
if let Some(f) = self.frame_q.get(&fi.number) {
self.idx += 1;
......@@ -769,7 +774,7 @@ impl Context {
if fi.show_frame {
let fi = fi.clone();
self.finalize_packet(&*frame, rec, &fi)
self.finalize_packet(rec, &fi)
} else {
Err(EncoderStatus::NeedMoreData)
}
......@@ -789,7 +794,7 @@ impl Context {
ret
}
fn finalize_packet(&mut self, original_frame: &Frame, rec: Option<Frame>, fi: &FrameInvariants) -> Result<Packet, EncoderStatus> {
fn finalize_packet(&mut self, rec: Option<Frame>, fi: &FrameInvariants) -> Result<Packet, EncoderStatus> {
let data = self.packet_data.clone();
self.packet_data.clear();
if write_temporal_delimiter(&mut self.packet_data).is_err() {
......@@ -799,6 +804,7 @@ impl Context {
let mut psnr = None;
if self.config.enc.show_psnr {
if let Some(ref rec) = rec {
let original_frame = self.get_frame(fi.number);
psnr = Some(calculate_frame_psnr(
&*original_frame,
rec,
......
......@@ -245,7 +245,7 @@ impl<'a> Iterator for PlaneIter<'a> {
type Item = u16;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
if self.y == self.height() - 1 && self.x == self.width() - 1 {
if self.y == self.height() {
return None;
}
let pixel = self.plane.p(self.x, self.y);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment