Script: Recordings Menu

Published 05-05-2018 22:47:05

Raw

#!/bin/bash
# Recording options menu
# Bound to Mod+Insert
mymenu=$(setmenu -l)
asktype() {
	case $(echo -e "Screencast\nVideo only\nAudio only" | $mymenu "Select recording style:") in
		Screencast) screencast ;;
		"Audio only") audio ;;
		"Video only") video ;;
	esac ;}
asktoend() {
	[[ $(echo -e "No\nYes" | $mymenu "Recording still active. End recording?") = "Yes" ]] &&
	sudo killall ffmpeg ||
	exit 0 ;}
audio() {
	while [[ -f $HOME/audio$n.mkv ]] ; do n=$((n+1)) ; done
	filename="$HOME/audio$n.mkv"
	[[ $(pgrep -x pulseaudio) ]] &&
	ffmpeg -f alsa -i default -c:a flac $filename ||
	ffmpeg -y -f alsa -ar 44100 -i hw:1 $filename ;}
video() {
	while [[ -f $HOME/video$n.mkv ]] ; do n=$((n+1)) ; done
	filename="$HOME/video$n.mkv"
	ffmpeg -f x11grab -s $(xdpyinfo | grep dimensions | awk '{print $2;}') -i :0.0 -c:v libx264 -qp 0 -r 30 $filename ;}
screencast() {
	while [[ -f $HOME/screencast$n.mkv ]] ; do n=$((n+1)) ; done
	filename="$HOME/screencast$n.mkv"
	[[ $(pgrep -x pulseaudio) ]] &&
	ffmpeg -y -f x11grab -framerate 60 -s $(xdpyinfo | grep dimensions | awk '{print $2;}') -i :0.0 -f alsa -i default -r 30 -c:v libx264rgb -crf 0 -preset ultrafast -c:a flac $filename ||
	ffmpeg -y -f x11grab -s $(xdpyinfo | grep dimensions | awk '{print $2;}') -i :0.0 -thread_queue_size 1024 -f alsa -ar 44100 -i hw:1 -c:v libx264 -r 30 -c:a flac $filename ;}
[[ (( $(pgrep ffmpeg | wc -l) > 0 )) ]] && asktoend || asktype