Skip to content

Commit

Permalink
Update to clap 4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic committed Sep 28, 2022
1 parent 0727373 commit 0d16cc1
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 84 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased
# Unreleased (v0.4.3)
* Leave incomplete progress bars when exitting early with _ctrl c_ instead of clearing them.
* Update to clap v4 which updates help/about output.

# v0.4.2
* Update _indicatif_ dependency to `0.17`.
Expand Down
96 changes: 57 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ab-av1"
version = "0.4.2"
version = "0.4.3"
authors = ["Alex Butler <[email protected]>"]
edition = "2021"
description = "AV1 encoding with fast VMAF sampling"
Expand All @@ -11,8 +11,8 @@ readme = "README.md"

[dependencies]
anyhow = "1.0.53"
clap = { version = "3.2", features = ["derive", "env"] }
clap_complete = "3.2"
clap = { version = "4", features = ["derive", "env", "help", "usage", "error-context", "wrap_help"] }
clap_complete = "4"
console = "0.15"
ffprobe = "0.3"
futures = "0.3.19"
Expand Down
12 changes: 6 additions & 6 deletions src/command/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ pub struct EncodeToOutput {
/// Output file, by default the same as input with `.av1` before the extension.
///
/// E.g. if unspecified: -i vid.mp4 --> vid.av1.mp4
#[clap(short, long, value_parser)]
#[arg(short, long)]
pub output: Option<PathBuf>,

/// Set the output ffmpeg audio codec.
/// By default when the input & output file extension match 'copy' is used,
/// otherwise 'libopus'.
///
/// See https://ffmpeg.org/ffmpeg.html#Audio-Options.
#[clap(long = "acodec", value_parser)]
#[arg(long = "acodec")]
pub audio_codec: Option<String>,

/// Downmix input audio streams to stereo if input streams use greater than
/// 3 channels.
///
/// No effect if the input audio has 3 or fewer channels.
#[clap(long, value_parser)]
#[arg(long)]
pub downmix_to_stereo: bool,
}

Expand All @@ -38,20 +38,20 @@ pub struct EncodeToOutput {
pub struct Sample {
/// Number of 20s samples to use across the input video. Overrides --sample-every.
/// More samples take longer but may provide a more accurate result.
#[clap(long, value_parser)]
#[arg(long)]
pub samples: Option<u64>,

/// Calculate number of samples by dividing the input duration by this value.
/// So "12m" would mean with an input 25-36 minutes long, 3 samples would be used.
/// More samples take longer but may provide a more accurate result.
///
/// Setting --samples overrides this value.
#[clap(long, default_value = "12m", value_parser = humantime::parse_duration)]
#[arg(long, default_value = "12m", value_parser = humantime::parse_duration)]
pub sample_every: Duration,

/// Directory to store temporary sample data in.
/// Defaults to using the input's directory.
#[clap(long, env = "AB_AV1_TEMP_DIR", value_parser)]
#[arg(long, env = "AB_AV1_TEMP_DIR")]
pub temp_dir: Option<PathBuf>,
}

Expand Down
22 changes: 11 additions & 11 deletions src/command/args/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ pub struct Encode {
/// Encoder override. See https://ffmpeg.org/ffmpeg-all.html#toc-Video-Encoders.
///
/// [possible values: svt-av1, libx264, libx265, libvpx-vp9, ...]
#[clap(arg_enum, short, long, value_parser, default_value = "svt-av1")]
#[arg(value_enum, short, long, default_value = "svt-av1")]
pub encoder: Encoder,

/// Input video file.
#[clap(short, long, value_parser)]
#[arg(short, long)]
pub input: PathBuf,

/// Ffmpeg video filter applied to the input before av1 encoding.
/// E.g. --vfilter "scale=1280:-1,fps=24".
///
/// See https://ffmpeg.org/ffmpeg-filters.html#Video-Filters
#[clap(long, value_parser)]
#[arg(long)]
pub vfilter: Option<String>,

/// Pixel format. svt-av1 default yuv420p10le.
#[clap(arg_enum, long, value_parser)]
#[arg(value_enum, long)]
pub pix_format: Option<PixelFormat>,

/// Encoder preset (0-13).
Expand All @@ -44,7 +44,7 @@ pub struct Encode {
/// libaom-av1 preset is mapped to equivalent -cpu-used argument.
///
/// [svt-av1 default: 8]
#[clap(long, value_parser)]
#[arg(long)]
pub preset: Option<Preset>,

/// Interval between keyframes. Can be specified as a number of frames, or a duration.
Expand All @@ -54,33 +54,33 @@ pub struct Encode {
/// Durations will be converted to frames using the input fps.
///
/// Works on svt-av1 & most ffmpeg encoders set with --encoder.
#[clap(long, value_parser)]
#[arg(long)]
pub keyint: Option<KeyInterval>,

/// Svt-av1 scene change detection, inserts keyframes at scene changes.
/// Defaults on if using default keyint & the input duration is over 3m. Otherwise off.
#[clap(long, value_parser)]
#[arg(long)]
pub scd: Option<bool>,

/// Additional svt-av1 arg(s). E.g. --svt mbr=2000 --svt film-grain=30
///
/// See https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/svt-av1_encoder_user_guide.md#options
#[clap(long = "svt", value_parser = parse_svt_arg)]
#[arg(long = "svt", value_parser = parse_svt_arg)]
pub svt_args: Vec<Arc<str>>,

/// Additional ffmpeg encoder arg(s). E.g. `--enc x265-params=lossless=1`
/// These are added as ffmpeg output file options.
///
/// The first '=' symbol will be used to infer that this is an option with a value.
/// Passed to ffmpeg like "x265-params=lossless=1" -> ['-x265-params', 'lossless=1']
#[clap(long = "enc", allow_hyphen_values = true, value_parser = parse_enc_arg)]
#[arg(long = "enc", allow_hyphen_values = true, value_parser = parse_enc_arg)]
pub enc_args: Vec<String>,

/// Additional ffmpeg input encoder arg(s). E.g. `--enc-input r=1`
/// These are added as ffmpeg input file options.
///
/// See --enc docs.
#[clap(long = "enc-input", allow_hyphen_values = true, value_parser = parse_enc_arg)]
#[arg(long = "enc-input", allow_hyphen_values = true, value_parser = parse_enc_arg)]
pub enc_input_args: Vec<String>,
}

Expand Down Expand Up @@ -455,7 +455,7 @@ impl std::str::FromStr for KeyInterval {
}
}

#[derive(clap::ArgEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[derive(clap::ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[clap(rename_all = "lower")]
pub enum PixelFormat {
Yuv420p10le,
Expand Down
4 changes: 2 additions & 2 deletions src/command/args/vmaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Vmaf {
/// Additional vmaf arg(s). E.g. --vmaf n_threads=8 --vmaf n_subsample=4
///
/// See https://ffmpeg.org/ffmpeg-filters.html#libvmaf.
#[clap(long = "vmaf", value_parser = parse_vmaf_arg)]
#[arg(long = "vmaf", value_parser = parse_vmaf_arg)]
pub vmaf_args: Vec<Arc<str>>,

/// Video resolution scale to use in VMAF analysis. If set, video streams will be bicupic
Expand All @@ -23,7 +23,7 @@ pub struct Vmaf {
/// are less than 3456 & 1944 respectively upscale to 4k. Otherwise no scaling.
///
/// Scaling happens after any input/reference vfilters.
#[clap(long, default_value_t = VmafScale::Auto, value_parser = parse_vmaf_scale)]
#[arg(long, default_value_t = VmafScale::Auto, value_parser = parse_vmaf_scale)]
pub vmaf_scale: VmafScale,
}

Expand Down
Loading

0 comments on commit 0d16cc1

Please sign in to comment.