Improve trimming

This commit is contained in:
Michael Campagnaro 2023-08-07 18:55:45 -04:00
parent 19b3701a95
commit 4fb7e6cf37
2 changed files with 32 additions and 6 deletions

View File

@ -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 <filename> <output name> <start time HH:MM:SS> <end time HH:MM:SS>${NORMAL}\n"
if [[ $filename == "" || $output_name == "" || $start_time == "" ]]; then
printf "${BOLD}${RED}Usage: trim-video <filename> <output name> <start time HH:MM:SS> <optional: end time HH:MM:SS, use empty string or 0 for no value>${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"

View File

@ -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 <filename> <output name> <start time HH:MM:SS> <end time HH:MM:SS>${NORMAL}\n"
if [[ $filename == "" || $output_name == "" || $start_time == "" ]]; then
printf "${BOLD}${RED}Usage: trim-video-fast <filename> <output name> <start time HH:MM:SS> <optional: end time HH:MM:SS, use empty string or 0 for no value>${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"