From 9053b258c0cb02af19209f6fc438483ff4c510f0 Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Sun, 12 May 2024 17:08:24 -0500 Subject: [PATCH] capture updates --- builds/utils.nix | 7 ++-- builds/utils/sh/capture | 87 +++++++++++++++-------------------------- 2 files changed, 36 insertions(+), 58 deletions(-) diff --git a/builds/utils.nix b/builds/utils.nix index 8fd47e9..c84a2f2 100644 --- a/builds/utils.nix +++ b/builds/utils.nix @@ -9,13 +9,14 @@ , bash , feh , jq -, ffmpeg , fzy , figlet , curl , ytfzf , herbe , xrandr +, xrectsel +, ffcast , svkbd , xkbset , rbw @@ -30,7 +31,7 @@ stdenv.mkDerivation rec { src = ./utils; nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ bash feh xrandr jq curl fzy ytfzf ffmpeg sshuttle svkbd scrcpy xkbset rbw xclip libsForQt5.kolourpaint ]; + buildInputs = [ bash feh xrandr jq curl fzy ytfzf sshuttle svkbd scrcpy xkbset rbw xclip ffcast libsForQt5.kolourpaint ]; installPhase = '' mkdir -p $out/bin @@ -38,7 +39,7 @@ stdenv.mkDerivation rec { for i in $(ls $src/sh); do cp $src/sh/$i $out/bin ln -sf $out/bin/tmenu_run $out/bin/regenerate - wrapProgram $out/bin/$i --prefix PATH : ${lib.makeBinPath [ sxhkd bash feh xrandr jq figlet curl fzy ytfzf herbe ffmpeg sshuttle svkbd scrcpy libsForQt5.kolourpaint ]} + wrapProgram $out/bin/$i --prefix PATH : ${lib.makeBinPath [ sxhkd bash feh xrandr jq figlet curl fzy ytfzf herbe sshuttle svkbd scrcpy libsForQt5.kolourpaint xrectsel ffcast ]} done ''; } diff --git a/builds/utils/sh/capture b/builds/utils/sh/capture index e74e052..fba1415 100755 --- a/builds/utils/sh/capture +++ b/builds/utils/sh/capture @@ -1,60 +1,37 @@ -#!/bin/sh +display=$(xrandr \ + | grep ' connected' \ + | awk -F ' ' '{print $1}' \ + | sed '1i select rectangle' \ + | fzy) -# get screen info and temporary file -tmp=$(mktemp -d) -res=$(xrandr | - grep ' connected' | - awk -F' ' '{print $1 " " $4}' | - awk -F'+' '{print $1}' | - fzy | - awk -F' ' '{print $2}' ) - -# still or motion -medium=$(printf ".mp4\n.png\n" | fzy) -output="$tmp/main$medium" - -# capture -case "$medium" in - *mp4*) - printf "> starting video capture...\n" - ffmpeg -video_size "$res" -f x11grab -framerate 60 -i $DISPLAY -preset ultrafast -pix_fmt yuv420p "$output" - ;; - *png*) - printf "> taking screenshot...\n" - # for a screenshot, we usually want an a s t h e t i c - ffmpeg -f x11grab -video_size "$res" -i $DISPLAY -vframes 1 "$output" -loglevel quiet # be quiet +case "$display" in + "select"*) + geom=$(xrectsel) ;; *) - printf "not a choice\n" - exit 1 + geom=$(xrandr \ + | grep "$display" \ + | awk -F ' ' '{print $3 " " $4}' \ + | sed 's/primary //g' \ + | awk -F ' ' '{print $1}' \ + | grep '[[:digit:]]' + ) + ;; esac -# what to do with the capture? -printf "> written to %s\n" "$output" -while true; do - result=$(printf "delete\nmove to home directory\nupload to pastebin\nreview footage\nquit\n" | fzy --prompt="what next? ") - case "$result" in - *upload*) - paste "$output" | xclip -i - printf "> pasted! check your clipboard\n" - ;; - *review*) - [ "$medium" = ".mp4" ] && mpv "$output" && continue - feh "$output" - ;; - *delete*) - printf "> removing target file...\n" - rm "$output" - exit 1 - ;; - *home*) - printf "> warping your capture to home...\n" - name=$(echo "capture$medium" | fzy --prompt="name please? ") - mv "$output" "$HOME/$name" - exit 1 - ;; - *quit*) - exit 1 - ;; - esac -done +printf "[] selected geometry is %s\n" "$geom" + +medium=$( + printf ".mp4\n.png\n" | fzy +) + +printf "[] capturing in medium %s\n" "$medium" + +case "$medium" in + *"mp4"*) + ffcast -g $geom rec + ;; + *"png"*) + ffcast -g $geom png + ;; +esac