Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive extra splits #584

Merged
merged 5 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ With your own parameters:

-s --scenes File to save/read scenes.

-x --extra-split Size of chunk after which it will be split [default: 240]
-x --extra-split Size of chunk after which it will be split [default: fps * 10]

--min-scene-len Specifies the minimum number of frames in each split.

Expand Down
26 changes: 15 additions & 11 deletions av1an-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,8 @@ pub struct CliOpts {
/// When a scenecut is found whose distance to the previous scenecut is greater than the value
/// specified by this option, one or more extra splits (scenecuts) are added. Set this option
/// to 0 to disable adding extra splits.
#[clap(
short = 'x',
long,
default_value_t = 240,
help_heading = "SCENE DETECTION"
)]
pub extra_split: usize,
#[clap(short = 'x', long, help_heading = "SCENE DETECTION")]
pub extra_split: Option<usize>,

/// Minimum number of frames for a scenecut
#[clap(long, default_value_t = 24, help_heading = "SCENE DETECTION")]
Expand Down Expand Up @@ -514,10 +509,19 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<EncodeArgs> {
chunk_order: args.chunk_order,
concat: args.concat,
encoder: args.encoder,
extra_splits_len: if args.extra_split > 0 {
Some(args.extra_split)
} else {
None
extra_splits_len: match args.extra_split {
Some(x) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written with less lines like this:

match args.extra_split {
  Some(0) => None,
  Some(x) => Some(x),
  None => { /* rest of the code */ }
}

if x > 0 {
Some(x)
} else {
None
}
}
// Make sure it's at least 10 seconds
None => match input.frame_rate() {
Ok(fps) => Some((fps * 10.0) as usize),
Err(_) => Some(240_usize),
},
},
photon_noise: args.photon_noise,
sc_pix_format: args.sc_pix_format,
Expand Down