From bae4504370f335d64697a8d114174134b44d5f98 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 15 Oct 2023 18:11:47 +0200 Subject: [PATCH] Install systemd service in install script, skip empty audio device Stop systemd service with SIGINT --- README.md | 10 ++++------ TODO | 6 ++++++ extra/gpu-screen-recorder.service | 1 + install.sh | 3 +++ src/main.cpp | 3 +++ uninstall.sh | 1 + 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e224606..2202a8b 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,11 @@ Run the script `scripts/start-replay.sh` to start replay and then `scripts/save- You can use these scripts to start replay at system startup if you add `scripts/start-replay.sh` to startup (this can be done differently depending on your desktop environment / window manager) and then go into hotkey settings on your system and choose a hotkey to run the script `scripts/save-replay.sh`. Modify `scripts/start-replay.sh` if you want to use other replay options. ## Run replay on system startup -If you are running a distro that uses systemd then you can use the systemd service in `extra/gpu-screen-recorder.service`. -Copy `extra/gpu-screen-recorder.service` to a location where systemd can find it, for example: `$HOME/.config/systemd/user` and then enable and start it with: `systemctl enable --now --user gpu-screen-recorder`. Copying the systemd service file is not needed if you installed GPU Screen Recorder from AUR as this is done automatically. -You can then use the `scripts/save-replay.sh` script to save a replay. The systemd service is configured with the file `$HOME/.config/gpu-screen-recorder.env` (create it if it doesn't exist). -You can see which variables that you can use by looking at the gpu-screen-recorder.service file. In general you only need to set the `WINDOW` variable to make it work. -Restart the systemd service after modifying that configuration file. By default it saves videos in `$HOME/Videos`.\ +If you are running a distro that uses systemd then the `install.sh` script installs `extra/gpu-screen-recorder.service` on the system and that systemd service can be started with `systemctl enable --now --user gpu-screen-recorder` +and it's configured with `$HOME/.config/gpu-screen-recorder.env` (create it if it doesn't exist). +You can see which variables that you can use in the `gpu-screen-recorder.env` file by looking at the `extra/gpu-screen-recorder.service` file. In general you only need to set the `WINDOW` variable to a monitor to make it work. +You can use the `scripts/save-replay.sh` script to save a replay and by default the systemd service saves files in `$HOME/Videos`.\ If you are using a NVIDIA GPU then it's recommended to set PreserveVideoMemoryAllocations=1 as mentioned in the section below. - ## Issues ### NVIDIA Nvidia drivers have an issue where CUDA breaks if CUDA is running when suspend/hibernation happens, and it remains broken until you reload the nvidia driver. To fix this, either disable suspend or tell the NVIDIA driver to preserve video memory on suspend/hibernate by using the `NVreg_PreserveVideoMemoryAllocations=1` option. You can run `sudo extra/install_preserve_video_memory.sh` to automatically add that option to your system. diff --git a/TODO b/TODO index 6f1ce79..fe3fb46 100644 --- a/TODO +++ b/TODO @@ -93,3 +93,9 @@ Preset is set to p5 for now but it should ideally be p6 or p7. For low latency, see https://developer.download.nvidia.com/compute/nvenc/v4.0/NVENC_VideoEncoder_API_ProgGuide.pdf (section 7.1). Remove follow focused option. + +Fix kms capture on 10-bit setup (both x11 and wayland). It may already work automatically on amd/intel, but on nvidia the color conversion shader needs to be used to automatically map 10-bit to 8-bit. + +Test vaapi av1 encoding (av1_vaapi) (which was recently added to ffmpeg master). + +Overclocking (-oc) can overclock too much on some systems. Maybe remove the option? \ No newline at end of file diff --git a/extra/gpu-screen-recorder.service b/extra/gpu-screen-recorder.service index b644bc8..7f1cbb1 100644 --- a/extra/gpu-screen-recorder.service +++ b/extra/gpu-screen-recorder.service @@ -14,6 +14,7 @@ Environment=REPLAYDURATION=60 Environment=OUTPUTDIR=%h/Videos Environment=MAKEFOLDERS=no ExecStart=/bin/sh -c 'AUDIO="${AUDIO_DEVICE:-$(pactl get-default-sink).monitor}"; gpu-screen-recorder -v no -w $WINDOW -c $CONTAINER -q $QUALITY -k $CODEC -ac $AUDIO_CODEC -a "$AUDIO" -f $FRAMERATE -r $REPLAYDURATION -o "$OUTPUTDIR" -mk $MAKEFOLDERS $ADDITIONAL_ARGS' +KillSignal=SIGINT Restart=on-failure RestartSec=5s diff --git a/install.sh b/install.sh index 1ea57bf..c82ad44 100755 --- a/install.sh +++ b/install.sh @@ -11,6 +11,9 @@ strip gpu-screen-recorder install -Dm755 "gsr-kms-server" "/usr/bin/gsr-kms-server" install -Dm755 "gpu-screen-recorder" "/usr/bin/gpu-screen-recorder" +if [ -d "/usr/lib/systemd/user" ]; then + install -Dm644 "extra/gpu-screen-recorder.service" "/usr/lib/systemd/user/gpu-screen-recorder.service" +fi setcap cap_sys_admin+ep /usr/bin/gsr-kms-server setcap cap_sys_nice+ep /usr/bin/gpu-screen-recorder diff --git a/src/main.cpp b/src/main.cpp index 2bbfd06..86567d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1308,6 +1308,9 @@ int main(int argc, char **argv) { // Pipewire instead DEFAULTS TO THE DEFAULT AUDIO INPUT. THAT'S RETARDED. // OH, YOU MISSPELLED THE AUDIO INPUT? FUCK YOU for(const char *audio_input : audio_input_arg.values) { + if(!audio_input || audio_input[0] == '\0') + continue; + requested_audio_inputs.push_back({parse_audio_input_arg(audio_input)}); for(AudioInput &request_audio_input : requested_audio_inputs.back().audio_inputs) { bool match = false; diff --git a/uninstall.sh b/uninstall.sh index 6578baa..9457d1f 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -4,5 +4,6 @@ rm -f "/usr/bin/gsr-kms-server" rm -f "/usr/bin/gpu-screen-recorder" +rm -f "/usr/lib/systemd/user/gpu-screen-recorder.service" echo "Successfully uninstalled gpu-screen-recorder" \ No newline at end of file