#!/bin/sh # Usage: # `$0`: Ask for recording type via mew # `$0 screencast`: Record both audio and screen # `$0 video`: Record only screen # `$0 audio`: Record only audio # `$0 kill`: Kill existing recording # # If there is already a running instance, user will be prompted to end it. getdim() { gpu-screen-recorder --list-capture-options | sed 's/|[0-9]\{1,\}x[0-9]\{1,\}//g' | mew -c -l 10 -p "Select output: " } updateicon() { echo "$1" >/tmp/recordingicon pkill -RTMIN+9 "$STATUSBAR" } killrecording() { recpid="$(bat /tmp/recordingpid)" echo "$recpid" kill -2 "$recpid" rm -f /tmp/recordingpid updateicon "" pkill -RTMIN+9 "$STATUSBAR" } screencast() { gpu-screen-recorder \ -w "$(getdim)" \ -fm content \ -f 60 \ -a default_output \ -a default_input \ -o "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" & echo $! >/tmp/recordingpid updateicon "📹🎙️" } video() { gpu-screen-recorder \ -w "$(getdim)" \ -fm content \ -f 60 \ -o "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & echo $! >/tmp/recordingpid updateicon "📹" } webcamhidef() { ffmpeg \ -f v4l2 \ -i /dev/video0 \ -video_size 1920x1080 \ "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & echo $! >/tmp/recordingpid updateicon "📷(hq)" } webcam() { ffmpeg \ -f v4l2 \ -i /dev/video0 \ -video_size 640x480 \ "$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" & echo $! >/tmp/recordingpid updateicon "📷" } audio() { ffmpeg \ -f alsa -i default \ -c:a flac \ "$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" & echo $! >/tmp/recordingpid updateicon "🎙️" } replay() { gpu-screen-recorder \ -w "$(getdim)" \ -fm content \ -f 60 \ -r 60 \ -c mkv \ -a default_output \ -a default_input \ -o "/mnt/ssd/rndm/clips/replays" & echo $! >/tmp/recordingpid updateicon "🔃📹🎙️" } savereplay() { recpid="$(bat /tmp/recordingpid)" echo $recpid kill -37 "$recpid" pkill -RTMIN+9 "$STATUSBAR" notify-send "Replay" "Last 60 seconds saved" exit } videoselected() { gpu-screen-recorder \ -w region -region "$(slurp -f "%wx%h+%x+%y")" \ -fm content \ -f 60 \ -o "$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" & echo $! >/tmp/recordingpid updateicon "📹(selected)" } askrecording() { choice=$(printf "screencast\\nreplay\\nvideo\\naudio\\nwebcam\\nwebcam (hi-def)" | mew -c -l 7 -i -p "Select recording style:") case "$choice" in screencast) screencast ;; replay) replay ;; audio) audio ;; video) video ;; *selected) videoselected ;; webcam) webcam ;; "webcam (hi-def)") webcamhidef ;; esac } asktoend() { if grep -q "🔃" /tmp/recordingicon; then response=$(printf "No\\nYes" | mew -c -l 2 -i -p "Replay is active. Save it?") && [ "$response" = "Yes" ] && savereplay fi response=$(printf "No\\nYes" | mew -c -l 2 -i -p "Recording still active. End recording?") && [ "$response" = "Yes" ] && killrecording } case "$1" in screencast) screencast ;; replay) replay ;; audio) audio ;; video) video ;; *selected) videoselected ;; kill) killrecording ;; *) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording ;; esac