From 3e8ccc39e2dbe3234f1bfdf1176686eca3013e79 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 25 Aug 2018 20:23:51 +0200 Subject: [PATCH] Rewrite rec script + Auto-optimizing gifs + Add -s option so screencasts can be toggled via keybind + Add keybind to sxhkd --- base/arch-desktop/bin/rec | 43 +++++++++++++++++++++++--- base/arch-desktop/config/sxhkd/sxhkdrc | 2 +- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/base/arch-desktop/bin/rec b/base/arch-desktop/bin/rec index 10d6ddb7..99e32814 100755 --- a/base/arch-desktop/bin/rec +++ b/base/arch-desktop/bin/rec @@ -1,14 +1,47 @@ #!/usr/bin/env bash # 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") -dest=${1:-$(mktemp -t recXXX.webm)} +if [[ $1 == -s ]]; then + 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 - mv $dest . +read -r X Y W H < <(slop -f "%x %y %w %h") +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}"