dotfiles

beau's configuration files
git clone https://git.beauhilton.com/dotfiles.git
Log | Files | Refs | README

dmenurecord (2362B)


      1 #!/usr/bin/env sh
      2 
      3 # Usage:
      4 # `record`: Ask for recording type via dmenu
      5 # `record screencast`: Record both audio and screen
      6 # `record video`: Record only screen
      7 # `record audio`: Record only audio
      8 # `record kill`: Kill existing recording
      9 #
     10 # If there is already a running instance, user will be prompted to end it.
     11 
     12 updateicon() { \
     13 	echo "$1" > /tmp/recordingicon
     14 	pkill -RTMIN+9 i3blocks
     15 	}
     16 
     17 killrecording() {
     18 	recpid="$(cat /tmp/recordingpid)"
     19 	# kill with SIGTERM, allowing finishing touches.
     20 	kill -15 "$recpid"
     21 	rm -f /tmp/recordingpid
     22 	updateicon ""
     23 	pkill -RTMIN+9 i3blocks
     24 	# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
     25 	sleep 3
     26 	kill -9 "$recpid"
     27 	exit
     28 	}
     29 
     30 screencast() { \
     31 	ffmpeg -y \
     32 	-f x11grab \
     33 	-framerate 60 \
     34 	-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
     35 	-i $DISPLAY \
     36 	-f alsa -i default \
     37 	-r 30 \
     38  	-c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \
     39 	"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" &
     40 	echo $! > /tmp/recordingpid
     41 	updateicon "⏺️🎙️"
     42        	}
     43 
     44 video() { ffmpeg \
     45 	-f x11grab \
     46 	-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
     47 	-i $DISPLAY \
     48  	-c:v libx264 -qp 0 -r 30 \
     49 	"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
     50 	echo $! > /tmp/recordingpid
     51 	updateicon "⏺️"
     52 	}
     53 
     54 webcamhidef() { ffmpeg \
     55 	-f v4l2 \
     56 	-i /dev/video0 \
     57 	-video_size 1920x1080 \
     58 	"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
     59 	echo $! > /tmp/recordingpid
     60 	updateicon "🎥"
     61 	}
     62 
     63 webcam() { ffmpeg \
     64 	-f v4l2 \
     65 	-i /dev/video0 \
     66 	-video_size 640x480 \
     67 	"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
     68 	echo $! > /tmp/recordingpid
     69 	updateicon "🎥"
     70 	}
     71 
     72 
     73 audio() { \
     74 	ffmpeg \
     75 	-f alsa -i default \
     76 	-c:a flac \
     77 	"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
     78 	echo $! > /tmp/recordingpid
     79 	updateicon "🎙️"
     80 	}
     81 
     82 askrecording() { \
     83 	choice=$(printf "screencast\\nvideo\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:")
     84 	case "$choice" in
     85 		screencast) screencast;;
     86 		audio) audio;;
     87 		video) video;;
     88 		webcam) webcam;;
     89 		"webcam (hi-def)") webcamhidef;;
     90 	esac
     91 	}
     92 
     93 asktoend() { \
     94 	response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
     95 	[ "$response" = "Yes" ] &&  killrecording
     96 	}
     97 
     98 
     99 case "$1" in
    100 	screencast) screencast;;
    101 	audio) audio;;
    102 	video) video;;
    103 	kill) killrecording;;
    104 	*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;;
    105 esac