From 4fb7e6cf37bd7d8f3b9578ab0beaf5aa7e52aa40 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Mon, 7 Aug 2023 18:55:45 -0400 Subject: [PATCH] Improve trimming --- dotfiles/bin/trim-video | 19 ++++++++++++++++--- dotfiles/bin/trim-video-fast | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/dotfiles/bin/trim-video b/dotfiles/bin/trim-video index e82ed65..7bad89d 100644 --- a/dotfiles/bin/trim-video +++ b/dotfiles/bin/trim-video @@ -30,15 +30,28 @@ output_name="$2" start_time="$3" end_time="$4" -if [[ $filename == "" || $output_name == "" || $start_time == "" || $end_time == "" ]]; then - printf "${BOLD}${RED}Usage: trim-video ${NORMAL}\n" +if [[ $filename == "" || $output_name == "" || $start_time == "" ]]; then + printf "${BOLD}${RED}Usage: trim-video ${NORMAL}\n" exit 1 fi extension="${filename##*.}" filename="${filename%.*}" output="${output_name}.$extension" -timing_args="-ss $start_time -to $end_time" + +timing_args="" +if [[ $start_time != "" ]]; then + timing_args="-ss $start_time " +fi +if [[ $end_time != "" ]]; then + if [[ $start_time == "0" && $end_time == "0" ]]; then + # We treat a start and end with 0 values as no op. + timing_args="" + elif [[ $end_time != "0" ]]; then + # Handle having a start time but end time is set to 0, can just ignore it and it'll use the remainder of the video. + timing_args+="-to $end_time" + fi +fi printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n" diff --git a/dotfiles/bin/trim-video-fast b/dotfiles/bin/trim-video-fast index 17b5e96..2d0f416 100644 --- a/dotfiles/bin/trim-video-fast +++ b/dotfiles/bin/trim-video-fast @@ -33,15 +33,28 @@ output_name="$2" start_time="$3" end_time="$4" -if [[ $filename == "" || $output_name == "" || $start_time == "" || $end_time == "" ]]; then - printf "${BOLD}${RED}Usage: trim-video-fast ${NORMAL}\n" +if [[ $filename == "" || $output_name == "" || $start_time == "" ]]; then + printf "${BOLD}${RED}Usage: trim-video-fast ${NORMAL}\n" exit 1 fi extension="${filename##*.}" filename="${filename%.*}" output="${output_name}.$extension" -timing_args="-ss $start_time -to $end_time" + +timing_args="" +if [[ $start_time != "" ]]; then + timing_args="-ss $start_time " +fi +if [[ $end_time != "" ]]; then + if [[ $start_time == "0" && $end_time == "0" ]]; then + # We treat a start and end with 0 values as no op. + timing_args="" + elif [[ $end_time != "0" ]]; then + # Handle having a start time but end time is set to 0, can just ignore it and it'll use the remainder of the video. + timing_args+="-to $end_time" + fi +fi printf "\n${YELLOW}${BOLD}Trimming '$filename.$extension' | output: $output | start: $start_time | end: $end_time${NORMAL}\n"