mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-11 09:49:32 -05:00
record: add NVIDIA GPU support with wf-recorder (#41)
* record: add NVIDIA GPU support with wf-recorder - Add automatic GPU detection to choose between wl-screenrec and wf-recorder - Use wf-recorder for NVIDIA GPUs to fix compatibility issues - Map wf-recorder arguments correctly for region, output, and audio recording - Update documentation to include wf-recorder as dependency for NVIDIA users Fixes #37 * format + deduplicate --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,8 @@ The main control script for the Caelestia dotfiles.
|
|||||||
- [`app2unit`](https://github.com/Vladimir-csp/app2unit) - launching apps
|
- [`app2unit`](https://github.com/Vladimir-csp/app2unit) - launching apps
|
||||||
- [`wl-clipboard`](https://github.com/bugaevc/wl-clipboard) - copying to clipboard
|
- [`wl-clipboard`](https://github.com/bugaevc/wl-clipboard) - copying to clipboard
|
||||||
- [`slurp`](https://github.com/emersion/slurp) - selecting an area
|
- [`slurp`](https://github.com/emersion/slurp) - selecting an area
|
||||||
- [`wl-screenrec`](https://github.com/russelltg/wl-screenrec) - screen recording
|
- [`wl-screenrec`](https://github.com/russelltg/wl-screenrec) - screen recording (default)
|
||||||
|
- [`wf-recorder`](https://github.com/ammen99/wf-recorder) - screen recording (for NVIDIA GPUs)
|
||||||
- `glib2` - closing notifications
|
- `glib2` - closing notifications
|
||||||
- `libpulse` - getting audio device
|
- `libpulse` - getting audio device
|
||||||
- [`cliphist`](https://github.com/sentriz/cliphist) - clipboard history
|
- [`cliphist`](https://github.com/sentriz/cliphist) - clipboard history
|
||||||
@@ -44,7 +45,7 @@ Install all [dependencies](#dependencies), then install
|
|||||||
e.g. via an AUR helper (yay)
|
e.g. via an AUR helper (yay)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
yay -S libnotify swappy grim dart-sass app2unit wl-clipboard slurp wl-screenrec glib2 libpulse cliphist fuzzel python-build python-installer python-hatch python-hatch-vcs
|
yay -S libnotify swappy grim dart-sass app2unit wl-clipboard slurp wl-screenrec wf-recorder glib2 libpulse cliphist fuzzel python-build python-installer python-hatch python-hatch-vcs
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, clone the repo, `cd` into it, build the wheel via `python -m build --wheel`
|
Now, clone the repo, `cd` into it, build the wheel via `python -m build --wheel`
|
||||||
|
|||||||
@@ -11,9 +11,34 @@ from caelestia.utils.paths import recording_notif_path, recording_path, recordin
|
|||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
args: Namespace
|
args: Namespace
|
||||||
|
recorder: str
|
||||||
|
|
||||||
def __init__(self, args: Namespace) -> None:
|
def __init__(self, args: Namespace) -> None:
|
||||||
self.args = args
|
self.args = args
|
||||||
|
self.recorder = self._detect_recorder()
|
||||||
|
|
||||||
|
def _detect_recorder(self) -> str:
|
||||||
|
"""Detect which screen recorder to use based on GPU."""
|
||||||
|
try:
|
||||||
|
# Check for NVIDIA GPU
|
||||||
|
lspci_output = subprocess.check_output(["lspci"], text=True)
|
||||||
|
if "nvidia" in lspci_output.lower():
|
||||||
|
# Check if wf-recorder is available
|
||||||
|
if shutil.which("wf-recorder"):
|
||||||
|
return "wf-recorder"
|
||||||
|
|
||||||
|
# Default to wl-screenrec if available
|
||||||
|
if shutil.which("wl-screenrec"):
|
||||||
|
return "wl-screenrec"
|
||||||
|
|
||||||
|
# Fallback to wf-recorder if wl-screenrec is not available
|
||||||
|
if shutil.which("wf-recorder"):
|
||||||
|
return "wf-recorder"
|
||||||
|
|
||||||
|
raise RuntimeError("No compatible screen recorder found")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# If lspci fails, default to wl-screenrec
|
||||||
|
return "wl-screenrec" if shutil.which("wl-screenrec") else "wf-recorder"
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
if self.proc_running():
|
if self.proc_running():
|
||||||
@@ -22,7 +47,7 @@ class Command:
|
|||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def proc_running(self) -> bool:
|
def proc_running(self) -> bool:
|
||||||
return subprocess.run(["pidof", "wl-screenrec"], stdout=subprocess.DEVNULL).returncode == 0
|
return subprocess.run(["pidof", self.recorder], stdout=subprocess.DEVNULL).returncode == 0
|
||||||
|
|
||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
args = []
|
args = []
|
||||||
@@ -43,7 +68,10 @@ class Command:
|
|||||||
sources = subprocess.check_output(["pactl", "list", "short", "sources"], text=True).splitlines()
|
sources = subprocess.check_output(["pactl", "list", "short", "sources"], text=True).splitlines()
|
||||||
for source in sources:
|
for source in sources:
|
||||||
if "RUNNING" in source:
|
if "RUNNING" in source:
|
||||||
args += ["--audio", "--audio-device", source.split()[1]]
|
if self.recorder == "wf-recorder":
|
||||||
|
args += ["-a", source.split()[1]]
|
||||||
|
else:
|
||||||
|
args += ["--audio", "--audio-device", source.split()[1]]
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
raise ValueError("No audio source found")
|
raise ValueError("No audio source found")
|
||||||
@@ -66,7 +94,7 @@ class Command:
|
|||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
# Start killing recording process
|
# Start killing recording process
|
||||||
subprocess.run(["pkill", "wl-screenrec"])
|
subprocess.run(["pkill", self.recorder])
|
||||||
|
|
||||||
# Wait for recording to finish to avoid corrupted video file
|
# Wait for recording to finish to avoid corrupted video file
|
||||||
while self.proc_running():
|
while self.proc_running():
|
||||||
|
|||||||
Reference in New Issue
Block a user