rav1repl.rs 2.5 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.

10
extern crate clap;
Guillaume Martres's avatar
Guillaume Martres committed
11 12 13
extern crate rustyline;
extern crate y4m;
extern crate rav1e;
14 15 16

mod common;

Raphaël Zumer's avatar
Raphaël Zumer committed
17
use common::*;
Guillaume Martres's avatar
Guillaume Martres committed
18 19 20 21 22 23
use rav1e::*;

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

fn main() {
Romain Vimont's avatar
Romain Vimont committed
24
  let CliOptions{mut io, enc, ..} = parse_cli();
25
  let mut y4m_dec = y4m::decode(&mut io.input).unwrap();
Michael Bebenita's avatar
Michael Bebenita committed
26 27 28
  let width = y4m_dec.get_width();
  let height = y4m_dec.get_height();
  let framerate = y4m_dec.get_framerate();
Luca Barbato's avatar
Luca Barbato committed
29 30
  let color_space = y4m_dec.get_colorspace();

31 32 33
  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
34 35 36
    None => None
  };
  write_ivf_header(
37
    &mut io.output,
Luca Barbato's avatar
Luca Barbato committed
38 39
    width,
    height,
Michael Bebenita's avatar
Michael Bebenita committed
40 41 42
    framerate.num,
    framerate.den
  );
Guillaume Martres's avatar
Guillaume Martres committed
43

44
  let (chroma_sampling, chroma_sample_position) = map_y4m_color_space(color_space);
Luca Barbato's avatar
Luca Barbato committed
45 46
  let bit_depth = color_space.get_bit_depth();

Kyle Siefring's avatar
Kyle Siefring committed
47
  let cfg = Config {
48
    frame_info: FrameInfo { width, height, bit_depth, chroma_sampling, chroma_sample_position },
Luca Barbato's avatar
Luca Barbato committed
49
    timebase: Rational::new(framerate.den as u64, framerate.num as u64),
Kyle Siefring's avatar
Kyle Siefring committed
50 51
    enc
  };
Luca Barbato's avatar
Luca Barbato committed
52 53
  let mut ctx = cfg.new_context();

Michael Bebenita's avatar
Michael Bebenita committed
54 55 56 57 58 59 60 61 62 63
  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") => {
64
            match process_frame(&mut ctx, &mut io.output, &mut y4m_dec, y4m_enc.as_mut()) {
Romain Vimont's avatar
Romain Vimont committed
65
              Ok(frame_info) => frame_info.iter().for_each(|frame| eprintln!("{}", frame)),
66 67
              Err(_) => break,
            };
Luca Barbato's avatar
Luca Barbato committed
68 69

            io.output.flush().unwrap();
Michael Bebenita's avatar
Michael Bebenita committed
70 71 72 73 74 75 76
          }
          Some("quit") => break,
          Some("exit") => break,
          Some(cmd) => {
            println!("Unrecognized command: {:?}", cmd);
          }
          None => {}
Guillaume Martres's avatar
Guillaume Martres committed
77
        }
Michael Bebenita's avatar
Michael Bebenita committed
78 79 80
      }
      Err(ReadlineError::Eof) => break,
      _ => {}
Guillaume Martres's avatar
Guillaume Martres committed
81
    }
Michael Bebenita's avatar
Michael Bebenita committed
82 83
  }
  rl.save_history(".rav1e-history").unwrap();
Guillaume Martres's avatar
Guillaume Martres committed
84
}