rav1repl.rs 1.76 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();
15 16 17 18
    let mut y4m_enc = match files.rec_file.as_mut() {
        Some(rec_file) => Some(y4m::encode(width, height, y4m::Ratio::new(30,1)).write_header(rec_file).unwrap()),
        None => None
    };
19
    let mut fi = FrameInvariants::new(width, height);
Guillaume Martres's avatar
Guillaume Martres committed
20 21 22 23 24
    let sequence = Sequence::new();
    write_ivf_header(&mut files.output_file, fi.sb_width*64, fi.sb_height*64);

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