Skip to content

Instantly share code, notes, and snippets.

@0187773933
Last active August 15, 2023 13:56
Show Gist options
  • Save 0187773933/7389ed1b30de09fa4b1e2df72aadf091 to your computer and use it in GitHub Desktop.
Save 0187773933/7389ed1b30de09fa4b1e2df72aadf091 to your computer and use it in GitHub Desktop.
Draws a Black Box Overtop of a Twitch Stream
#!/bin/bash
# twitchIINABlackBox playirresponsibly bottom-left 600 400 0 20
# twitchIINABlackBox chess24 bottom-left 800 110 580 0
if [[ "$1" == *"twitch.tv"* ]]; then
url="$1"
else
url="https://twitch.tv/$1"
fi
POSITION="$2"
X_SIZE="$3"
Y_SIZE="$4"
X_OFFSET="${5:-0}"
Y_OFFSET="${6:-0}"
# Create a PNG image with the black box
convert -size ${X_SIZE}x${Y_SIZE} xc:black black_box.png
X=0
Y=0
case "$POSITION" in
"top-left")
X=$X_OFFSET
Y=$Y_OFFSET
;;
"top-right")
X="main_w-$X_SIZE-$X_OFFSET" # Subtract X offset here
Y=$Y_OFFSET
;;
"bottom-left")
X=$X_OFFSET
Y="main_h-$Y_SIZE-$Y_OFFSET" # Subtract Y offset here
;;
"bottom-right")
X="main_w-$X_SIZE-$X_OFFSET" # Subtract X offset here
Y="main_h-$Y_SIZE-$Y_OFFSET" # Subtract Y offset here
;;
*)
echo "Invalid position. Use top-left, top-right, bottom-left, or bottom-right."
exit 1
;;
esac
# yt-dlp \
# --cookies="/Users/morpheous/Library/CloudStorage/Dropbox/Misc/Cookies/twitch_youtube.txt" \
# -q -o - "$url" | ffmpeg -i - -i black_box.png -filter_complex "[0:v][1:v]overlay=$X:$Y" -c:v libx264 -c:a copy -f mpegts - | /Applications/IINA.app/Contents/MacOS/iina-cli --stdin
# fast encoding preset
yt-dlp \
--cookies="/Users/morpheous/Library/CloudStorage/Dropbox/Misc/Cookies/twitch_youtube.txt" \
-q -o - "$url" | ffmpeg -i - -i black_box.png -filter_complex "[0:v][1:v]overlay=$X:$Y" -c:v libx264 -preset ultrafast -c:a copy -f mpegts - | /Applications/IINA.app/Contents/MacOS/iina-cli --stdin
rm black_box.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment