-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreenrecorder
executable file
·59 lines (52 loc) · 1.63 KB
/
screenrecorder
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
#!/usr/bin/env bash
# Copyright 2024 Raffaele Mancuso
# SPDX-License-Identifier: MIT
# Requires wf-recorder: https://github.com/ammen99/wf-recorder
SIGNAL=1
pidf="/tmp/waybar-screenrecorder"
WF_RECORDER_OPTS=""
# Insert `--audio` if you want to record audio
# Specify video codec
# find available video codecs with `ffmpeg -encoders`
WF_RECORDER_OPTS="$WF_RECORDER_OPTS --codec libvpx"
# Specify audio codec
# find available audio codecs with `ffmpeg -codecs`
# WF_RECORDER_OPTS="$WF_RECORDER_OPTS --audio --codec opus"
# printf "WF_RECORDER_OPTS=%s\n" "$WF_RECORDER_OPTS"
VIDEOEXT="webm"
if [ "$1" == "status" ]; then
if [ -s "$pidf" ]; then
awk 'BEGIN{printf "{\"text\":\"\", \"tooltip\":\"Recording\\n"}
NR==1{printf "PID: %s\\n", $0}
NR==2{printf "Save to: %s\\n", $0}
NR==3{printf "Log to: %s\"}\n", $0}' "$pidf"
else
printf '{"text":"", "tooltip":"Stopped"}\n'
fi
elif [ "$1" == "toggle" ]; then
if [ -s "$pidf" ]; then
pid=$(awk 'NR==1' "$pidf")
kill "$pid"
printf "" > "$pidf"
else
mkdir -p "$HOME/Videos/Screencasts"
bf="$HOME/Videos/Screencasts/$(date +'%Y%m%dT%H%M%S')"
vidf="$bf.$VIDEOEXT"
logf="$bf.log"
if [ "$2" == "fullscreen" ]; then
wf-recorder $WF_RECORDER_OPTS --file "$vidf" 1>"$logf" 2>&1 &
elif [ "$2" == "region" ]; then
sleep 1
wf-recorder $WF_RECORDER_OPTS --geometry "$(slurp)" --file "$vidf" 1>"$logf" 2>&1 &
else
printf "Argument \$2='%s' not valid (fullscreen/region)" "$2"
exit
fi
pid=$(jobs -p | tail -n 1)
printf "%d\n%s\n%s" "$pid" "$vidf" "$logf" > "$pidf"
disown "$pid"
fi
pkill -RTMIN+$SIGNAL waybar
else
printf "ERROR: Argument %s not valid\n" "$1"
fi