diff --git a/README.md b/README.md index 67d3516..64f28ea 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`). diff --git a/src/clipper.rs b/src/clipper.rs index 7065e95..b25f5d8 100644 --- a/src/clipper.rs +++ b/src/clipper.rs @@ -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, @@ -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; @@ -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 -segment [OPTIONS] + +Arguments: + The output file + +Options: +-input, -i Add an input file. This option can be repeated to add more inputs +-video-track, -vt Set the last input's video track +-audio-track, -at Set the last input's audio track +-subtitle-track, -st Burn the last input's subtitle track for all its segments +-speed, -spd Set the speed multiplier for the last input's segments +-segment, -s 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[=] 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 Set the encoder preset +-crf Set the CRF for CPU encoder +-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 {