-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffrec
executable file
·58 lines (51 loc) · 992 Bytes
/
ffrec
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
#!/bin/sh
# Record the screen.
# runtime files
lockdir=/tmp/ffrec$DISPLAY
pidfile=$lockdir/pid
# spawn ffmpeg processes
ffstart() {
ffmpeg \
-loglevel panic \
-f x11grab \
-s 1920x1080 \
-i "$DISPLAY" \
-f pulse \
-i default \
-r 25 \
-pix_fmt yuv420p \
-c:v libx264 \
-c:a aac \
"$HOME/$(date +'%d-%m-%y_%H:%M:%S').mp4" &
}
# wait for ffmpeg to terminate
ffwait() {
# we use loop here because signals interrupt wait
while ! wait; do : ;done
}
# kill ffmpeg process (on SIGTERM)
ffkill() {
trap '' TERM
kill "$!"
}
# do the recording
record() {
ffstart
trap ffkill TERM
ffwait
}
# ignore SIGTERM before trying to acquire the lock
trap '' TERM
if mkdir "$lockdir" 2>/dev/null; then
# recorder branch
echo $$ >"$pidfile"
case $(printf '%s\n' Yes No | dmenu -p 'Start recording?') in
Y*) record
esac
rm -r "$lockdir"
else
# killer branch
case $(printf '%s\n' Yes No | dmenu -p 'Stop recording?') in
Y*) pkill -F "$pidfile" 2>/dev/null ;;
esac
fi