#!/usr/bin/env nix-shell #! nix-shell -i bash -p ffmpeg slop # 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 if [[ $1 == -s ]]; then is_script=1 shift fi if [[ -f /tmp/_stop ]]; then echo q > /tmp/_stop if [[ $is_script ]]; then >&2 echo "Nope" else echo "Stopped previous recording" fi exit 0 fi 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 echo "Starting" touch /tmp/_stop ffmpeg -y -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "${mp4dest:-$dest}"