Skip to content

Commit

Permalink
Remove extra quotes and spaces from custom args
Browse files Browse the repository at this point in the history
  • Loading branch information
redzic committed Jul 7, 2022
1 parent 440fef2 commit f3051f4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions av1an-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ pub(crate) fn resolve_file_paths(path: &Path) -> anyhow::Result<Box<dyn Iterator
}
}

/// Remove extra quotes and spaces from the beginning and end of string if present.
fn remove_extra_chars(s: &str) -> &str {
s.trim_matches(|c: char| c.is_ascii_whitespace() || c == '"' || c == '\'')
}

/// Returns vector of Encode args ready to be fed to encoder
pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
let input_paths = &*args.input;
Expand Down Expand Up @@ -557,7 +562,8 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
Path::new(&temp).join("log.log")
},
ffmpeg_filter_args: if let Some(args) = args.ffmpeg_filter_args.as_ref() {
shlex::split(args).ok_or_else(|| anyhow!("Failed to split ffmpeg filter arguments"))?
shlex::split(remove_extra_chars(args))
.ok_or_else(|| anyhow!("Failed to split ffmpeg filter arguments"))?
} else {
Vec::new()
},
Expand All @@ -569,7 +575,8 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
args.encoder.get_default_pass()
},
video_params: if let Some(args) = args.video_params.as_ref() {
shlex::split(args).ok_or_else(|| anyhow!("Failed to split video encoder arguments"))?
shlex::split(remove_extra_chars(args))
.ok_or_else(|| anyhow!("Failed to split video encoder arguments"))?
} else {
Vec::new()
},
Expand All @@ -595,7 +602,7 @@ pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
)
},
audio_params: if let Some(args) = args.audio_params.as_ref() {
shlex::split(args)
shlex::split(remove_extra_chars(args))
.ok_or_else(|| anyhow!("Failed to split ffmpeg audio encoder arguments"))?
} else {
into_vec!["-c:a", "copy"]
Expand Down

0 comments on commit f3051f4

Please sign in to comment.