rav1e.rs 1.93 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
extern crate rav1e;
extern crate y4m;

use rav1e::*;

fn main() {
Michael Bebenita's avatar
Michael Bebenita committed
16 17 18 19 20 21 22 23 24 25 26
  let mut files = EncoderConfig::from_cli();
  let mut y4m_dec = y4m::decode(&mut files.input_file).unwrap();
  let width = y4m_dec.get_width();
  let height = y4m_dec.get_height();
  let framerate = y4m_dec.get_framerate();
  let mut y4m_enc = match files.rec_file.as_mut() {
    Some(rec_file) => Some(
      y4m::encode(width, height, framerate).write_header(rec_file).unwrap()
    ),
    None => None
  };
27

Michael Bebenita's avatar
Michael Bebenita committed
28 29
  let mut fi =
    FrameInvariants::new(width, height, files.quantizer, files.speed);
Yushin Cho's avatar
Yushin Cho committed
30
  let mut sequence = Sequence::new(width, height);
Michael Bebenita's avatar
Michael Bebenita committed
31 32 33 34 35 36 37
  write_ivf_header(
    &mut files.output_file,
    width,
    height,
    framerate.num,
    framerate.den
  );
Guillaume Martres's avatar
Guillaume Martres committed
38

Michael Bebenita's avatar
Michael Bebenita committed
39 40 41 42 43 44 45 46
  let mut last_rec: Option<Frame> = None;
  loop {
    //fi.frame_type = FrameType::KEY;
    fi.frame_type = if fi.number % 30 == 0 {
      FrameType::KEY
    } else {
      FrameType::INTER
    };
47

Michael Bebenita's avatar
Michael Bebenita committed
48 49 50
    fi.intra_only = fi.frame_type == FrameType::KEY
      || fi.frame_type == FrameType::INTRA_ONLY;
    fi.use_prev_frame_mvs = !(fi.intra_only || fi.error_resilient);
51

Michael Bebenita's avatar
Michael Bebenita committed
52
    if !process_frame(
53
      &mut sequence,
Yushin Cho's avatar
Yushin Cho committed
54
      &mut fi,
Michael Bebenita's avatar
Michael Bebenita committed
55 56 57 58 59 60 61 62 63 64 65
      &mut files.output_file,
      &mut y4m_dec,
      y4m_enc.as_mut(),
      &mut last_rec
    ) {
      break;
    }
    fi.number += 1;
    //fi.show_existing_frame = fi.number % 2 == 1;
    if fi.number == files.limit {
      break;
Guillaume Martres's avatar
Guillaume Martres committed
66
    }
Michael Bebenita's avatar
Michael Bebenita committed
67 68
    files.output_file.flush().unwrap();
  }
Guillaume Martres's avatar
Guillaume Martres committed
69
}