record: switch to wl-screenrec

Is better
This commit is contained in:
2 * r + 2 * t
2025-05-01 19:42:45 +10:00
parent 1d60df6aa1
commit b3667476ad
2 changed files with 25 additions and 55 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
. (dirname (status filename))/util.fish . (dirname (status filename))/util.fish
install-deps git hyprland-git hyprpaper-git imagemagick wl-clipboard fuzzel-git socat foot jq python xdg-user-dirs python-materialyoucolor-git app2unit-git install-deps git hyprland-git hyprpaper-git imagemagick wl-clipboard fuzzel-git socat foot jq python xdg-user-dirs python-materialyoucolor-git app2unit-git
install-optional-deps 'equibop-bin (discord client)' 'btop (system monitor)' 'wf-recorder (screen recorder)' 'grim (screenshot tool)' 'zen-browser (web browser)' 'spotify-adblock (music player)' install-optional-deps 'equibop-bin (discord client)' 'btop (system monitor)' 'wl-screenrec (screen recorder)' 'grim (screenshot tool)' 'zen-browser (web browser)'
set -l dist $C_DATA/scripts set -l dist $C_DATA/scripts
+24 -54
View File
@@ -1,31 +1,22 @@
#!/bin/fish #!/bin/fish
function get-audio-source function get-audio-source
pactl list sources | grep 'Name' | grep 'monitor' | cut -d ' ' -f2 pactl list short sources | grep '\.monitor.*RUNNING' | cut -f 2 | head -1
end
function get-region
slurp || exit 0
end end
function get-active-monitor function get-active-monitor
hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .name' hyprctl monitors -j | jq -r '.[] | select(.focused == true) | .name'
end end
function has-gpu
test -e /dev/dri/renderD128
end
function supports-codec -a codec
ffmpeg -hide_banner -encoders | grep -E '^ V' | grep -F '(codec' | grep $codec >/dev/null
end
function supports-gpu-codecs
supports-codec hevc_vaapi || supports-codec h264_vaapi
end
argparse -n 'caelestia-record' -X 0 \ argparse -n 'caelestia-record' -X 0 \
'h/help' \ 'h/help' \
's/sound' \ 's/sound' \
'r/region=?' \ 'r/region=?' \
'c/compression=!_validate_int' \ 'n/no-hwaccel' \
'H/hwaccel' \
-- $argv -- $argv
or exit or exit
@@ -35,29 +26,28 @@ if set -q _flag_h
echo ' caelestia record [ -s | --sound ] [ -r | --region ] [ -c | --compression ] [ -H | --hwaccel ]' echo ' caelestia record [ -s | --sound ] [ -r | --region ] [ -c | --compression ] [ -H | --hwaccel ]'
echo echo
echo 'Options:' echo 'Options:'
echo ' -h, --help Print this help message and exit' echo ' -h, --help Print this help message and exit'
echo ' -s, --sound Enable audio capturing' echo ' -s, --sound Enable audio capturing'
echo ' -r, --region [ <region> ] The region to capture, current monitor if option not given, default region slurp' echo ' -r, --region [ <region> ] The region to capture, current monitor if option not given, default region slurp'
echo ' -c, --compression <compression> Use given compression level, lower = better quality, higher = better compression' echo ' -N, --no-hwaccel Do not use the GPU encoder'
echo ' -H, --hwaccel Use hardware acceleration if available'
exit exit
end end
. (dirname (status filename))/util.fish . (dirname (status filename))/util.fish
set storage_dir (xdg-user-dir VIDEOS)/Recordings set -l storage_dir (xdg-user-dir VIDEOS)/Recordings
set state_dir $C_STATE/record set -l state_dir $C_STATE/record
mkdir -p $storage_dir mkdir -p $storage_dir
mkdir -p $state_dir mkdir -p $state_dir
set file_ext 'mp4' set -l file_ext 'mp4'
set recording_path "$state_dir/recording.$file_ext" set -l recording_path "$state_dir/recording.$file_ext"
set notif_id_path "$state_dir/notifid.txt" set -l notif_id_path "$state_dir/notifid.txt"
if pgrep wf-recorder > /dev/null if pgrep wl-screenrec > /dev/null
pkill wf-recorder pkill wl-screenrec
# Move to recordings folder # Move to recordings folder
set -l new_recording_path "$storage_dir/recording_$(date '+%Y%m%d_%H-%M-%S').$file_ext" set -l new_recording_path "$storage_dir/recording_$(date '+%Y%m%d_%H-%M-%S').$file_ext"
@@ -73,7 +63,7 @@ if pgrep wf-recorder > /dev/null
end end
# Notification with actions # Notification with actions
set -l action (notify-send 'Recording stopped' "Stopped recording $new_recording_path" -i 'video-x-generic-symbolic' -a 'caelestia-record' \ set -l action (notify-send 'Recording stopped' "Stopped recording $new_recording_path" -i 'video-x-generic' -a 'caelestia-record' \
--action='watch=Watch' --action='open=Open' --action='save=Save As') --action='watch=Watch' --action='open=Open' --action='save=Save As')
switch $action switch $action
@@ -90,38 +80,18 @@ else
# Set region if flag given otherwise active monitor # Set region if flag given otherwise active monitor
if set -q _flag_r if set -q _flag_r
# Use given region if value otherwise slurp # Use given region if value otherwise slurp
set region -g (test -n "$_flag_r" && echo $_flag_r || slurp) set region -g (test -n "$_flag_r" && echo $_flag_r || get-region)
# No hardware encoding when smaller than 256x128 cause unsupported
if set -q _flag_H
set -l size (echo $region[2] | string split -n -f 2 ' ' | string split x)
if test $size[1] -lt 256 -o $size[2] -lt 128
warn 'Hardware encoding unsupported below size 256x128. Falling back to software encoding.'
set -e _flag_H
end
end
else else
set region -o (get-active-monitor) set region -o (get-active-monitor)
end end
# Sound if enabled # Sound if enabled
set -q _flag_s && set audio --audio=(get-audio-source) set -q _flag_s && set -l audio --audio --audio-device (get-audio-source)
# Codec stuff # No hardware accel
if set -q _flag_H && has-gpu && supports-gpu-codecs set -q _flag_n && set -l hwaccel --no-hw
# Hardware encoding (GPU)
supports-codec hevc_vaapi && set codec hevc_vaapi || set codec h264_vaapi
set -q _flag_c && set compression -p qp=$_flag_c -p rc_mode=CQP
set codec_flags -d /dev/dri/renderD128
else
# Software encoding (CPU)
set -q _flag_H && warn 'Unable to use hardware acceleration. Falling back to software encoding.'
supports-codec libx265 && set codec libx265 || set codec libx264
set -q _flag_c && set compression -p crf=$_flag_c
set codec_flags -x yuv420p
end
wf-recorder -c $codec $codec_flags $compression $region $audio -f $recording_path & disown wl-screenrec $region $audio $hwaccel -f $recording_path & disown
notify-send 'Recording started' 'Recording...' -i 'video-x-generic-symbolic' -a 'caelestia-record' -p > $notif_id_path notify-send 'Recording started' 'Recording...' -i 'video-x-generic' -a 'caelestia-record' -p > $notif_id_path
end end