From 20f09041a788fb0f1fba9ce3eb1ca987864c2c49 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 7 Sep 2021 16:13:41 +0100 Subject: [PATCH] BIN: Adds screen record script --- bin/.bin/screenrecord | 80 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 bin/.bin/screenrecord diff --git a/bin/.bin/screenrecord b/bin/.bin/screenrecord new file mode 100755 index 00000000..26bac652 --- /dev/null +++ b/bin/.bin/screenrecord @@ -0,0 +1,80 @@ +#!/bin/bash + +# A simple wrapper around ffmpeg +# +# When run, a screenrecording will be made +# The file path will be put in the primary selection +# Will create notification containing file path +# +# If you have a project specified, it will put the sceenshot in that folder instead of /tmp +# +# Relies on ffmpeg for taking screenrecording + +PIDFILE="/tmp/screenrecord.pid" + + + +if [ -f "$PIDFILE" ]; then + pkill ffmpeg + exit +fi + +echo $$ > "$PIDFILE" + + + +path='/tmp' +command -v ffmpeg > /dev/null || ( echo -n "You need to install ffmpeg" && exit 1 ) + +#If a project is set we will put screenshots in the project's folder +command -v project > /dev/null && project=$(project current --path) +if [ -n "$project" ]; then + path="$project/screenrecordings" + #Make the directory if it doesn't exist + mkdir "$path" 2> /dev/null +fi + +filename="$(date +"%Y-%m-%dT%H-%M-%SZ").mkv" +file="${path}/${filename}" + +[ "$1" = "-w" ] && sleep "$2" && shift && shift + +case $1 in + "select") + if [ -n "$WAYLAND_DISPLAY" ]; then + echo "Shouldn't get here" + echo "No wayland support yet" >&2 + exit + else + echo "I get here" + ffmpeg -framerate 30 -f x11grab $(slop -l -c "0.41,0.62,0.42,0.2" -f "-video_size %wx%h -i :0.0+%x,%y") "$file" + fi + ;; + *) + if [ -n "$WAYLAND_DISPLAY" ]; then + echo "No wayland support yet" >&2 + exit + else + ffmpeg -framerate 30 -f x11grab -video_size "$(xdpyinfo | grep dimensions | awk '{print $2}')" -i :0.0 "$file" + fi + ;; +esac + +if [ -f "$file" ]; then + # Create a gif + ffmpeg -i "$file" -vf "fps=10,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "${file%.*}".gif + if [ -n "$WAYLAND_DISPLAY" ]; then + # Copies the image to your clipboard (ctrl + v) + wl-copy < "${file%.*}.gif" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "${file%.*}.gif" | wl-copy --primary + else + # Copies the image to your clipboard (ctrl + v) + xclip -selection clipboard -target image/gif -i "${file%.*}.gif" + # Copies the filename to primary selection (shift + insert or middle mouse) + echo -n "${file%.*}.gif" | xclip -selection primary + fi + # Creates notification with file name + notify-send "New Screenrecording" "$file\n${file%.*}.gif" +fi +rm "$PIDFILE"