mirror of
https://github.com/quantum5/wayland-recorder.git
synced 2025-04-24 12:11:57 -04:00
feat(app): Added flags to enable audio and to use only one script
The script can now be run with optional flag to enable audio in the screen recording. The flag can be passed to check if the recording is on (for the waybar module). This allows only one script to be used for everything.
This commit is contained in:
parent
5795cd5484
commit
c889afb92b
86
README.md
86
README.md
|
@ -1,44 +1,84 @@
|
|||
# `wayland-recorder`
|
||||
Scripts to use with `wf-recorder` and `waybar` for screen recording
|
||||
|
||||
Scripts to use with `wf-recorder` and `waybar` for screen recording.
|
||||
|
||||
## Dependencies
|
||||
|
||||
* [`slurp`](https://github.com/emersion/slurp)
|
||||
* [`wf-recorder`](https://github.com/ammen99/wf-recorder)
|
||||
- [`slurp`](https://github.com/emersion/slurp)
|
||||
- [`wf-recorder`](https://github.com/ammen99/wf-recorder)
|
||||
|
||||
[`waybar`](https://github.com/Alexays/Waybar) can optionally be used to show
|
||||
that a recording is in progress, but is not strictly necessary.
|
||||
[`waybar`](https://github.com/Alexays/Waybar) can optionally be used to show that a recording is in progress, but is not strictly necessary.
|
||||
|
||||
## Setup
|
||||
|
||||
[`record-screen`](record-screen) is the main script. It is intended to be
|
||||
bound to a hot key. Upon the first invocation, it runs `slurp` to let you
|
||||
select an area of the screen to record, and then runs `wf-recorder` in the
|
||||
background. By default, it records to `~/Videos/Recordings`, but this can be
|
||||
changed by editing the script. On a second invocation, it stops the
|
||||
recording.
|
||||
[`record-screen`](record-screen) is the main script. It is intended to be bound to a hotkey. Upon the first invocation, it runs `slurp` to let you select an area of the screen to record, and then runs `wf-recorder` in the background. By default, it records to `~/vids/recordings`, but this can be changed by editing the script. On a second invocation, it stops the recording.
|
||||
|
||||
To use it, you can, for example, configure `sway` as such:
|
||||
### New Flags:
|
||||
|
||||
- `-c` or `--check`: Checks if a recording is in progress and prints the status.
|
||||
- `-a` or `--audio`: Records audio only (no screen recording).
|
||||
- Default behavior (without flags) starts a screen recording after selecting the area via `slurp`.
|
||||
|
||||
### Usage:
|
||||
|
||||
- **To start a screen recording**:
|
||||
Simply run the script or bind it to a hotkey. The first time you run it, it will prompt you to select the screen area and start the recording.
|
||||
|
||||
```bash
|
||||
./record-screen
|
||||
```
|
||||
|
||||
- **To stop an ongoing recording**:
|
||||
Running the script again will stop the recording.
|
||||
|
||||
```bash
|
||||
./record-screen
|
||||
```
|
||||
|
||||
- **To start an audio-only recording**:
|
||||
Pass the `-a` or `--audio` flag to the script to start recording audio only (no screen capture).
|
||||
|
||||
```bash
|
||||
./record-screen --audio
|
||||
```
|
||||
|
||||
- **To check if a recording is currently in progress**:
|
||||
Use the `-c` or `--check` flag to see if a recording is currently active.
|
||||
```bash
|
||||
./record-screen --check
|
||||
```
|
||||
|
||||
### Example Keybinding for `sway`:
|
||||
|
||||
You can configure the script to be executed via a hotkey, for example with the following line in your `sway` configuration:
|
||||
|
||||
```bash
|
||||
bindsym $mod+print exec exec <path to record-screen>
|
||||
```
|
||||
|
||||
This will start/stop the screen recording upon each key press.
|
||||
|
||||
## Waybar integration
|
||||
|
||||
[`record-screend`](record-screend) can be used to create a custom waybar
|
||||
widget which shows if a recording is in progress.
|
||||
[`record-screen -c`](record-screen) can be used to create a custom waybar widget that shows if a recording is in progress.
|
||||
|
||||
This is an example configuration:
|
||||
Here's an example configuration for `waybar`:
|
||||
|
||||
```json
|
||||
"custom/recording": {
|
||||
"exec": "exec <path to record-screend>",
|
||||
"exec-on-event": false,
|
||||
"on-click": "pkill -INT -P \"$(pgrep -xo record-screen)\" wf-recorder"
|
||||
},
|
||||
"exec": "~/.local/bin/record-screen -c",
|
||||
"interval": 1,
|
||||
"tooltip-format": "Recording ON!",
|
||||
"on-click": "~/.local/bin/record-screen"
|
||||
}
|
||||
```
|
||||
|
||||
This configuration also allows you to terminate the current recording by
|
||||
simply clicking the message.
|
||||
### Explanation:
|
||||
|
||||
Note that the script attempts to display an icon with Font Awesome. If this
|
||||
is not desired, the script could be edited to remove it.
|
||||
- `"exec"` runs the script with the `-c` flag every second to check if a recording is in progress.
|
||||
- `"on-click"` will execute the script without flags, which will stop the current recording when clicked.
|
||||
- `"interval": 1` updates the status every second.
|
||||
|
||||
This configuration also allows you to terminate the current recording by simply clicking the widget.
|
||||
|
||||
Note that the script attempts to display an icon with Font Awesome. If this is not desired, the script could be edited to remove the icon.
|
||||
|
|
|
@ -1,10 +1,50 @@
|
|||
#!/bin/bash
|
||||
if ! pkill -INT -P "$(pgrep -xo record-screen)" wf-recorder 2>/dev/null; then
|
||||
geometry="$(slurp -d)"
|
||||
if [ -n "$geometry" ]; then
|
||||
pkill -USR1 -x record-screend
|
||||
mkdir -p ~/Videos/Recordings
|
||||
wf-recorder -f ~/Videos/Recordings/"screen-record-$(date +%Y-%m-%d-%H-%M-%S).mp4" -g "$geometry"
|
||||
pkill -USR2 -x record-screend
|
||||
|
||||
# Get the process ID of the running wf-recorder
|
||||
recording_pid=$(pgrep -xo wf-recorder)
|
||||
|
||||
# Check if -a or --audio is passed for audio-only recording
|
||||
audio_only=false
|
||||
if [[ "$1" == "-a" || "$1" == "--audio" ]]; then
|
||||
audio_only=true
|
||||
fi
|
||||
|
||||
# Function to handle errors gracefully
|
||||
error_exit() {
|
||||
notify-send "Screen Recording" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Handle the --check (-c) flag
|
||||
if [[ "$1" == "-c" || "$1" == "--check" ]]; then
|
||||
if [[ -n "$recording_pid" ]]; then
|
||||
echo " Recording"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Stop recording if already running
|
||||
if [[ -n "$recording_pid" ]]; then
|
||||
kill "$recording_pid" && notify-send "Screen Recording" "Recording stopped" || error_exit "Failed to stop recording :/"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the screen geometry using `slurp`
|
||||
geometry="$(slurp -d)" || error_exit "Failed to capture screen geometry :/"
|
||||
|
||||
if [[ -n "$geometry" ]]; then
|
||||
# Create the recordings directory if it doesn't exist
|
||||
recordings_dir=~/vids/recordings
|
||||
mkdir -p "$recordings_dir" || error_exit "Failed to create directory: $recordings_dir :/"
|
||||
|
||||
# Start recording using wf-recorder
|
||||
if [[ "$audio_only" == true ]]; then
|
||||
wf-recorder -a -f "$recordings_dir/screen-record-$(date +%Y-%m-%d-%H-%M-%S).mp4" -g "$geometry" || \
|
||||
error_exit "Failed to start screen recording :/"
|
||||
else
|
||||
wf-recorder -f "$recordings_dir/screen-record-$(date +%Y-%m-%d-%H-%M-%S).mp4" -g "$geometry" || \
|
||||
error_exit "Failed to start screen recording :/"
|
||||
fi
|
||||
else
|
||||
error_exit "No geometry selected :/"
|
||||
fi
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
recordings=0
|
||||
|
||||
update() {
|
||||
if [ "$recordings" -gt 0 ]; then
|
||||
echo " Recording"
|
||||
else
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
begin_record() {
|
||||
recordings=$((recordings + 1))
|
||||
update
|
||||
}
|
||||
|
||||
end_record() {
|
||||
recordings=$((recordings - 1))
|
||||
update
|
||||
}
|
||||
|
||||
exec sleep infinity &
|
||||
|
||||
pid="$!"
|
||||
trap begin_record SIGUSR1
|
||||
trap end_record SIGUSR2
|
||||
trap "kill $pid" EXIT
|
||||
|
||||
while :; do
|
||||
wait "$pid"
|
||||
done
|
Loading…
Reference in a new issue