summaryrefslogtreecommitdiff
path: root/debian/.local/bin/screenshotactivewindow
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-24 13:54:03 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-12-24 13:54:03 +0900
commit28e8bdf7f8286bd431b7f3b709e79f3827b31469 (patch)
tree85b44eff6da4d8443198fb6e04dfb6ee55244588 /debian/.local/bin/screenshotactivewindow
parent8470ff001befcfd0f626dea69a9e76d43aee0511 (diff)
updates
Diffstat (limited to 'debian/.local/bin/screenshotactivewindow')
-rwxr-xr-xdebian/.local/bin/screenshotactivewindow37
1 files changed, 37 insertions, 0 deletions
diff --git a/debian/.local/bin/screenshotactivewindow b/debian/.local/bin/screenshotactivewindow
new file mode 100755
index 0000000..79365e0
--- /dev/null
+++ b/debian/.local/bin/screenshotactivewindow
@@ -0,0 +1,37 @@
+#!/bin/bash
+set -eo pipefail
+
+pidfile=/tmp/screencast.lock
+
+if [ -e $pidfile ]; then
+ pid=$(cat $pidfile)
+ echo "Already running as ID $pid, now quitting"
+ rm $pidfile
+ kill -15 $pid
+ exit 0
+fi
+
+if [[ "$1" == "" ]]; then
+ echo "Usage: ${0##*/} <window-id>"
+ exit 2
+fi
+
+windowId=$1
+tmpFile=/tmp/screencast-$(date +%s).mkv
+paletteFile=/tmp/palette-$(date +%s).png
+gifFile=/tmp/screencast-$(date +%s).gif
+
+size=$(xdotool getwindowgeometry $windowId | grep Geometry | awk '{print $2}')
+posX=$(xwininfo -id $windowId | grep 'Absolute upper-left X' | awk '{print $4}')
+posY=$(xwininfo -id $windowId | grep 'Absolute upper-left Y' | awk '{print $4}')
+pos="$posX,$posY"
+
+ffmpeg -hide_banner -loglevel info -f x11grab -show_region 1 -video_size $size -i :0+$pos $tmpFile &
+ffPID=$!
+echo $ffPID >$pidfile
+wait $ffPID && echo
+
+ffmpeg -y -i $tmpFile -vf fps=10,palettegen $paletteFile
+ffmpeg -i $tmpFile -i $paletteFile -filter_complex "paletteuse" $gifFile
+
+rm $paletteFile $tmpFile