Commit 0b21d2f6 authored by Frank Bossen's avatar Frank Bossen Committed by Thomas Daede

Encode correct number of frames when reordering is enabled

Fixes #722
parent f16cf157
......@@ -190,7 +190,7 @@ impl Config {
aom_dsp_rtcd();
}
Context { fi, seq, frame_count: 0, idx: 0, frame_q: BTreeMap::new(), packet_data: Vec::new() }
Context { fi, seq, frame_count: 0, frames_to_be_coded: 0, idx: 0, frame_q: BTreeMap::new(), packet_data: Vec::new() }
}
}
......@@ -199,6 +199,7 @@ pub struct Context {
seq: Sequence,
// timebase: Rational,
frame_count: u64,
frames_to_be_coded: u64,
idx: u64,
frame_q: BTreeMap<u64, Option<Arc<Frame>>>, // packet_q: VecDeque<Packet>
packet_data: Vec<u8>
......@@ -249,6 +250,18 @@ impl Context {
Ok(())
}
pub fn get_frame_count(&self) -> u64 {
self.frame_count
}
pub fn set_frames_to_be_coded(&mut self, frames_to_be_coded: u64) {
self.frames_to_be_coded = frames_to_be_coded;
}
pub fn needs_more_frames(&self, frame_count: u64) -> bool {
self.frames_to_be_coded == 0 || frame_count < self.frames_to_be_coded
}
pub fn container_sequence_header(&mut self) -> Vec<u8> {
use bitstream_io::*;
use std::io;
......@@ -430,6 +443,11 @@ impl Context {
idx = self.idx;
}
if !self.needs_more_frames(self.fi.number) {
self.idx = self.idx + 1;
return Err(EncoderStatus::EnoughData)
}
if self.fi.show_existing_frame {
self.idx = self.idx + 1;
......
......@@ -171,39 +171,46 @@ pub fn process_frame(
let bit_depth = y4m_dec.get_colorspace().get_bit_depth();
let read_frame =
match y4m_dec.read_frame() {
Ok(y4m_frame) => {
let y4m_y = y4m_frame.get_y_plane();
let y4m_u = y4m_frame.get_u_plane();
let y4m_v = y4m_frame.get_v_plane();
let mut input = ctx.new_frame();
{
let input = Arc::get_mut(&mut input).unwrap();
input.planes[0].copy_from_raw_u8(&y4m_y, width * y4m_bytes, y4m_bytes);
input.planes[1].copy_from_raw_u8(
&y4m_u,
width * y4m_bytes / 2,
y4m_bytes
);
input.planes[2].copy_from_raw_u8(
&y4m_v,
width * y4m_bytes / 2,
y4m_bytes
);
}
if ctx.needs_more_frames(ctx.get_frame_count()) {
match y4m_dec.read_frame() {
Ok(y4m_frame) => {
let y4m_y = y4m_frame.get_y_plane();
let y4m_u = y4m_frame.get_u_plane();
let y4m_v = y4m_frame.get_v_plane();
let mut input = ctx.new_frame();
{
let input = Arc::get_mut(&mut input).unwrap();
input.planes[0].copy_from_raw_u8(&y4m_y, width * y4m_bytes, y4m_bytes);
input.planes[1].copy_from_raw_u8(
&y4m_u,
width * y4m_bytes / 2,
y4m_bytes
);
input.planes[2].copy_from_raw_u8(
&y4m_v,
width * y4m_bytes / 2,
y4m_bytes
);
}
match y4m_bits {
8 | 10 | 12 => {}
_ => panic!("unknown input bit depth!")
}
match y4m_bits {
8 | 10 | 12 => {}
_ => panic!("unknown input bit depth!")
}
let _ = ctx.send_frame(input);
true
}
_ => {
ctx.flush();
false
let _ = ctx.send_frame(input);
true
}
_ => {
let frames_to_be_coded = ctx.get_frame_count();
ctx.set_frames_to_be_coded(frames_to_be_coded);
ctx.flush();
false
}
}
} else {
ctx.flush();
false
};
let mut has_data = true;
......@@ -294,11 +301,7 @@ pub fn process_frame(
_ => { has_data = false; }
}
}
if read_frame {
Ok(frame_summaries)
} else {
Err(())
}
Ok(frame_summaries)
}
#[derive(Debug, Clone)]
......
......@@ -80,6 +80,8 @@ fn main() {
if cli.limit == 0 { None } else { Some(cli.limit) }
);
ctx.set_frames_to_be_coded(cli.limit as u64);
loop {
match process_frame(&mut ctx, &mut cli.io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Ok(frame_info) => {
......@@ -95,7 +97,7 @@ fn main() {
Err(_) => break,
};
if cli.limit != 0 && progress.frames_encoded() >= cli.limit {
if !ctx.needs_more_frames(progress.frames_encoded() as u64) {
break;
}
......
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