2020-01-12 15:18:09 -08:00
|
|
|
#!/usr/bin/env cached-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
|
2020-01-03 19:55:59 -08:00
|
|
|
count=3
|
|
|
|
fps=30
|
|
|
|
stopfile=/tmp/_stop
|
2020-01-12 15:18:09 -08:00
|
|
|
while getopts c:d:f:g:ps opt; do
|
2019-08-26 10:15:12 -07:00
|
|
|
case $opt in
|
2020-01-03 19:55:59 -08:00
|
|
|
c) count=$OPTARG ;;
|
2020-01-12 15:18:09 -08:00
|
|
|
d) delay="$OPTARG" ;;
|
2020-01-03 19:55:59 -08:00
|
|
|
f) fps=$OPTARG ;;
|
2019-08-26 10:15:12 -07:00
|
|
|
g) geom="$OPTARG" ;;
|
2020-01-12 15:18:09 -08:00
|
|
|
p) compton= ;;
|
|
|
|
s) is_script=1 ;;
|
2019-08-26 10:15:12 -07:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2020-01-03 19:55:59 -08:00
|
|
|
##
|
2020-01-12 15:18:09 -08:00
|
|
|
select-region() {
|
2020-01-03 19:55:59 -08:00
|
|
|
if [[ $geom ]]; then
|
|
|
|
echo "${geom//[x+]/ }"
|
|
|
|
else
|
2020-01-12 15:18:09 -08:00
|
|
|
slop -nof "%w %h %x %y"
|
2020-01-03 19:55:59 -08:00
|
|
|
fi
|
|
|
|
}
|
2018-08-25 11:23:51 -07:00
|
|
|
|
2020-01-03 19:55:59 -08:00
|
|
|
countdown() {
|
|
|
|
if (( count > 0 )); then
|
|
|
|
for ((i=count;i>0;i--)); do
|
|
|
|
if [[ $is_script ]]; then
|
|
|
|
notify-send -u critical -t 1000 "Recording in $i"
|
2020-02-08 20:26:11 -08:00
|
|
|
else
|
|
|
|
echo "Recording in $i"
|
2020-01-03 19:55:59 -08:00
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
elif [[ $is_script ]]; then
|
|
|
|
notify-send -u critical "Starting recording..."
|
2020-02-08 20:26:11 -08:00
|
|
|
else
|
|
|
|
echo "Started recording..."
|
2018-08-25 11:23:51 -07:00
|
|
|
fi
|
2020-01-03 19:55:59 -08:00
|
|
|
}
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2020-01-03 19:55:59 -08:00
|
|
|
recording-start() {
|
2020-01-12 15:18:09 -08:00
|
|
|
local ffmpeg_opts="-y -f x11grab -show_region 1 -ss $delay -s ${4}x${5} -i :0.0+${2},${3} -framerate ${fps}"
|
2020-01-03 19:55:59 -08:00
|
|
|
local dest=${1:-./rec.mp4}
|
2020-01-12 15:18:09 -08:00
|
|
|
local mp4dest=
|
2020-01-03 19:55:59 -08:00
|
|
|
[[ $dest == *.gif ]] && mp4dest="${dest%.*}.mp4"
|
|
|
|
countdown
|
2020-02-29 15:48:25 -08:00
|
|
|
ffmpeg $ffmpeg_opts "${mp4dest:-$dest}" &
|
|
|
|
pid=$!
|
|
|
|
echo $pid >$stopfile
|
|
|
|
wait $pid
|
2020-01-03 19:55:59 -08:00
|
|
|
rm -f $stopfile
|
|
|
|
if [[ -f "$mp4dest" ]]; then
|
|
|
|
mov2gif "$mp4dest" "$dest" && rm -fv "$mp4dest"
|
|
|
|
fi
|
2020-02-29 15:48:25 -08:00
|
|
|
echo -n "$dest" | xclip -selection clipboard -in
|
2020-02-08 20:26:11 -08:00
|
|
|
notify-send "Screencast successful" "Saved to $dest\nAnd copied to your clipboard!"
|
2020-01-03 19:55:59 -08:00
|
|
|
}
|
2018-08-25 11:23:51 -07:00
|
|
|
|
2016-11-12 06:47:41 -08:00
|
|
|
|
2020-01-03 19:55:59 -08:00
|
|
|
# If a recording session is already active, stop that one.
|
2020-02-29 15:48:25 -08:00
|
|
|
if [[ -n "$is_script" && -f "$stopfile" ]]; then
|
|
|
|
kill $(cat $stopfile)
|
2020-01-03 19:55:59 -08:00
|
|
|
echo "Stopped previous recording"
|
|
|
|
exit 0
|
2017-12-05 22:39:10 -08:00
|
|
|
fi
|
|
|
|
|
2020-01-12 15:18:09 -08:00
|
|
|
read -r W H X Y < <(select-region)
|
2020-02-29 15:48:25 -08:00
|
|
|
[[ -z "$W$H$X$Y" ]] && exit 1
|
2020-01-12 15:18:09 -08:00
|
|
|
|
2020-01-03 19:55:59 -08:00
|
|
|
# Compton with blur and/or transparencies cause unbearable flickering in
|
|
|
|
# recordings, so temporarily disable it.
|
2020-01-12 15:18:09 -08:00
|
|
|
compton=
|
2020-01-03 19:55:59 -08:00
|
|
|
if systemctl is-enabled --user compton >/dev/null; then
|
|
|
|
systemctl --user stop compton
|
2020-01-12 15:18:09 -08:00
|
|
|
compton=1
|
2020-01-03 19:55:59 -08:00
|
|
|
fi
|
2020-01-12 15:18:09 -08:00
|
|
|
cleanup() { [[ $compton ]] && systemctl --user start compton; }
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
# Let 'er rip
|
2020-02-08 20:26:11 -08:00
|
|
|
recording-start "$1" "$X" "$Y" "$W" "$H"
|
2019-08-26 10:15:12 -07:00
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
# vim:set ft=sh shiftwidth=2:
|