@@ -8,15 +8,17 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
88 exit 1
99fi
1010
11- SCOPE= " "
12- AUDIO =" false"
11+ DESKTOP_AUDIO= " false "
12+ MICROPHONE_AUDIO =" false"
1313WEBCAM=" false"
14+ STOP_RECORDING=" false"
1415
1516for arg in " $@ " ; do
1617 case " $arg " in
17- --with-audio) AUDIO=" true" ;;
18+ --with-desktop-audio) DESKTOP_AUDIO=" true" ;;
19+ --with-microphone-audio) MICROPHONE_AUDIO=" true" ;;
1820 --with-webcam) WEBCAM=" true" ;;
19- output|region) SCOPE= " $arg " ;;
21+ --stop-recording) STOP_RECORDING= " true "
2022 esac
2123done
2224
@@ -57,27 +59,35 @@ start_webcam_overlay() {
5759
5860start_screenrecording () {
5961 local filename=" $OUTPUT_DIR /screenrecording-$( date +' %Y-%m-%d_%H-%M-%S' ) .mp4"
62+ local audio_devices=" "
6063 local audio_args=" "
6164
62- # Merge audio tracks into one - separate tracks only play one at a time in most players
63- [[ " $AUDIO " == " true" ]] && audio_args=" -a default_output|default_input"
65+ [[ " $DESKTOP_AUDIO " == " true" ]] && audio_devices+=" default_output"
6466
65- gpu-screen-recorder -w " $@ " -f 60 -c mp4 -o " $filename " $audio_args &
67+ if [[ " $MICROPHONE_AUDIO " == " true" ]]; then
68+ # Merge audio tracks into one - separate tracks only play one at a time in most players
69+ [[ -n " $audio_devices " ]] && audio_devices+=" |"
70+ audio_devices+=" default_input"
71+ fi
72+
73+ [[ -n " $audio_devices " ]] && audio_args+=" -a $audio_devices "
74+
75+ gpu-screen-recorder -w portal -f 60 -fallback-cpu-encoding yes -o " $filename " $audio_args -ac aac &
6676 toggle_screenrecording_indicator
6777}
6878
6979stop_screenrecording () {
70- pkill -SIGINT -f " gpu-screen-recorder" # SIGINT required to save video properly
80+ pkill -SIGINT -f " ^ gpu-screen-recorder" # SIGINT required to save video properly
7181
7282 # Wait a maximum of 5 seconds to finish before hard killing
7383 local count=0
74- while pgrep -f " gpu-screen-recorder" > /dev/null && [ $count -lt 50 ]; do
84+ while pgrep -f " ^ gpu-screen-recorder" > /dev/null && [ $count -lt 50 ]; do
7585 sleep 0.1
7686 count=$(( count + 1 ))
7787 done
7888
79- if pgrep -f " gpu-screen-recorder" > /dev/null; then
80- pkill -9 -f " gpu-screen-recorder"
89+ if pgrep -f " ^ gpu-screen-recorder" > /dev/null; then
90+ pkill -9 -f " ^ gpu-screen-recorder"
8191 cleanup_webcam
8292 notify-send " Screen recording error" " Recording process had to be force-killed. Video may be corrupted." -u critical -t 5000
8393 else
@@ -92,51 +102,19 @@ toggle_screenrecording_indicator() {
92102}
93103
94104screenrecording_active () {
95- pgrep -f " gpu-screen-recorder" > /dev/null || pgrep -x slurp > /dev/null || pgrep -f " WebcamOverlay" > /dev/null
105+ pgrep -f " ^ gpu-screen-recorder" > /dev/null || pgrep -f " WebcamOverlay" > /dev/null
96106}
97107
98108if screenrecording_active; then
99- if pgrep -x slurp > /dev/null; then
100- pkill -x slurp 2> /dev/null
101- elif pgrep -f " WebcamOverlay" > /dev/null && ! pgrep -f " gpu-screen-recorder" > /dev/null; then
109+ if pgrep -f " WebcamOverlay" > /dev/null && ! pgrep -f " ^gpu-screen-recorder" > /dev/null; then
102110 cleanup_webcam
103111 else
104112 stop_screenrecording
105113 fi
106- elif [[ " $SCOPE " == " output " ]]; then
114+ elif [[ " $STOP_RECORDING " == " false " ]]; then
107115 [[ " $WEBCAM " == " true" ]] && start_webcam_overlay
108116
109- if ! output=$( slurp -o -f " %o" ) ; then
110- [[ " $WEBCAM " == " true" ]] && cleanup_webcam
111- exit 1
112- fi
113-
114- if [[ -z " $output " ]]; then
115- notify-send " Error" " Could not detect monitor" -u critical
116- [[ " $WEBCAM " == " true" ]] && cleanup_webcam
117- exit 1
118- fi
119-
120- start_screenrecording " $output "
117+ start_screenrecording || cleanup_webcam
121118else
122- [[ " $WEBCAM " == " true" ]] && start_webcam_overlay
123-
124- scale=$( hyprctl monitors -j | jq -r ' .[] | select(.focused == true) | .scale' )
125-
126- if ! region=$( slurp -f " %wx%h+%x+%y" ) ; then
127- [[ " $WEBCAM " == " true" ]] && cleanup_webcam
128- exit 1
129- fi
130-
131- if [[ " $region " =~ ^([0-9]+)x([0-9]+)\+ ([0-9]+)\+ ([0-9]+)$ ]]; then
132- w=$( awk " BEGIN {printf \" %.0f\" , ${BASH_REMATCH[1]} * $scale }" )
133- h=$( awk " BEGIN {printf \" %.0f\" , ${BASH_REMATCH[2]} * $scale }" )
134- x=$( awk " BEGIN {printf \" %.0f\" , ${BASH_REMATCH[3]} * $scale }" )
135- y=$( awk " BEGIN {printf \" %.0f\" , ${BASH_REMATCH[4]} * $scale }" )
136- scaled_region=" ${w} x${h} +${x} +${y} "
137- else
138- scaled_region=" $region "
139- fi
140-
141- start_screenrecording region -region " $scaled_region "
119+ exit 1
142120fi
0 commit comments