diff options
| author | Batuhan Edgüer <67585935+BestSithInEU@users.noreply.github.com> | 2025-08-16 11:05:02 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-16 18:05:02 +1000 |
| commit | 651efcd137077cf38a8dfc1a20e7cf2f8ad20606 (patch) | |
| tree | 0d21ab7ff927908f080d9fd5c70f8504689a0501 /src | |
| parent | toggle: improvements (diff) | |
| download | caelestia-cli-651efcd137077cf38a8dfc1a20e7cf2f8ad20606.tar.gz caelestia-cli-651efcd137077cf38a8dfc1a20e7cf2f8ad20606.tar.bz2 caelestia-cli-651efcd137077cf38a8dfc1a20e7cf2f8ad20606.zip | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/caelestia/subcommands/record.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/caelestia/subcommands/record.py b/src/caelestia/subcommands/record.py index b7f0f65..f251cf3 100644 --- a/src/caelestia/subcommands/record.py +++ b/src/caelestia/subcommands/record.py @@ -11,9 +11,34 @@ from caelestia.utils.paths import recording_notif_path, recording_path, recordin class Command: args: Namespace + recorder: str def __init__(self, args: Namespace) -> None: 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: if self.proc_running(): @@ -22,7 +47,7 @@ class Command: self.start() 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: args = [] @@ -43,7 +68,10 @@ class Command: sources = subprocess.check_output(["pactl", "list", "short", "sources"], text=True).splitlines() for source in sources: 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 else: raise ValueError("No audio source found") @@ -66,7 +94,7 @@ class Command: def stop(self) -> None: # Start killing recording process - subprocess.run(["pkill", "wl-screenrec"]) + subprocess.run(["pkill", self.recorder]) # Wait for recording to finish to avoid corrupted video file while self.proc_running(): |