Skip to content

Instantly share code, notes, and snippets.

@statik
Last active December 18, 2020 05:25
Show Gist options
  • Save statik/a6468f1c535de39c83d6f2a8b7a673f8 to your computer and use it in GitHub Desktop.
Save statik/a6468f1c535de39c83d6f2a8b7a673f8 to your computer and use it in GitHub Desktop.
prototyping generating placeholders for obs scenes
#!/usr/bin/env bash
# nice script boilerplate from https://betterdev.blog/minimal-safe-bash-script-template/
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] -t text_to_add
Generates a test video signal
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-t, --text Text to overlay
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
msg() {
echo >&2 -e "${1-}"
}
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}
parse_params() {
# default values of variables set from params
loglevel="-loglevel quiet"
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose)
set -x
loglevel="-loglevel debug"
;;
--no-color) NO_COLOR=1 ;;
-t | --text) # named parameter
text="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
# check required params and arguments
[[ -z "${text-}" ]] && die "Missing required parameter: --text"
# if arguments are required (like the input file)
# [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"
return 0
}
parse_params "$@"
setup_colors
# script logic here
# debugging parameter handling
#msg "${RED}Read parameters:${NOFORMAT}"
#msg "- text: ${text}"
#msg "- arguments: ${args[*]-}"
t1=10
t2=15
x1=0
y1=0
x2=100
y2=100
font="Lato-Regular.ttf"
fontsize="65"
text="'${text}'"
#input="output-text1.mp4"
duration="30"
input="testsrc=duration=${duration}:size=1910x1080:rate=30"
overlay="guest-card-leaves.png"
output="outputVideo.mp4"
ffmpeg ${loglevel:-} -f lavfi -i "${input}" -i "${overlay}" \
-filter_complex "[0:v][1:v] overlay=0:0, drawtext=${font}:text=${text}:[email protected]:fontsize=${fontsize}:x=150:y=h-th-150" \
-codec:v libx264 -codec:a copy -y ${output}
@statik
Copy link
Author

statik commented Dec 17, 2020

needs more parameters hooked up but this may be easier to experiment with the filter expressions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment