Last active
December 20, 2021 20:15
-
-
Save joshzcold/7689a42656e5610cd7327735e794d969 to your computer and use it in GitHub Desktop.
use ffcast to record either a gif or mp4 from rectangle selection using slop. set the stop/start execute of this script to a hotkey.
This file contains hidden or 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
#!/usr/bin/env bash | |
# use ffcast to record either a gif or mp4 from rectangle selection using slop | |
# required: ffmpeg,ffcast,imagemagick,slop | |
# set the stop/start execute of this script to a hotkey. | |
function usage() { | |
echo "Usage : $(basename "$0") [options] [--] | |
Options: | |
-k|kill kill last running record | |
-r|record start recording | |
* toggle starting/stopping recording with no arguments | |
" | |
} # ---------- end of function usage ---------- | |
kill_record() { | |
pkill -fxn '(/\S+)*ffmpeg\s.*\sx11grab\s.*' | |
} | |
record() { | |
choice=$(echo "mp4,gif" | tr ',' '\n' | rofi -dmenu) | |
TMP="/tmp/$(date '+%Y-%m-%d.%H:%M:%S')" | |
if [[ "$choice" = "mp4" ]]; then | |
ffcast -q -g $(slop -n -f '%g') rec $TMP.mp4 | |
notify-send "$TMP.mp4" | |
echo -n "$TMP.mp4" | xclip -selection clipboard | |
elif [[ "$choice" = "gif" ]]; then | |
trap "rm -f $TMP.avi" EXIT | |
ffcast -s % ffmpeg -y -f x11grab -show_region 1 -framerate 15 \ | |
-video_size %s -i %D+%c -codec:v huffyuv \ | |
-vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" $TMP.avi | |
convert -set delay 10 -layers Optimize $TMP.avi $TMP.gif | |
notify-send "$TMP.gif" | |
echo -n "$TMP.gif" | xclip -selection clipboard | |
fi | |
} | |
toggle() { | |
if pgrep "ffmpeg"; then | |
kill_record | |
else | |
record | |
fi | |
} | |
while getopts ":krh" o; do | |
echo $o | |
case "${o}" in | |
k) | |
kill_record | |
exit 0 | |
;; | |
r) | |
record | |
exit 0 | |
;; | |
h) | |
usage | |
exit 0 | |
;; | |
esac | |
done | |
if [ $OPTIND -eq 1 ]; then | |
toggle | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment