2016-11-12 06:47:41 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Select a region and record it.
|
2018-08-25 11:23:51 -07:00
|
|
|
#
|
|
|
|
# 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
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2018-08-25 11:23:51 -07:00
|
|
|
if [[ $1 == -s ]]; then
|
|
|
|
is_script=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f /tmp/_stop ]]; then
|
|
|
|
echo q > /tmp/_stop
|
|
|
|
if [[ $is_script ]]; then
|
|
|
|
ding error &
|
|
|
|
else
|
|
|
|
echo "Stopped previous recording"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2018-08-25 11:23:51 -07:00
|
|
|
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}" </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
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2018-08-25 11:23:51 -07:00
|
|
|
if [[ -f $mp4dest ]]; then
|
|
|
|
mov2gif "$mp4dest" "$dest" && rm -fv "$mp4dest"
|
2017-12-05 22:39:10 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# vim:set ft=sh shiftwidth=2:
|