| 1 |
// Copyright (c) 2017-2022, The rav1e contributors. All rights reserved |
| 2 |
// |
| 3 |
// This source code is subject to the terms of the BSD 2 Clause License and |
| 4 |
// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 5 |
// was not distributed with this source code in the LICENSE file, you can |
| 6 |
// obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 7 |
// Media Patent License 1.0 was not distributed with this source code in the |
| 8 |
// PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 9 |
|
| 10 |
mod ivf; |
| 11 |
use self::ivf::IvfMuxer; |
| 12 |
|
| 13 |
mod y4m; |
| 14 |
pub use self::y4m::write_y4m_frame; |
| 15 |
|
| 16 |
use rav1e::prelude::*; |
| 17 |
|
| 18 |
use std::ffi::OsStr; |
| 19 |
use std::io; |
| 20 |
use std::path::Path; |
| 21 |
|
| 22 |
use crate::error::*; |
| 23 |
|
| 24 |
pub trait Muxer: Send { |
| 25 |
fn write_header( |
| 26 |
&mut self, width: usize, height: usize, framerate_num: usize, |
| 27 |
framerate_den: usize, |
| 28 |
); |
| 29 |
|
| 30 |
fn write_frame(&mut self, pts: u64, data: &[u8], frame_type: FrameType); |
| 31 |
|
| 32 |
fn flush(&mut self) -> io::Result<()>; |
| 33 |
} |
| 34 |
|
| 35 |
pub fn create_muxer<P: AsRef<Path>>( |
| 36 |
path: P, overwrite: bool, |
| 37 |
) -> Result<Box<dyn Muxer + Send>, CliError> { |
| 38 |
if !overwrite { |
| 39 |
IvfMuxer::check_file(path.as_ref())?; |
| 40 |
} |
| 41 |
|
| 42 |
if let Some(path) = path.as_ref().to_str() { |
| 43 |
if path == "-" { |
| 44 |
return IvfMuxer::open(path); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
let ext = path |
| 49 |
.as_ref() |
| 50 |
.extension() |
| 51 |
.and_then(OsStr::to_str) |
| 52 |
.map(str::to_lowercase) |
| 53 |
.unwrap_or_else(|| "ivf".into()); |
| 54 |
|
| 55 |
match &ext[..] { |
| 56 |
"ivf" => IvfMuxer::open(path), |
| 57 |
_e => { |
| 58 |
panic!("{ext} is not a supported extension, please change to .ivf"); |
| 59 |
} |
| 60 |
} |
| 61 |
} |