dmenurecord (2712B)
1 #!/bin/sh 2 3 # Usage: 4 # `$0`: Ask for recording type via dmenu 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=$(swaymsg -t get_outputs | grep name | awk -F'"' '{print $4}') 14 choice=$(printf "$screens\nExit\n" | bemenu) 15 [ "${choice}" != "Exit" ] || [ -z "${choice}" ] || exit && 16 echo $choice 17 } 18 19 updateicon() { \ 20 echo "$1" > /tmp/recordingicon 21 pkill -RTMIN+9 "${STATUSBAR:-i3blocks}" 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:-i3blocks}" 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)" | bemenu -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" | bemenu -i -p "Recording still active. End recording?") && 93 [ "$response" = "Yes" ] && killrecording 94 } 95 96 # needs rewrite and support by gpu-screen-recorder 97 98 # videoselected() 99 # { 100 # slop -f "%x %y %w %h" > /tmp/slop 101 # read -r X Y W H < /tmp/slop 102 # rm /tmp/slop 103 # 104 # ffmpeg \ 105 # -f x11grab \ 106 # -framerate 30 \ 107 # -video_size "$W"x"$H" \ 108 # -i :0.0+"$X,$Y" \ 109 # -c:v libx264 -qp 0 -r 30 \ 110 # "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & 111 # echo $! > /tmp/recordingpid 112 # updateicon "⏺️" 113 # } 114 115 case "$1" in 116 screencast) screencast;; 117 audio) audio;; 118 video) video;; 119 # *selected) videoselected;; 120 kill) killrecording;; 121 *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;; 122 esac