Last active
December 28, 2022 21:36
-
-
Save tonkku107/d170f2faaa6ee09a1fbf08b260f8d179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -m | |
#** | |
# Screenrecorder script by Tonkku | |
# Credit goes to lots of Googling which finally brought me to | |
# https://www.reddit.com/r/i3wm/comments/7ahbvv/what_do_you_use_to_make_gif_screen_capture/dpavjo7 | |
# Which was basically what I was doing originally but in a nicer form. | |
# Then I expanded it according to my original plans. | |
# | |
# Depends on | |
# - ffmpeg | |
# - slop (and the boxzoom shader) | |
# - curl | |
# - kdialog | |
# - xclip | |
#** | |
# Check if there's already a running recorder | |
if [ -f /tmp/recorder.pid ]; then | |
notify-send --icon=dialog-error "Recorder is already running" | |
exit 0 | |
fi | |
# Set variables | |
TMP="$(mktemp -t screenrecording-XXXXXXXXXX.mkv)" | |
FILENAME="$(date '+%Y-%m-%d_%H-%M-%S')" | |
TMPGIF="/tmp/$FILENAME.gif" | |
UPLOADERKEY="" | |
# Select region and start recording | |
read -r X Y W H G ID < <(slop -f "%x %y %w %h %g %i" -r boxzoom) | |
ffmpeg -y -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "$TMP" & | |
echo $! > /tmp/recorder.pid | |
fg | |
# Convert video to gif | |
notify-send --icon=dialog-information "Post-processing..." | |
ffmpeg -y -i "$TMP" -vf fps=10,palettegen /tmp/palette.png | |
ffmpeg -i "$TMP" -i /tmp/palette.png -filter_complex "paletteuse" $TMPGIF | |
notify-send --icon=dialog-information "Done. $(du -h $TMPGIF | awk '{print $1}')" | |
# Upload / Save | |
choice=$(kdialog --title "Choose action" --radiolist "Choose action" 1 "Save as..." on 2 "Upload to example.com" off) | |
if [ $choice -eq 1 ]; then | |
# Save | |
location=$(kdialog --title "Where should this recording be saved?" --getsavefilename $HOME/Desktop/$FILENAME.gif "GIF File (*.gif)") | |
mv $TMPGIF $location | |
elif [ $choice -eq 2 ]; then | |
notify-send --icon=dialog-information "Uploading..." | |
REMOTE=$(curl -F "file=@$TMPGIF" -H "key: $UPLOADERKEY" https://example.com/upload) | |
notify-send --icon=dialog-information "Uploaded. $REMOTE" | |
echo -n $REMOTE | xclip -selection clipboard | |
else | |
echo "Invalid option / cancel" | |
fi | |
# Clean up | |
trap "rm -f /tmp/recorder.pid && rm -f '$TMP' && rm -f '$TMPGIF' && rm /tmp/palette.png" 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#** | |
# Script used to stop the recording when using with keyboard shortcuts | |
#** | |
kill $(cat /tmp/recorder.pid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment