rav1repl.rs 2.18 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 21
  let (mut io, config) = EncoderConfig::from_cli();
  let mut y4m_dec = y4m::decode(&mut io.input).unwrap();
Michael Bebenita's avatar
Michael Bebenita committed
22 23 24
  let width = y4m_dec.get_width();
  let height = y4m_dec.get_height();
  let framerate = y4m_dec.get_framerate();
25 26 27
  let mut y4m_enc = match io.rec.as_mut() {
    Some(rec) =>
      Some(y4m::encode(width, height, framerate).write_header(rec).unwrap()),
Michael Bebenita's avatar
Michael Bebenita committed
28 29
    None => None
  };
30
  let mut fi = FrameInvariants::new(width, height, &config);
Yushin Cho's avatar
Yushin Cho committed
31
  let mut sequence = Sequence::new(width, height);
Michael Bebenita's avatar
Michael Bebenita committed
32
  write_ivf_header(
33
    &mut io.output,
Michael Bebenita's avatar
Michael Bebenita committed
34 35 36 37 38
    fi.padded_w,
    fi.padded_h,
    framerate.num,
    framerate.den
  );
Guillaume Martres's avatar
Guillaume Martres committed
39

Michael Bebenita's avatar
Michael Bebenita committed
40 41 42 43 44 45 46 47 48 49 50
  let mut rl = Editor::<()>::new();
  let _ = rl.load_history(".rav1e-history");
  let mut last_rec: Option<Frame> = None;
  loop {
    let readline = rl.readline(">> ");
    match readline {
      Ok(line) => {
        rl.add_history_entry(&line);
        match line.split_whitespace().next() {
          Some("process_frame") => {
            process_frame(
51
              &mut sequence,
Yushin Cho's avatar
Yushin Cho committed
52
              &mut fi,
53
              &mut io.output,
Michael Bebenita's avatar
Michael Bebenita committed
54
              &mut y4m_dec,
55
              y4m_enc.as_mut()
Michael Bebenita's avatar
Michael Bebenita committed
56 57
            );
            fi.number += 1;
58
            if fi.number == config.limit {
Michael Bebenita's avatar
Michael Bebenita committed
59 60 61 62 63 64 65 66 67
              break;
            }
          }
          Some("quit") => break,
          Some("exit") => break,
          Some(cmd) => {
            println!("Unrecognized command: {:?}", cmd);
          }
          None => {}
Guillaume Martres's avatar
Guillaume Martres committed
68
        }
Michael Bebenita's avatar
Michael Bebenita committed
69 70 71
      }
      Err(ReadlineError::Eof) => break,
      _ => {}
Guillaume Martres's avatar
Guillaume Martres committed
72
    }
Michael Bebenita's avatar
Michael Bebenita committed
73 74
  }
  rl.save_history(".rav1e-history").unwrap();
Guillaume Martres's avatar
Guillaume Martres committed
75
}