Add more features to wf-shadow

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-05-12 17:45:53 -04:00
parent ea781c6857
commit 1fcd7298da
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
2 changed files with 63 additions and 15 deletions

View File

@ -173,6 +173,8 @@ bindsym KP_7 exec mpv ~/Audio/mega.opus
exec pactl load-module module-null-sink sink_name=Combined
exec pactl load-module module-loopback sink=Combined source=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
exec pactl load-module module-loopback sink=Combined source=alsa_input.pci-0000_00_1b.0.analog-stereo
exec pactl load-module module-loopback sink=Combined source=bluez_input.7C_96_D2_D9_4D_F7.0
exec pactl load-module module-loopback sink=Combined source=bluez_output.7C_96_D2_D9_4D_F7.1.monitor
exec ~/.local/bin/wf-shadow -s 1
exec ~/.local/bin/wf-shadow -s 2

View File

@ -1,7 +1,15 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 Skylar Widulski
trap 'kill $(jobs -p)' EXIT
MONITOR=1
AUDIO_DEV=""
VIDEO_DEV=""
VERBOSE=""
trap 'kill $(jobs -p) 2>/dev/null' EXIT
trap 'exit' INT
set -m
#( read -rsn1 && exit 12 ) &
if [ ! -d /tmp/wf-shadow ]; then
mkdir -p /tmp/wf-shadow 2>/dev/null
@ -27,27 +35,32 @@ print_help() {
printf "USAGE: %s OPTION\n" "$0"
printf "\n"
printf "OPTIONS:\n"
printf "\t-s DISPLAY, --start DISPLAY\tStart a wf-shadow instance with display number DISPLAY\n"
printf "\t-r DISPLAY, --record DISPLAY\tRecord the last few moments of video using a wofi menu\n"
printf "\t-s MONITOR, --start MONITOR\tStart a wf-shadow instance with display number MONITOR\n"
printf "\t-r MONITOR, --record MONITOR\tRecord the last few moments of video using a wofi menu\n"
printf "\t-a DEVICE, --audio DEVICE\tUse DEVICE for audio recording. Passed to wf-recorder -a\n"
printf "\t-V DEVICE, --video DEVICE\tUse DEVICE for video encoding. Passed to wf-recorder -d\n"
printf "\t-v, --verbose\tVerbose output\n"
printf "\t-h, --help\tShow this menu\n"
printf "\n"
printf "Press any key to exit. Exit code of 12 or 0 is successful.\n"
exit $1
}
record() {
local FILE="$HOME"/Videos/wf-shadow/"$(date +%Y%m%d_%H:%M:%S)__$2".mp4
ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE"
notify-send "$2 second clip saved to $FILE"
ffmpeg -nostdin -y -sseof -"$2" -i "$1" "$FILE" ${VERBOSE:-&>/dev/null} &&
notify-send "Clip saved" "$2 second clip saved to $FILE"
}
start() {
while true; do
eval 'for i in /tmp/wf-shadow/tmp{00..'"${2:-10}"'}.mp4; do
eval 'for i in /tmp/wf-shadow/tmp{00..10}.mp4; do
touch "$i"
wf-recorder -d /dev/dri/renderD128 -a Combined.monitor -f "$i" <<< "y"$'\''\n'\'"$1"' &
printf "%s" "$!" > "$XDG_RUNTIME_DIR"/wf-shadow_'"$1"'.pid
wf-recorder '"${VIDEO_DEV:+-d "$VIDEO_DEV"}"' -a '"$AUDIO_DEV"' -f "$i" <<< y$'\''\n'\'"$MONITOR"' '"${VERBOSE:-&>/dev/null}"' &
printf "%s" "$!" > "$XDG_RUNTIME_DIR"/wf-shadow_'"$MONITOR"'.pid
fg || exit
case "$(printf "5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 )" in
case "$(printf "5 seconds\n10 seconds\n15 seconds\n30 seconds\n1 minute\n5 minutes\n10 minutes\nCancel\n" | wofi --dmenu -i -H 500 -W 250 -x 0 -y 0 '"${VERBOSE:-&>/dev/null}"' )" in
'\''5 seconds'\'') record "$i" 5 ;;
'\''10 seconds'\'') record "$i" 10 ;;
'\''15 seconds'\'') record "$i" 15 ;;
@ -61,9 +74,42 @@ start() {
done
}
case "$1" in
'-h' | '--help') print_help ;;
'-r' | '--record') [[ "$2" ]] && kill -2 $(<"$XDG_RUNTIME_DIR"/wf-shadow_"$2".pid) ;;
'-s' | '--start') [[ "$2" ]] && start "$2" || print_help 1 ;;
*) print_help ;;
esac
until [ -z "$1" ]; do
case "$1" in
'-h' | '--help') print_help ;;
'-r' | '--record')
RECORD=1
MONITOR="$2"
shift 2 ;;
'-s' | '--start')
START=1
MONITOR="$2"
shift 2 ;;
'-a' | '--audio')
AUDIO_DEV="$2"
shift 2 ;;
'-V' | '--video')
VIDEO_DEV="$2"
shift 2 ;;
'-v' | '--verbose')
VERBOSE=" "
shift 1 ;;
*) print_help ;;
esac
done
if [ "$START" == 1 ]; then
if [ "$MONITOR" ]; then
start
else
print_help 1
fi
fi
if [ "$RECORD" == 1 ]; then
if [ "$MONITOR" ]; then
kill -2 "$(<"$XDG_RUNTIME_DIR"/wf-shadow_"$MONITOR".pid)"
else
print_help 1
fi
fi