-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscreencasting
More file actions
executable file
·79 lines (69 loc) · 2.06 KB
/
screencasting
File metadata and controls
executable file
·79 lines (69 loc) · 2.06 KB
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
78
79
#!/usr/bin/env bash
# Record desktop (or webcam) with microphone audio using ffmpeg.
set -euo pipefail
PIDFILE="${PIDFILE:-/tmp/screencasting.pid}"
video_source=( )
video_encoder=( -c:v libx264 -r 30 )
audio_source=( -f alsa -ac 2 -i default )
audio_encoder=( -c:a aac -b:a 128k )
output_name="$HOME/output_$(date +%Y%m%d%H%M%S).mkv"
webcam_only=false
info() {
printf 'Usage: %s [-p] [-w] [-o FILE] [-s] [-h]\n' "$0"
printf '\t-p\tUse PulseAudio input instead of ALSA\n'
printf '\t-w\tRecord webcam only (/dev/video0)\n'
printf '\t-o\tSet output file path\n'
printf '\t-s\tStop active recording\n'
printf '\t-h\tDisplay this help\n'
}
stop_recording() {
if [[ -f "$PIDFILE" ]] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
kill "$(cat "$PIDFILE")"
rm -f "$PIDFILE"
echo 'Recording stopped.'
else
echo 'No active recording found.' >&2
return 1
fi
}
while getopts 'pwo:sh' o; do
case "$o" in
p) audio_source=( -f pulse -ac 2 -i default ) ;;
w) webcam_only=true ;;
o) output_name=$OPTARG ;;
s)
stop_recording
exit 0
;;
h)
info
exit 0
;;
*)
info
exit 1
;;
esac
done
command -v ffmpeg >/dev/null 2>&1 || {
echo 'ffmpeg is required but was not found in PATH.' >&2
exit 1
}
if $webcam_only; then
video_source=( -i /dev/video0 )
else
command -v xdpyinfo >/dev/null 2>&1 || {
echo 'xdpyinfo is required to capture desktop size.' >&2
exit 1
}
screen_size=$(xdpyinfo | awk '/dimensions/{print $2; exit}')
video_source=( -f x11grab -s "$screen_size" -i :0.0 )
fi
if [[ -f "$PIDFILE" ]] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo 'A recording session is already running. Use -s to stop it.' >&2
exit 1
fi
ffmpeg -y -nostdin "${video_source[@]}" "${audio_source[@]}" \
"${video_encoder[@]}" "${audio_encoder[@]}" "$output_name" >/dev/null 2>&1 &
echo "$!" > "$PIDFILE"
echo "Recording started: $output_name"