From 968899c41093025ac1eda615b1ce53b1fc55eb48 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sun, 22 Dec 2024 06:50:15 +0300 Subject: [PATCH] Screenrec: Use h264 for partial rec and av1 for fullscreen. --- home/file/sway/default.nix | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/home/file/sway/default.nix b/home/file/sway/default.nix index 07d60bca..bed9e40c 100644 --- a/home/file/sway/default.nix +++ b/home/file/sway/default.nix @@ -24,6 +24,7 @@ let container = "mp4"; format = "%Y-%m-%d_%H-%M-%S"; framerate = 30; + keyint = framerate * 5; opacity = "26"; pixfmt = "yuv420p10le"; selection = "slurp -d -b ${color.bg.light}${opacity} -c ${color.fg.light} -w 0 -s 00000000"; @@ -80,13 +81,35 @@ let [[ "''${scrTransform}" = "normal" ]] && scrTransform="" ''; - vidStart = '' + vidStart = extra: '' wf-recorder \ + --codec h264_vaapi \ + --device /dev/dri/renderD128 \ --no-damage \ - --codec ${codec} \ - --file "''${scrFile}" \ --framerate ${toString framerate} \ - --pixel-format ${pixfmt} \ + --file "''${scrFile}" \ + ${extra} || + wf-recorder \ + --codec libx264 \ + --no-damage \ + --framerate ${toString framerate} \ + --file "''${scrFile}" \ + ${extra} + ''; + + # NOTE: Only fullscreen rec is re-encoded. + vidEncode = '' + ffmpeg \ + -i "''${scrFile}" \ + -c:v ${codec} \ + -svtav1-params "tune=0" \ + -pix_fmt ${pixfmt} \ + -g ${toString keyint} \ + -f ${container} \ + -vf "fps=${toString framerate}" \ + "''${scrFile}_" \ + && mv "''${scrFile}_" "''${scrFile}" \ + || rm "''${scrFile}_" ''; vidMuxAudio = '' @@ -123,7 +146,7 @@ let ${vidPrepFile} ${notifyStart} ${updateWaybar} - ${vidStart} ${vidSelected} + ${vidStart vidSelected} ${notifyEnd} ${updateWaybar} ${vidMuxAudio} @@ -138,9 +161,10 @@ let ${vidPrepFile} ${notifyStart} ${updateWaybar} - ${vidStart} ${vidFull} + ${vidStart vidFull} ${notifyEnd} ${updateWaybar} + ${vidEncode} ${vidMuxAudio} ${vidTransform} ${vidRefLatestFile}