diff options
Diffstat (limited to 'ar/.local/bin/screenshotactivewindow')
| -rwxr-xr-x | ar/.local/bin/screenshotactivewindow | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ar/.local/bin/screenshotactivewindow b/ar/.local/bin/screenshotactivewindow new file mode 100755 index 0000000..79365e0 --- /dev/null +++ b/ar/.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 |
