feat(hypr): add capturing gif support to screen-cap.bash

This commit is contained in:
Price Hiller 2023-03-05 02:38:31 -06:00
parent 0722a6c6db
commit 939a45ff6b
No known key found for this signature in database
2 changed files with 16 additions and 5 deletions

View File

@ -4,12 +4,14 @@
# - wf-recorder: https://github.com/ammen99/wf-recorder
# - notification daemon: https://archlinux.org/packages/?name=notification-daemon
# - wl-clipboard: https://github.com/bugaevc/wl-clipboard
# - gifski: https://github.com/sindresorhus/Gifski
#
# Some of this is hacky because I can't get wf-recorder to nicely output GIFs by itself :(
mk-mp4() {
local program_name="Screen Capture"
local pid_file="/tmp/mk-gif-pid"
local output_type="${1:-MP4}"
if [[ -f "${pid_file}" ]]; then
notify-send "Saving ${program_name}" "This May Take a Minute" -a "${program_name}"
@ -22,19 +24,27 @@ mk-mp4() {
notify-send "Saved ${program_name}" "Successfully Saved Screen Capture to Clipboard" -a "${program_name}"
else
local input_tmpfile
notify-send "Starting ${program_name}" "Recording GIF of Selected Region" -a "${program_name}"
notify-send "Starting ${program_name}" "Recording ${output_type^^} of Selected Region" -a "${program_name}"
(
local tmp_dir
tmp_dir="$(mktemp -d)"
cd "${tmp_dir}"
input_tmpfile="${tmp_dir}/$(mktemp wf-recorder.XXXXXXXXXXX)"
wf-recorder -g "$(slurp)" -f "${input_tmpfile}.mp4" -c h264_vaapi -d /dev/dri/renderD128 --framerate 24 -- &
input_tmpfile="${tmp_dir}/$(mktemp wf-recorder.XXXXXXXXXXX).mp4"
wf-recorder -g "$(slurp)" -f "${input_tmpfile}" -c h264_vaapi -d /dev/dri/renderD128 -- &
printf "%s" $! >"${pid_file}"
wait
wl-copy --type video/mp4 <"${input_tmpfile}.mp4"
if [[ "${output_type}" == "gif" ]]; then
local gifski_tmpoutput
pwd
gifski_tmpoutput="${tmp_dir}/$(mktemp gifski.XXXXXXXXXXX).gif"
gifski "${input_tmpfile}" --output "${gifski_tmpoutput}"
wl-copy --type image/gif <"${gifski_tmpoutput}"
else
wl-copy --type video/mp4 <"${input_tmpfile}"
fi
rm -f "${pid_file}"
)
fi
}
mk-mp4
mk-mp4 "${@}"

View File

@ -65,6 +65,7 @@ bind=SUPER,A,togglefloating,
bind=SUPERSHIFT,Q,exec,swaylock
bind=SUPER,S,exec,grim -g "$(slurp)" - | wl-copy --type image/png
bind=SUPERSHIFT,S,exec,~/.config/hypr/scripts/screen-cap.bash
bind=SUPERSHIFT,A,exec,~/.config/hypr/scripts/screen-cap.bash gif
bind=SUPERSHIFT,M,exit
# Mediakey bindings as taken from `wev`