Skip to content

Commit

Permalink
refactor: vec of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
flazepe committed Oct 23, 2024
1 parent 2021e2d commit 4d2ef7a
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/clipper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{args::Args, error};
use crate::{args::Args, error, string_vec};
use std::{fmt::Display, process::Command};

pub struct Clipper(Args);
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Clipper {
let mut segment_count = 0;

for (input_index, (input, segments)) in self.0.input.iter().enumerate() {
args.extend_from_slice(&["-i".into(), input.into()]);
args.append(&mut string_vec!["-i", input]);

for segment in segments {
let (from, to) = segment
Expand Down Expand Up @@ -104,40 +104,33 @@ impl Clipper {
));
}

args.extend_from_slice(&["-filter_complex".into(), filters.join(";")]);
args.append(&mut string_vec!["-filter_complex", filters.join(";")]);

if !self.0.no_video {
args.extend_from_slice(&["-map".into(), "[v]".into()]);
args.append(&mut string_vec!["-map", "[v]"]);
}

if !self.0.no_audio {
args.extend_from_slice(&["-map".into(), "[a]".into()]);
args.append(&mut string_vec!["-map", "[a]"]);
}

args
}

fn generate_ffmpeg_encoder_args(&self) -> Vec<String> {
if let Some(cq) = self.0.cq.as_ref() {
vec![
"-c:v".into(),
string_vec![
"-c:v",
if self.0.hevc {
"hevc_nvenc".into()
"hevc_nvenc"
} else {
"h264_nvenc".into()
"h264_nvenc"
},
"-cq".into(),
cq.into(),
"-cq",
cq,
]
} else {
vec![
"-c:v".into(),
if self.0.hevc {
"libx265".into()
} else {
"libx264".into()
},
]
string_vec!["-c:v", if self.0.hevc { "libx265" } else { "libx264" }]
}
}

Expand All @@ -161,6 +154,11 @@ impl Clipper {
}
}

#[macro_export]
macro_rules! string_vec {
($($item:expr),*$(,)?) => (vec![$($item.to_string()),*]);
}

#[macro_export]
macro_rules! error {
($message:expr) => {{
Expand Down

0 comments on commit 4d2ef7a

Please sign in to comment.