-
Notifications
You must be signed in to change notification settings - Fork 1
/
record-gif
executable file
·63 lines (53 loc) · 1.48 KB
/
record-gif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/bash -e
# https://github.com/naelstrof/slop
# https://github.com/kaihendry/recordmydesktop2.0
while getopts "mnhv" o
do
case "$o" in
(\?) echo "Invalid option: -$OPTARG" >&2 ;;
(h) less $(readlink -f $(dirname $0))/README.md; exit;;
(v) verbose="";; # funnily ffmpeg is verbose by default
(*) break;;
esac
done
shift $((OPTIND - 1))
lockfile=/tmp/r2d2
if test -f $lockfile
then
pid=$(awk '{print $1}' $lockfile)
if kill -0 $pid
then
kill -INT $pid
echo Killed $(cat $lockfile)
logger x11captured: $(du -h $(awk '{print $2}' $lockfile))
rm $lockfile
exit
else
rm $lockfile
fi
fi
if test "$1"
then
output=$1
else
output="$(dirname $(readlink -f $0))/$(date +%s).mkv"
fi
# Only create RAW file if one does not exist
if test -f "$output"
then
echo $output already exists
logger $(basename $0): $output already exists
exit 1
fi
die() { echo "$@"; exit 1; }
require() { which $1 &> /dev/null; }
for prg in slop ffmpeg; do
require $prg || die "needs ${prg} installed"
done
#res="$(xdpyinfo | awk '/dimensions:/ { print $2; exit }')"
read -r X Y W H G ID < <(slop -f "%x %y %w %h %g %i")
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f pulse -i default -acodec pcm_s16le -c:v libx264 $output &>> /tmp/r2d2.log &
#ffmpeg -f x11grab -video_size $res -i $DISPLAY -f pulse
# https://trac.ffmpeg.org/wiki/Capture/Desktop
echo "$! $(readlink -f $output)" > $lockfile
echo -e "\033[1;34m$0\033[m Capturing $res, kill $(awk '{print $1}' $lockfile) to kill capture or run $0 again"