Rewrite rec script

+ Auto-optimizing gifs
+ Add -s option so screencasts can be toggled via keybind
+ Add keybind to sxhkd
This commit is contained in:
Henrik Lissner 2018-08-25 20:23:51 +02:00
parent 0b6a85fd05
commit 3e8ccc39e2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 39 additions and 6 deletions

View file

@ -1,14 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Select a region and record it. # Select a region and record it.
#
# If given a gif, it will record an mp4 and convert it afterwards using the
# mov2gif script included in this repo (which is powered by gifsicle and
# ffmpeg).
#
# Usage: rec somefile.mp4
# rec another.gif
read -r X Y W H G ID < <(slop -f "%x %y %w %h %g %i") if [[ $1 == -s ]]; then
dest=${1:-$(mktemp -t recXXX.webm)} is_script=1
shift
fi
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y "$dest" if [[ -f /tmp/_stop ]]; then
echo q > /tmp/_stop
if [[ $is_script ]]; then
ding error &
else
echo "Stopped previous recording"
fi
exit 0
fi
if [[ -f $dest ]]; then read -r X Y W H < <(slop -f "%x %y %w %h")
mv $dest . dest=${1:-./rec.mp4}
if [[ $dest == *.gif ]]; then
echo "Detected gif"
mp4dest="${dest%.*}.mp4"
fi
if [[ $is_script ]]; then
ding &
touch /tmp/_stop
ffmpeg -y -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "${mp4dest:-$dest}" </tmp/_stop
rm -f /tmp/_stop
else
ffmpeg -y -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "${mp4dest:-$dest}"
fi
if [[ -f $mp4dest ]]; then
mov2gif "$mp4dest" "$dest" && rm -fv "$mp4dest"
fi fi
# vim:set ft=sh shiftwidth=2: # vim:set ft=sh shiftwidth=2:

View file

@ -31,7 +31,7 @@ Print
mod4 + Print mod4 + Print
maim ~/screenshots/$(date +%F-%T).png && notify-send "Fullscreen screenshot saved" maim ~/screenshots/$(date +%F-%T).png && notify-send "Fullscreen screenshot saved"
mod4 + shift + Print mod4 + shift + Print
maim -d 3 ~/screenshots/$(date +%F-%T).png && notify-send "Screenshot saved" rec -s ~/screenshots/$(date +%F-%T).mp4
Pause Pause
mpc -q toggle # play/pause music mpc -q toggle # play/pause music