Skip to content

Commit

Permalink
Support negative --preset args (#248)
Browse files Browse the repository at this point in the history
* Support negative `--preset` args

* Simplify preset arg type
  • Loading branch information
alexheretic authored Dec 22, 2024
1 parent d75e319 commit 1c17a7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased (0.8.1)
* Support negative `--preset` args.

# v0.8.0
* crf-search: Tweak 2nd iteration logic that slices the crf range at the 25% or 75% crf point.
- Widen to 20%/80% to account for searches of the "middle" two subranges being more optimal.
Expand Down
35 changes: 4 additions & 31 deletions src/command/args/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct Encode {
/// libaom-av1 preset is mapped to equivalent -cpu-used argument.
///
/// [svt-av1 default: 8]
#[arg(long)]
pub preset: Option<Preset>,
#[arg(long, allow_hyphen_values = true)]
pub preset: Option<Arc<str>>,

/// Interval between keyframes. Can be specified as a number of frames, or a duration.
/// E.g. "300" or "10s". Defaults to 10s if the input duration is over 3m.
Expand Down Expand Up @@ -191,8 +191,7 @@ impl Encode {
);

let preset = match &self.preset {
Some(Preset::Number(n)) => Some(n.to_string().into()),
Some(Preset::Name(n)) => Some(n.clone()),
Some(n) => Some(n.clone()),
None if svtav1 => Some("8".into()),
None => None,
};
Expand Down Expand Up @@ -391,32 +390,6 @@ impl std::str::FromStr for Encoder {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Preset {
Number(u8),
Name(Arc<str>),
}

impl fmt::Display for Preset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Number(n) => n.fmt(f),
Self::Name(name) => name.fmt(f),
}
}
}

impl std::str::FromStr for Preset {
type Err = anyhow::Error;

fn from_str(s: &str) -> anyhow::Result<Self> {
match s.parse::<u8>() {
Ok(n) => Ok(Self::Number(n)),
_ => Ok(Self::Name(s.into())),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeyInterval {
Frames(i32),
Expand Down Expand Up @@ -610,7 +583,7 @@ fn svtav1_to_ffmpeg_args_default_under_3m() {
encoder: Encoder("libsvtav1".into()),
input: "vid.mp4".into(),
vfilter: None,
preset: Some(Preset::Number(7)),
preset: Some("7".into()),
pix_format: Some(PixelFormat::Yuv420p),
keyint: None,
scd: None,
Expand Down

0 comments on commit 1c17a7f

Please sign in to comment.