-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #232
- Loading branch information
Showing
8 changed files
with
204 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use clap::{Args, ValueHint}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct RemoveArgs { | ||
#[arg( | ||
id = "input", | ||
help = "Sets the input HEVC file to use, or piped with -", | ||
long, | ||
short = 'i', | ||
conflicts_with = "input_pos", | ||
required_unless_present = "input_pos", | ||
value_hint = ValueHint::FilePath, | ||
)] | ||
pub input: Option<PathBuf>, | ||
|
||
#[arg( | ||
id = "input_pos", | ||
help = "Sets the input HEVC file to use, or piped with - (positional)", | ||
conflicts_with = "input", | ||
required_unless_present = "input", | ||
value_hint = ValueHint::FilePath | ||
)] | ||
pub input_pos: Option<PathBuf>, | ||
|
||
#[arg( | ||
long, | ||
short = 'o', | ||
help = "Base layer output file location", | ||
value_hint = ValueHint::FilePath | ||
)] | ||
pub output: Option<PathBuf>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use anyhow::{bail, Result}; | ||
use indicatif::ProgressBar; | ||
use std::path::PathBuf; | ||
|
||
use crate::commands::RemoveArgs; | ||
|
||
use super::{general_read_write, input_from_either, CliOptions, IoFormat}; | ||
|
||
use general_read_write::{DoviProcessor, DoviWriter}; | ||
|
||
pub struct Remover { | ||
format: IoFormat, | ||
input: PathBuf, | ||
output: PathBuf, | ||
} | ||
|
||
impl Remover { | ||
pub fn from_args(args: RemoveArgs) -> Result<Self> { | ||
let RemoveArgs { | ||
input, | ||
input_pos, | ||
output, | ||
} = args; | ||
|
||
let input = input_from_either("remove", input, input_pos)?; | ||
let format = hevc_parser::io::format_from_path(&input)?; | ||
|
||
let output = output.unwrap_or(PathBuf::from("BL.hevc")); | ||
|
||
Ok(Self { | ||
format, | ||
input, | ||
output, | ||
}) | ||
} | ||
|
||
pub fn remove(args: RemoveArgs, options: CliOptions) -> Result<()> { | ||
let remover = Remover::from_args(args)?; | ||
remover.process_input(options) | ||
} | ||
|
||
fn process_input(&self, options: CliOptions) -> Result<()> { | ||
let pb = super::initialize_progress_bar(&self.format, &self.input)?; | ||
|
||
match self.format { | ||
IoFormat::Matroska => bail!("Remover: Matroska input is unsupported"), | ||
_ => self.remove_from_raw_hevc(pb, options), | ||
} | ||
} | ||
|
||
fn remove_from_raw_hevc(&self, pb: ProgressBar, options: CliOptions) -> Result<()> { | ||
let bl_out = Some(self.output.as_path()); | ||
|
||
let dovi_writer = DoviWriter::new(bl_out, None, None, None); | ||
let mut dovi_processor = DoviProcessor::new(options, self.input.clone(), dovi_writer, pb); | ||
|
||
dovi_processor.read_write_from_io(&self.format) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ mod demux; | |
mod extract_rpu; | ||
mod inject_rpu; | ||
mod mux; | ||
mod remove; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use assert_cmd::Command; | ||
use assert_fs::prelude::*; | ||
use predicates::prelude::*; | ||
|
||
const SUBCOMMAND: &str = "remove"; | ||
|
||
#[test] | ||
fn help() -> Result<()> { | ||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; | ||
let assert = cmd.arg(SUBCOMMAND).arg("--help").assert(); | ||
|
||
assert | ||
.success() | ||
.stderr(predicate::str::is_empty()) | ||
.stdout(predicate::str::contains( | ||
"dovi_tool remove [OPTIONS] [input_pos]", | ||
)); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn remove() -> Result<()> { | ||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; | ||
let temp = assert_fs::TempDir::new().unwrap(); | ||
|
||
let input_file = Path::new("assets/hevc_tests/regular_start_code_4_muxed_el.hevc"); | ||
let expected_bl = Path::new("assets/hevc_tests/regular_bl_start_code_4.hevc"); | ||
|
||
let output_bl = temp.child("BL.hevc"); | ||
|
||
let assert = cmd | ||
.arg(SUBCOMMAND) | ||
.arg(input_file) | ||
.arg("--output") | ||
.arg(output_bl.as_ref()) | ||
.assert(); | ||
|
||
assert.success().stderr(predicate::str::is_empty()); | ||
|
||
output_bl | ||
.assert(predicate::path::is_file()) | ||
.assert(predicate::path::eq_file(expected_bl)); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn annexb() -> Result<()> { | ||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME"))?; | ||
let temp = assert_fs::TempDir::new().unwrap(); | ||
|
||
let input_file = Path::new("assets/hevc_tests/regular_start_code_4_muxed_el.hevc"); | ||
let expected_bl = Path::new("assets/hevc_tests/regular_demux_bl_annexb.hevc"); | ||
|
||
let output_bl = temp.child("BL.hevc"); | ||
|
||
let assert = cmd | ||
.arg("--start-code") | ||
.arg("annex-b") | ||
.arg(SUBCOMMAND) | ||
.arg(input_file) | ||
.arg("--output") | ||
.arg(output_bl.as_ref()) | ||
.assert(); | ||
|
||
assert.success().stderr(predicate::str::is_empty()); | ||
|
||
output_bl | ||
.assert(predicate::path::is_file()) | ||
.assert(predicate::path::eq_file(expected_bl)); | ||
|
||
Ok(()) | ||
} |