Last active
December 18, 2020 05:25
-
-
Save statik/a6468f1c535de39c83d6f2a8b7a673f8 to your computer and use it in GitHub Desktop.
prototyping generating placeholders for obs scenes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
output="outputVideo.mp4" | |
#die $text | |
# one version | |
# ffmpeg ${loglevel:-} -i ${input} \ | |
# -vf "drawtext=enable='between(t,${t1},${t2})':${font}:text=${text}: \ | |
# x='if(lt(t-${t2}+1\,0)\,${x1}+(${x2}-${x1})*(t-${t1})/(${t2}-${t1}-1)\,x)': \ | |
# y='if(lt(t-${t2}+1\,0)\,${y1}+(${y2}-${y1})*(t-${t1})/(${t2}-${t1}-1)\,y)':fontsize=${fontsize}" \ | |
# -acodec copy ${output} | |
# another version | |
ffmpeg ${loglevel:-} -i ${input} \ | |
-filter:v drawtext="${font}: \ | |
text=${text}:[email protected]:fontsize=${fontsize}:y=h-line_h-100:x=w/10*mod(t\,${t1}):enable=gt(mod(t\,${t2})\,1)" \ | |
-codec:v libx264 -codec:a copy -y ${output} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
needs more parameters hooked up but this may be easier to experiment with the filter expressions