Commit 43317da0 authored by Michael Bebenita's avatar Michael Bebenita Committed by Thomas Daede

Split up EncoderConfig into mutable / immutable structs.

parent 1280decb
......@@ -13,23 +13,22 @@ extern crate y4m;
use rav1e::*;
fn main() {
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let (mut io, config) = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut io.input).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(
y4m::encode(width, height, framerate).write_header(rec_file).unwrap()
),
let mut y4m_enc = match io.rec.as_mut() {
Some(rec) =>
Some(y4m::encode(width, height, framerate).write_header(rec).unwrap()),
None => None
};
let mut fi =
FrameInvariants::new(width, height, files.quantizer, files.speed);
FrameInvariants::new(width, height, config.quantizer, config.speed);
let mut sequence = Sequence::new(width, height);
write_ivf_header(
&mut files.output_file,
&mut io.output,
width,
height,
framerate.num,
......@@ -49,7 +48,7 @@ fn main() {
if !process_frame(
&mut sequence,
&mut fi,
&mut files.output_file,
&mut io.output,
&mut y4m_dec,
y4m_enc.as_mut(),
&mut last_rec
......@@ -58,9 +57,9 @@ fn main() {
}
fi.number += 1;
//fi.show_existing_frame = fi.number % 2 == 1;
if fi.number == files.limit {
if fi.number == config.limit {
break;
}
files.output_file.flush().unwrap();
io.output.flush().unwrap();
}
}
......@@ -17,22 +17,21 @@ use rustyline::error::ReadlineError;
use rustyline::Editor;
fn main() {
let mut files = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
let (mut io, config) = EncoderConfig::from_cli();
let mut y4m_dec = y4m::decode(&mut io.input).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let mut y4m_enc = match files.rec_file.as_mut() {
Some(rec_file) => Some(
y4m::encode(width, height, framerate).write_header(rec_file).unwrap()
),
let mut y4m_enc = match io.rec.as_mut() {
Some(rec) =>
Some(y4m::encode(width, height, framerate).write_header(rec).unwrap()),
None => None
};
let mut fi =
FrameInvariants::new(width, height, files.quantizer, files.speed);
FrameInvariants::new(width, height, config.quantizer, config.speed);
let mut sequence = Sequence::new(width, height);
write_ivf_header(
&mut files.output_file,
&mut io.output,
fi.padded_w,
fi.padded_h,
framerate.num,
......@@ -52,13 +51,13 @@ fn main() {
process_frame(
&mut sequence,
&mut fi,
&mut files.output_file,
&mut io.output,
&mut y4m_dec,
y4m_enc.as_mut(),
&mut last_rec
);
fi.number += 1;
if fi.number == files.limit {
if fi.number == config.limit {
break;
}
}
......
......@@ -394,11 +394,13 @@ impl fmt::Display for FrameType{
}
}
pub struct EncoderIO {
pub input: Box<Read>,
pub output: Box<Write>,
pub rec: Option<Box<Write>>,
}
pub struct EncoderConfig {
pub input_file: Box<Read>,
pub output_file: Box<Write>,
pub rec_file: Option<Box<Write>>,
pub limit: u64,
pub quantizer: usize,
pub speed: usize,
......@@ -406,7 +408,7 @@ pub struct EncoderConfig {
}
impl EncoderConfig {
pub fn from_cli() -> EncoderConfig {
pub fn from_cli() -> (EncoderIO, EncoderConfig) {
let matches = App::new("rav1e")
.version("0.1.0")
.about("AV1 video encoder")
......@@ -448,23 +450,29 @@ impl EncoderConfig {
.case_insensitive(true))
.get_matches();
EncoderConfig {
input_file: match matches.value_of("INPUT").unwrap() {
let io = EncoderIO {
input: match matches.value_of("INPUT").unwrap() {
"-" => Box::new(std::io::stdin()) as Box<Read>,
f => Box::new(File::open(&f).unwrap()) as Box<Read>
},
output_file: match matches.value_of("OUTPUT").unwrap() {
output: match matches.value_of("OUTPUT").unwrap() {
"-" => Box::new(std::io::stdout()) as Box<Write>,
f => Box::new(File::create(&f).unwrap()) as Box<Write>
},
rec_file: matches.value_of("RECONSTRUCTION").map(|f| {
rec: matches.value_of("RECONSTRUCTION").map(|f| {
Box::new(File::create(&f).unwrap()) as Box<Write>
}),
})
};
let config = EncoderConfig {
limit: matches.value_of("LIMIT").unwrap().parse().unwrap(),
quantizer: matches.value_of("QP").unwrap().parse().unwrap(),
speed: matches.value_of("SPEED").unwrap().parse().unwrap(),
tune: matches.value_of("TUNE").unwrap().parse().unwrap()
}
};
(io, config)
}
}
......
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