Skip to content

Commit

Permalink
Add --keep flag to crf-search subcommand (#166)
Browse files Browse the repository at this point in the history
* Add `--keep` flag to `crf-search` subcommand

* Refactor `--keep` into Args::Sample

* Revert keep_temp_files back to default match arm; add documentation of cleaning process

* Add changelog entries

* Update CHANGELOG.md

---------

Co-authored-by: Alex Butler <alexheretic@gmail.com>
  • Loading branch information
t-nil and alexheretic committed Jan 18, 2024
1 parent 4399a14 commit 5f6f0ed
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
* Use a single ffmpeg process to calculate VMAF replacing multi process piping.
* Exclude subtitle tracks from samples.
* Add `--keep` option for _crf-search_ & _auto-encode_.

# v0.7.12
* Improve eta stability.
Expand Down
4 changes: 4 additions & 0 deletions src/command/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub struct Sample {
#[arg(long)]
pub min_samples: Option<u64>,

/// Keep temporary files after exiting.
#[arg(long)]
pub keep: bool,

/// Directory to store temporary sample data in.
/// Defaults to using the input's directory.
#[arg(long, env = "AB_AV1_TEMP_DIR")]
Expand Down
1 change: 0 additions & 1 deletion src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ pub async fn run(
args: args.clone(),
crf: 0.0,
sample: sample.clone(),
keep: false,
cache: *cache,
stdout_format: sample_encode::StdoutFormat::Json,
vmaf: vmaf.clone(),
Expand Down
6 changes: 1 addition & 5 deletions src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ pub struct Args {
#[clap(flatten)]
pub sample: args::Sample,

/// Keep temporary files after exiting.
#[arg(long)]
pub keep: bool,

/// Enable sample-encode caching.
#[arg(
long,
Expand Down Expand Up @@ -87,7 +83,6 @@ pub async fn run(
args,
crf,
sample: sample_args,
keep,
cache,
stdout_format,
vmaf,
Expand All @@ -103,6 +98,7 @@ pub async fn run(
let duration = input_probe.duration.clone()?;
let input_fps = input_probe.fps.clone()?;
let samples = sample_args.sample_count(duration).max(1);
let keep = sample_args.keep;
let temp_dir = sample_args.temp_dir;

let (samples, sample_duration, full_pass) = {
Expand Down
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,24 @@ async fn main() -> anyhow::Result<()> {
_ = signal::ctrl_c() => Err(anyhow!("ctrl_c")),
};

// Final cleanup. Samples are already deleted (if wished by the user) during `command::sample_encode::run`.
temporary::clean(keep).await;

out
}

impl Command {
/// This decides what commands will keep temp files.
///
/// # Important
///
/// Add commands using the sample sub-args here referencing the `keep` flag,
/// or the temp files will be removed anyways.
fn keep_temp_files(&self) -> bool {
match self {
Self::SampleEncode(args) => args.keep,
Self::SampleEncode(args) => args.sample.keep,
Self::CrfSearch(args) => args.sample.keep,
Self::AutoEncode(args) => args.search.sample.keep,
_ => false,
}
}
Expand Down

0 comments on commit 5f6f0ed

Please sign in to comment.