From 0a7bb3c2a12ef1de6eaada2b13c71ff2f1fcddb5 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Wed, 28 Dec 2022 00:46:37 -0500 Subject: [PATCH] Improve the compress video scripts --- bin/compress-video | 17 +++++++++----- bin/compress-video-and-trim | 44 ------------------------------------- bin/compress-video-with-crf | 30 ++++++++++++++++++------- 3 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 bin/compress-video-and-trim diff --git a/bin/compress-video b/bin/compress-video index ba309b5..2e0eb98 100644 --- a/bin/compress-video +++ b/bin/compress-video @@ -23,20 +23,25 @@ else NORMAL="" fi -use_gpu=$1 -filename=$(basename -- "$2") -output_name="$3" +use_gpu=0 -if [[ $use_gpu == "" || $2 == "" || $output_name == "" ]]; then - printf "${BOLD}${RED}Usage: $0 ${NORMAL}\n" +if [[ $# < 2 || $# > 3 ]]; then + printf "${BOLD}${RED}Usage: $0 ${NORMAL}\n" exit 1 fi +filename=$(basename -- "$1") +output_name="$2" + +if [[ $# > 2 ]]; then + use_gpu=$3 +fi + # Found the following to work best with vids containing text (e.g. programming vid): 25 for CPU encoding and 27 for GPU. use_crf=21 if [[ $use_gpu -eq 1 ]]; then use_crf=25 fi -compress-video-with-crf $use_gpu $use_crf "$filename" "$output_name" +compress-video-with-crf $use_crf "$filename" "$output_name" $use_gpu diff --git a/bin/compress-video-and-trim b/bin/compress-video-and-trim deleted file mode 100644 index 8105a65..0000000 --- a/bin/compress-video-and-trim +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) -fi -if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then - RED="$(tput setaf 1)" - GREEN="$(tput setaf 2)" - YELLOW="$(tput setaf 3)" - BLUE="$(tput setaf 4)" - MAGENTA="$(tput setaf 5)" - CYAN="$(tput setaf 6)" - BOLD="$(tput bold)" - NORMAL="$(tput sgr0)" -else - RED="" - GREEN="" - YELLOW="" - BLUE="" - MAGENTA="" - CYAN="" - BOLD="" - NORMAL="" -fi - -use_gpu=$1 -filename=$(basename -- "$2") -output_name="$3" -start_time="$4" -end_time="$5" - -if [[ $use_gpu == "" || $2 == "" || $output_name == "" || $start_time == "" || $end_time == "" ]]; then - printf "${BOLD}${RED}Usage: $0 ${NORMAL}\n" - exit 1 -fi - -# Found the following to work best with vids containing text (e.g. programming vid): 25 for CPU encoding and 27 for GPU. -use_crf=25 -if [[ $use_gpu -eq 1 ]]; then - use_crf=27 -fi - -compress-video-with-crf $use_gpu $use_crf "$filename" "$output_name" "$start_time" "$end_time" - diff --git a/bin/compress-video-with-crf b/bin/compress-video-with-crf index 7fe9490..4f505c0 100644 --- a/bin/compress-video-with-crf +++ b/bin/compress-video-with-crf @@ -23,22 +23,36 @@ else NORMAL="" fi -use_gpu=$1 -use_crf=$2 -output_name="$4" -start_time="$5" -end_time="$6" +use_gpu=0 -if [[ $use_gpu == "" || $use_crf == "" || $3 == "" || $output_name == "" || ($start_time != "" && $end_time == "") ]]; then - printf "${BOLD}${RED}Usage: $0 \n\nIf you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n" +if [[ "$#" < 3 || "$#" > 6 ]]; then + printf "${BOLD}${RED}Usage: $0 \n\nIf you want to encode a range of CRF values then use -1 as the crf value.${NORMAL}\n" exit 1 fi +use_crf=$1 -filename=$(basename -- "$3") +filename=$(basename -- "$2") extension="${filename##*.}" filename="${filename%.*}" +output_name="$3" + +if [[ "$#" > 3 ]]; then + use_gpu=$4 + if [[ "$#" > 4 ]]; then + start_time="$5" + if [[ "$#" > 5 ]]; then + end_time="$6" + fi + fi +fi + +if [[ $use_gpu -ne 0 && $use_gpu -ne 1 ]]; then + printf "${BOLD}${RED}Invalid use_gpu value. Got $use_gpu, but expected either 0 or 1${NORMAL}\n" + exit 1 +fi + function encode() { crf=$1 output="${output_name}.$extension"