dotfiles/bin/compress-video

48 lines
997 B
Plaintext
Raw Normal View History

2020-07-25 23:39:09 +00:00
#!/usr/bin/env bash
if which tput >/dev/null 2>&1; then
2020-07-26 17:58:29 +00:00
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
2020-07-26 17:58:29 +00:00
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
2020-07-26 17:58:29 +00:00
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
BOLD=""
NORMAL=""
fi
2022-12-28 05:46:37 +00:00
use_gpu=0
2021-08-22 17:49:35 +00:00
2022-12-28 05:46:37 +00:00
if [[ $# < 2 || $# > 3 ]]; then
printf "${BOLD}${RED}Usage: $0 <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> ${NORMAL}\n"
exit 1
fi
2022-12-28 05:46:37 +00:00
filename=$(basename -- "$1")
output_name="$2"
if [[ $# > 2 ]]; then
use_gpu=$3
fi
2021-08-11 14:37:50 +00:00
# Found the following to work best with vids containing text (e.g. programming vid): 25 for CPU encoding and 27 for GPU.
2022-06-23 21:15:30 +00:00
use_crf=21
if [[ $use_gpu -eq 1 ]]; then
2022-06-23 21:15:30 +00:00
use_crf=25
fi
2022-12-28 05:46:37 +00:00
compress-video-with-crf $use_crf "$filename" "$output_name" $use_gpu