Skip to content

Commit

Permalink
feat: -help/-h and -version/-v options
Browse files Browse the repository at this point in the history
  • Loading branch information
flazepe committed Oct 28, 2024
1 parent 6c1437e commit 20fb467
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ Combining multiple clips from multiple inputs
clipper -i input1.mp4 -s 2:00-2:30 -s 5:12-5:20 -i input2.mp4 -s 1:15-1:25 -s 7:20-7:27 output.mp4
```

Selecting a video/audio track and burning subtitles from input (these options work per input)
Selecting an audio track from input (these options work per input)

```
clipper -input input.mp4 -video-track 1 -audio-track 1 -subtitle-track 1 -segment 2:00-2:30 -segment 5:12-5:20 output.mp4
clipper -input input.mp4 -vt 1 -at 1 -st 1 -s 2:00-2:30 -s 5:12-5:20 output.mp4
clipper -input input1.mp4 -vt 1 -at 1 -st 1 -s 2:00-2:30 -s 5:12-5:20 -i input2.mp4 -vt 2 -at 2 -st 2 -s 1:15-1:25 -s 7:20-7:27 output.mp4
```

Setting the input's segment speed. This speeds up all segments of the input by the specified multiplier (this option works per input)

```
clipper -i input.mp4 -speed 2 -s 2:00-2:30 -s 5:12-5:20 output.mp4
clipper -i input.mp4 -spd 2 -s 2:00-2:30 -s 5:12-5:20 output.mp4
clipper -input input.mp4 -audio-track 1 -segment 2:00-2:30 -segment 5:12-5:20 output.mp4
clipper -input input.mp4 -at 1 -s 2:00-2:30 -s 5:12-5:20 output.mp4
```

Adding a fade transition between segments with optional duration in seconds (this option applies to all segments, regardless of their inputs)
Expand All @@ -43,17 +34,4 @@ clipper -i input.mp4 -s 2:00-2:30 -s 5:12-5:20 -fade=1 output.mp4
clipper -i input.mp4 -s 2:00-2:30 -s 5:12-5:20 -f=1 output.mp4
```

Setting options for encoder

```
clipper -i input.mp4 -s 2:00-2:30 -preset veryfast -crf 23 output.mp4
clipper -i input.mp4 -s 2:00-2:30 -nvenc -hevc -preset fast -cq 16 output.mp4
```

Additional flags

```
-no-video / -vn: Disables the video track
-no-audio / -an: Disables the audio track
-dry-run / -d : Outputs the ffmpeg command instead of directly running ffmpeg
```
Other options can be found by using the help command (`clipper -help`).
47 changes: 45 additions & 2 deletions src/clipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use crate::{
error,
ffmpeg::{Encoder, Inputs, Output},
};
use std::{env::args, process::Command, vec::IntoIter};
use std::{
env::args,
process::{exit, Command},
vec::IntoIter,
};

pub struct Clipper {
inputs: Inputs,
Expand Down Expand Up @@ -43,7 +47,9 @@ impl Clipper {
"no-video" | "vn" => inputs.set_no_video(true),
"no-audio" | "an" => inputs.set_no_audio(true),
"dry-run" | "d" => dry_run = true,
_ => error!("Invalid option: -{option}"),
"help" | "h" => Self::print_help(),
"version" | "v" => Self::print_version(),
_ => error!("Invalid option: -{option}. Use -help for more information."),
}

continue;
Expand Down Expand Up @@ -107,6 +113,43 @@ impl Clipper {
.and_then(|child| child.wait_with_output());
}
}

fn print_help() {
println!(
r#"A simple ffmpeg wrapper for clipping videos.
Usage: clipper -input <INPUT> -segment <DURATION RANGE> [OPTIONS] <OUTPUT>
Arguments:
<OUTPUT> The output file
Options:
-input, -i <INPUT> Add an input file. This option can be repeated to add more inputs
-video-track, -vt <INDEX> Set the last input's video track
-audio-track, -at <INDEX> Set the last input's audio track
-subtitle-track, -st <INDEX> Burn the last input's subtitle track for all its segments
-speed, -spd <SPEED> Set the speed multiplier for the last input's segments
-segment, -s <DURATION RANGE> Add a segment duration range to the last input (e.g. "-segment 2:00-2:30"). This option can be repeated to add more segments
-fade, -f[=<FADE>] Add a fade transition between all segments. If set (e.g. "-fade=1"), this would be the fade duration in seconds (default: 0.5)
-nvenc Encode with NVENC instead of CPU
-hevc Convert to HEVC/H.265 instead of AVC/H.264
-preset, -p <PRESET> Set the encoder preset
-crf <CRF> Set the CRF for CPU encoder
-cq <CQ> Set the CQ for NVENC encoder
-no-video, -vn Disable the video track for all inputs
-no-audio, -an Disable the audio track for all inputs
-dry-run, -d Output the ffmpeg command instead of directly running ffmpeg
-help, -h Print help
-version, -v Print version"#
);

exit(0);
}

fn print_version() {
println!("v{}", env!("CARGO_PKG_VERSION"));
exit(0);
}
}

impl Default for Clipper {
Expand Down

0 comments on commit 20fb467

Please sign in to comment.