-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecord
executable file
·77 lines (64 loc) · 1.82 KB
/
record
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
set -eu
__help="Usage: ${0##*/} [OPTIONS]
Take a screencast.
Options:
-h, --help display this help and exit
-o, --output FILE the name of the output file
-s, --select select an area of the screen to take a screencast of
-v, --voice record microphone instead of device audio"
unset output
unset select
unset voice
check_argument() { [ $# -ge 2 ] || { echo "Error: flag $1 requires an argument." && exit 1; } }
while [ ! $# -eq 0 ]; do
case "$1" in
-h | --help)
echo "$__help"
exit 0
;;
-s | --select)
select=1
;;
-v | --voice)
voice=1
;;
-o | --output)
check_argument "$@"
output=$2
shift
;;
*)
break;
;;
esac
shift
done
[ -z "$*" ] || { echo "Error: unexpected positional arguments: $*." && exit 1; }
output=${output:-${XDG_VIDEOS_DIR:-"$HOME/Videos"}/$(date +%s).mp4}
# PulseAudio device names can be determined with `pactl list sources short`.
sound_name="alsa_output.pci-0000_00_1f.3.analog-stereo.monitor"
microphone_name="alsa_input.pci-0000_00_1f.3.analog-stereo"
if pgrep --exact ffmpeg; then
pkill --exact -INT ffmpeg
notify-send --urgency=low 'Stopped video recording'
exit 0
fi
if [ -z ${select:-} ]; then
# Record entire desktop.
dimensions=$(xdpyinfo | awk '/dimensions/{print $2}')
offset="0,0"
notify-send --urgency=low 'Started video recording (desktop)'
else
# Record area.
slop=$(slop --format '%wx%h %x,%y') || exit 1
dimensions=$(echo "$slop" | cut --delimiter=' ' --fields=1)
offset=$(echo "$slop" | cut --delimiter=' ' --fields=2)
notify-send --urgency=low 'Started video recording (area)'
fi
if [ -z ${voice:-} ]; then
input=$sound_name
else
input=$microphone_name
fi
ffmpeg -f x11grab -s "$dimensions" -i :0.0+"$offset" -f pulse -i $input "$output"