52 lines
1.2 KiB
Bash
52 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Bigger crf values == bigger compression.
|
|
|
|
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
|
|
# Found the following to work best with vids containing text (e.g. programming vids). These give similar bitrates.
|
|
cpu_crf=20
|
|
gpu_crf=33
|
|
|
|
if [[ $# < 2 || $# > 5 ]]; then
|
|
printf "${BOLD}${RED}Usage: compress-video <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS> (NOTE: gpu crf is $gpu_crf and cpu crf is $cpu_crf - change it by calling compress-video-with-crf)${NORMAL}\n"
|
|
exit 1
|
|
fi
|
|
|
|
filename=$(basename -- "$1")
|
|
output_name="$2"
|
|
|
|
if [[ $# > 2 ]]; then
|
|
use_gpu=$3
|
|
fi
|
|
|
|
use_crf=$cpu_crf
|
|
if [[ $use_gpu -eq 1 ]]; then
|
|
use_crf=$gpu_crf
|
|
fi
|
|
|
|
compress-video-with-crf $use_crf "$filename" "$output_name" $use_gpu $4 $5
|
|
|