2019-08-06 10:56:54 -07:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#! nix-shell -i bash -p ffmpeg slop
|
2016-11-12 06:47:41 -08:00
|
|
|
|
|
|
|
# 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).
|
|
|
|
#
|
2019-08-26 10:15:12 -07:00
|
|
|
# Usage: scrrec somefile.mp4
|
|
|
|
# scrrec another.gif
|
|
|
|
|
|
|
|
is_script=
|
|
|
|
geom=
|
|
|
|
delay=1
|
|
|
|
while getopts sg:d: opt; do
|
|
|
|
case $opt in
|
|
|
|
s) is_script=1 ;;
|
|
|
|
g) geom="$OPTARG" ;;
|
|
|
|
d) delay="$OPTARG" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2018-08-25 11:23:51 -07:00
|
|
|
|
|
|
|
if [[ -f /tmp/_stop ]]; then
|
|
|
|
echo q > /tmp/_stop
|
|
|
|
if [[ $is_script ]]; then
|
2019-08-06 10:56:54 -07:00
|
|
|
>&2 echo "Nope"
|
2018-08-25 11:23:51 -07:00
|
|
|
else
|
|
|
|
echo "Stopped previous recording"
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2019-08-26 10:15:12 -07:00
|
|
|
if [[ $geom ]]; then
|
|
|
|
read -r W H X Y <<<"${geom//[x+]/ }"
|
|
|
|
else
|
|
|
|
read -r X Y W H < <(slop -n -f "%x %y %w %h")
|
|
|
|
fi
|
2018-08-25 11:23:51 -07:00
|
|
|
dest=${1:-./rec.mp4}
|
|
|
|
if [[ $dest == *.gif ]]; then
|
|
|
|
echo "Detected gif"
|
|
|
|
mp4dest="${dest%.*}.mp4"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $is_script ]]; then
|
2019-08-06 10:56:54 -07:00
|
|
|
echo "Starting"
|
2018-08-25 11:23:51 -07:00
|
|
|
touch /tmp/_stop
|
2019-08-26 10:15:12 -07:00
|
|
|
ffmpeg -y -f x11grab -ss $delay -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "${mp4dest:-$dest}" </tmp/_stop
|
2018-08-25 11:23:51 -07:00
|
|
|
rm -f /tmp/_stop
|
|
|
|
else
|
2019-08-26 10:15:12 -07:00
|
|
|
ffmpeg -y -f x11grab -ss $delay -s "$W"x"$H" -i :0.0+$X,$Y -framerate 30 "${mp4dest:-$dest}"
|
2018-08-25 11:23:51 -07:00
|
|
|
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
|
|
|
|
|
2019-08-26 10:15:12 -07:00
|
|
|
echo "Finishing up"
|
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
# vim:set ft=sh shiftwidth=2:
|