-
Notifications
You must be signed in to change notification settings - Fork 1
/
screenrec.sh
executable file
·49 lines (44 loc) · 1.14 KB
/
screenrec.sh
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
#!/bin/bash
rec_date=$(date +%Y-%m-%d_%H-%M-%S)
output_file="$rec_date.mp4"
flag_file="recording.flag"
pid_file="wf-recorder.pid"
start_recording() {
if [ -e "$flag_file" ]; then
echo "Recording is already in progress. Press Ctrl+C to stop."
else
touch "$flag_file"
echo "Recording started. Press Ctrl+C to stop."
wf-recorder -f "$output_file" -x yuv420p &
echo $! > "$pid_file" # Save the PID of the wf-recorder process
fi
}
stop_recording() {
if [ -e "$pid_file" ]; then
echo "Stopping recording..."
kill $(cat "$pid_file") # Terminate the wf-recorder process using its PID
rm "$pid_file"
rm "$flag_file"
echo "Recording stopped. Video saved to $output_file"
else
echo "No recording in progress."
fi
}
# Check if arguments are provided
if [ "$#" -eq 0 ]; then
echo "Usage: $0 [start|stop]"
exit 1
fi
# Process command line arguments
case "$1" in
"start")
start_recording
;;
"stop")
stop_recording
;;
*)
echo "Invalid argument. Usage: $0 [start|stop]"
exit 1
;;
esac