dmenurecord (2541B)
1 #!/bin/sh 2 3 # Usage: 4 # `$0`: Ask for recording type via wmenu 5 # `$0 screencast`: Record both audio and screen 6 # `$0 video`: Record only screen 7 # `$0 audio`: Record only audio 8 # `$0 kill`: Kill existing recording 9 # 10 # If there is already a running instance, user will be prompted to end it. 11 12 getdim() { 13 screens=$(hyprctl monitors | grep Monitor | cut -d' ' -f2) 14 choice=$(printf "$screens\nExit\n" | wmenu) 15 [ "${choice}" != "Exit" ] || [ -z "${choice}" ] || exit && 16 echo $choice 17 } 18 19 updateicon() { \ 20 echo "$1" > /tmp/recordingicon 21 pkill -RTMIN+9 "${STATUSBAR:-waybar}" 22 } 23 24 killrecording() { 25 recpid="$(cat /tmp/recordingpid)" 26 echo $recpid 27 kill -2 "$recpid" 28 rm -f /tmp/recordingpid 29 updateicon "" 30 pkill -RTMIN+9 "${STATUSBAR:-waybar}" 31 } 32 33 screencast() { gpu-screen-recorder \ 34 -w "$(getdim)" \ 35 -f 60 \ 36 -a default_output \ 37 -a default_input \ 38 -o "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & 39 echo $! > /tmp/recordingpid 40 updateicon "⏺️🎙️" 41 } 42 43 video() { gpu-screen-recorder \ 44 -w "$(getdim)" \ 45 -f 60 \ 46 -o "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & 47 echo $! > /tmp/recordingpid 48 updateicon "⏺️" 49 } 50 51 webcamhidef() { ffmpeg \ 52 -f v4l2 \ 53 -i /dev/video0 \ 54 -video_size 1920x1080 \ 55 "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & 56 echo $! > /tmp/recordingpid 57 updateicon "🎥" 58 } 59 60 webcam() { ffmpeg \ 61 -f v4l2 \ 62 -i /dev/video0 \ 63 -video_size 640x480 \ 64 "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & 65 echo $! > /tmp/recordingpid 66 updateicon "🎥" 67 } 68 69 70 audio() { \ 71 ffmpeg \ 72 -f alsa -i default \ 73 -c:a flac \ 74 "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & 75 echo $! > /tmp/recordingpid 76 updateicon "🎙️" 77 } 78 79 askrecording() { \ 80 choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | wmenu -i -p "Select recording style:") 81 case "$choice" in 82 screencast) screencast;; 83 audio) audio;; 84 video) video;; 85 *selected) videoselected;; 86 webcam) webcam;; 87 "webcam (hi-def)") webcamhidef;; 88 esac 89 } 90 91 asktoend() { \ 92 response=$(printf "No\\nYes" | wmenu -i -p "Recording still active. End recording?") && 93 [ "$response" = "Yes" ] && killrecording 94 } 95 96 videoselected() 97 { 98 slurp -f "%x %y %w %h" > /tmp/slurp 99 read -r X Y W H < /tmp/slurp 100 rm /tmp/slurp 101 wf-recorder -g "$X,$Y ${W}x${H}" -r 60 -f "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & 102 echo $! > /tmp/recordingpid 103 updateicon "⏺️" 104 } 105 106 case "$1" in 107 screencast) screencast;; 108 audio) audio;; 109 video) video;; 110 *selected) videoselected;; 111 kill) killrecording;; 112 *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; 113 esac