Commit 714c5ca7 authored by Josh Holmer's avatar Josh Holmer Committed by Luca Barbato

Improve CLI progress indicator and print stats after encode

Adds a new `--verbose` flag to display frame-by-frame info similar to
the old behavior.
parent 7862710a
This diff is collapsed.
......@@ -14,18 +14,19 @@ extern crate y4m;
mod common;
use common::*;
use std::io;
use std::io::Write;
use rav1e::*;
fn main() {
let (mut io, enc, limit) = parse_cli();
let mut y4m_dec = y4m::decode(&mut io.input).unwrap();
let mut cli = parse_cli();
let mut y4m_dec = y4m::decode(&mut cli.io.input).unwrap();
let width = y4m_dec.get_width();
let height = y4m_dec.get_height();
let framerate = y4m_dec.get_framerate();
let color_space = y4m_dec.get_colorspace();
let mut count = 0;
let mut y4m_enc = match io.rec.as_mut() {
let mut y4m_enc = match cli.io.rec.as_mut() {
Some(rec) => Some(
y4m::encode(width, height, framerate)
.with_colorspace(color_space)
......@@ -56,31 +57,49 @@ fn main() {
let cfg = Config {
frame_info: FrameInfo { width, height, bit_depth, chroma_sampling },
timebase: Rational::new(framerate.den as u64, framerate.num as u64),
enc
enc: cli.enc
};
let mut ctx = cfg.new_context();
let stderr = io::stderr();
let mut err = stderr.lock();
let _ = writeln!(err, "{}x{} @ {}/{} fps", width, height, framerate.num, framerate.den);
write_ivf_header(
&mut io.output,
&mut cli.io.output,
width,
height,
framerate.num,
framerate.den
);
loop {
if !process_frame(&mut ctx, &mut io.output, &mut y4m_dec, y4m_enc.as_mut())
{
break;
}
let mut progress = ProgressInfo::new(
framerate,
if cli.limit == 0 { None } else { Some(cli.limit) }
);
count += 1;
loop {
match process_frame(&mut ctx, &mut cli.io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Ok(Some(frame_info)) => {
progress.add_frame(frame_info);
let _ = if cli.verbose {
writeln!(err, "{} - {}", frame_info, progress)
} else {
write!(err, "\r{} ", progress)
};
},
Ok(_) => (),
Err(_) => break,
};
if limit != 0 && count >= limit {
if cli.limit != 0 && progress.frames_encoded() >= cli.limit {
break;
}
io.output.flush().unwrap();
cli.io.output.flush().unwrap();
}
let _ = write!(err, "\n{}\n", progress.print_stats());
}
......@@ -76,14 +76,11 @@ fn main() {
rl.add_history_entry(&line);
match line.split_whitespace().next() {
Some("process_frame") => {
if !process_frame(
&mut ctx,
&mut io.output,
&mut y4m_dec,
y4m_enc.as_mut()
) {
break;
}
match process_frame(&mut ctx, &mut io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Ok(Some(frame_info)) => eprintln!("{}", frame_info),
Ok(_) => (),
Err(_) => break,
};
io.output.flush().unwrap();
}
......
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