rav1repl.rs 1.83 KB
Newer Older
Guillaume Martres's avatar
Guillaume Martres committed
1 2 3 4 5 6 7 8 9 10
extern crate rustyline;
extern crate y4m;

extern crate rav1e;
use rav1e::*;

use rustyline::error::ReadlineError;
use rustyline::Editor;

fn main() {
11
    let mut files = EncoderConfig::from_cli();
Guillaume Martres's avatar
Guillaume Martres committed
12 13 14
    let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
    let width = y4m_dec.get_width();
    let height = y4m_dec.get_height();
Thomas Daede's avatar
Thomas Daede committed
15
    let framerate = y4m_dec.get_framerate();
16
    let mut y4m_enc = match files.rec_file.as_mut() {
Thomas Daede's avatar
Thomas Daede committed
17
        Some(rec_file) => Some(y4m::encode(width, height, framerate).write_header(rec_file).unwrap()),
18 19
        None => None
    };
Thomas Daede's avatar
Thomas Daede committed
20
    let mut fi = FrameInvariants::new(width, height, files.quantizer);
Guillaume Martres's avatar
Guillaume Martres committed
21
    let sequence = Sequence::new();
22
    write_ivf_header(&mut files.output_file, fi.padded_w, fi.padded_h, framerate.num, framerate.den);
Guillaume Martres's avatar
Guillaume Martres committed
23 24 25

    let mut rl = Editor::<()>::new();
    let _ = rl.load_history(".rav1e-history");
26
    let mut last_rec: Option<Frame> = None;
Guillaume Martres's avatar
Guillaume Martres committed
27 28 29 30 31 32 33
    loop {
        let readline = rl.readline(">> ");
        match readline {
            Ok(line) => {
                rl.add_history_entry(&line);
                match line.split_whitespace().next() {
                    Some("process_frame") => {
34
                        process_frame(&sequence, &fi, &mut files.output_file, &mut y4m_dec, y4m_enc.as_mut(), &mut last_rec);
35 36
                        fi.number += 1;
                        if fi.number == files.limit {
37 38
                            break;
                        }
Guillaume Martres's avatar
Guillaume Martres committed
39
                    },
40 41
                    Some("quit") => break,
                    Some("exit") => break,
Guillaume Martres's avatar
Guillaume Martres committed
42 43 44 45 46 47 48 49 50 51 52 53
                    Some(cmd) => {
                        println!("Unrecognized command: {:?}", cmd);
                    },
                    None => {}
                }
            },
            Err(ReadlineError::Eof) => break,
            _ => {}
        }
    }
    rl.save_history(".rav1e-history").unwrap();
}