rav1repl.rs 2.36 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright (c) 2017-2018, The rav1e contributors. All rights reserved
//
// This source code is subject to the terms of the BSD 2 Clause License and
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
// was not distributed with this source code in the LICENSE file, you can
// obtain it at www.aomedia.org/license/software. If the Alliance for Open
// Media Patent License 1.0 was not distributed with this source code in the
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.

Guillaume Martres's avatar
Guillaume Martres committed
10 11 12 13 14 15 16 17 18 19
extern crate rustyline;
extern crate y4m;

extern crate rav1e;
use rav1e::*;

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

fn main() {
20
    let mut files = EncoderConfig::from_cli();
Guillaume Martres's avatar
Guillaume Martres committed
21 22 23
    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
24
    let framerate = y4m_dec.get_framerate();
25
    let mut y4m_enc = match files.rec_file.as_mut() {
Thomas Daede's avatar
Thomas Daede committed
26
        Some(rec_file) => Some(y4m::encode(width, height, framerate).write_header(rec_file).unwrap()),
27 28
        None => None
    };
29
    let mut fi = FrameInvariants::new(width, height, files.quantizer, files.speed);
Guillaume Martres's avatar
Guillaume Martres committed
30
    let sequence = Sequence::new();
31
    write_ivf_header(&mut files.output_file, fi.padded_w, fi.padded_h, framerate.num, framerate.den);
Guillaume Martres's avatar
Guillaume Martres committed
32 33 34

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