update screen grab scripts to partially support wayland

This commit is contained in:
Crispy 2024-12-23 01:28:26 +01:00
parent 728c410552
commit 427a0f9ec6
3 changed files with 41 additions and 16 deletions

View file

@ -1,20 +1,27 @@
#!/bin/bash #!/bin/bash
statusfile="/tmp/running_screen_recorder" STATUSFILE="/tmp/running_screen_recorder"
# check for running instance, stop it and exit # check for running instance, stop it and exit
if [ -f $statusfile ]; then if [ -f $STATUSFILE ]; then
ffpid=$(<$statusfile) FFPID=$(<$STATUSFILE)
kill $ffpid kill $FFPID
rm $statusfile rm $STATUSFILE
exit 0 exit 0
fi fi
# select area of screen # select area of screen
slop=$(slop -f "%x %y %w %h %g %i" --color=0.8,0.4,1.0,1.0 -t 16) || exit 1 if [ $XDG_SESSION_TYPE = 'wayland' ]; then
read -r X Y W H G ID < <(echo $slop) SLURP=$(slurp -b#ff44ff22 -w0) || exit 1
read -r POS DIMS < <(echo $SLURP)
W=${DIMS%x*}
H=${DIMS#*x}
else
SLOP=$(slop -f "%x,%y %w %h" --color=0.8,0.4,1.0,1.0 -t 16) || exit 1
read -r POS W H< <(echo $SLOP)
fi
videofile=$(xdg-user-dir VIDEOS)/sel_$(date "+%Y-%m-%d_%H.%M.%S").mp4 OUTPUT_FILE=$(xdg-user-dir VIDEOS)/sel_$(date "+%Y-%m-%d_%H.%M.%S").mp4
logfile="/tmp/screen_recorder_ffmpeg.log" LOGFILE="/tmp/screen_recorder_ffmpeg.log"
# make sure selection width and height is even # make sure selection width and height is even
# even video size needed for yuv420p format # even video size needed for yuv420p format
@ -22,10 +29,15 @@ logfile="/tmp/screen_recorder_ffmpeg.log"
H=$(( $H - $H%2 )) H=$(( $H - $H%2 ))
W=$(( $W - $W%2 )) W=$(( $W - $W%2 ))
# empty audio track to prevent videos showing up as "GIF" on certain platforms (mastodon)
dummy_audio="-f lavfi -i anullsrc=cl=mono" dummy_audio="-f lavfi -i anullsrc=cl=mono"
ffmpeg -y $dummy_audio -video_size "$W"x"$H" -f x11grab -framerate 60 \ if [ $XDG_SESSION_TYPE = 'wayland' ]; then
-i $DISPLAY+$X,$Y -pix_fmt yuv420p $videofile 2> $logfile & echo "fuck (todo figure out wayland ffmpeg shit)"
# ffmpeg $video_settings -device /dev/dri/card1-re-fkms-grab -i - $OUTPUT_FILE 2> $LOGFILE &
else
ffmpeg -y $dummy_audio -video_size "$W"x"$H" -f x11grab -framerate 60 \
-i $DISPLAY+$POS -pix_fmt yuv420p $OUTPUT_FILE 2> $LOGFILE &
fi
# store pid so that recording can be stopped next time the script is run # store pid so that recording can be stopped next time the script is run
echo $! > $statusfile echo $! > $STATUSFILE

View file

@ -1,5 +1,12 @@
#!/bin/bash #!/bin/bash
path=$(xdg-user-dir PICTURES)/screenshots/screen-$(date "+%Y-%m-%d_%H:%M:%S").png path=$(xdg-user-dir PICTURES)/screenshots/screen-$(date "+%Y-%m-%d_%H:%M:%S").png
mkdir -p $(xdg-user-dir PICTURES)/screenshots mkdir -p $(xdg-user-dir PICTURES)/screenshots
maim -u -o $path
xclip -selection clipboard -target image/png -i $path if [ $XDG_SESSION_TYPE = 'wayland' ]; then
grim $path
wl-copy -t image/png < $path
else
maim -u -o $path
xclip -selection clipboard -target image/png -i $path
fi

View file

@ -1,2 +1,8 @@
#!/bin/bash #!/bin/bash
maim -s -u --color=1.0,0.5,0.0,1.0 -t 16 | xclip -selection clipboard -t image/png
if [ $XDG_SESSION_TYPE = 'wayland' ]; then
grim -g "$(slurp -b#ffff4411 -w0)" - | wl-copy -t image/png
else
maim -s -u --color=1.0,0.5,0.0,1.0 -t 16 | xclip -selection clipboard -t image/png
fi