From f5cd0fefa5ca09a2f23132455b6c9485fcef8d68 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Mon, 24 Sep 2018 11:23:46 -0400 Subject: [PATCH] dmenurecord overhaul --- .config/i3/config | 2 +- .scripts/dmenurecord | 106 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 89 insertions(+), 19 deletions(-) diff --git a/.config/i3/config b/.config/i3/config index 5783f6f..3ced420 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -24,7 +24,7 @@ gaps inner 15 gaps outer 15 set $term --no-startup-id $TERMINAL set $mod Mod4 -set $stoprec --no-startup-id killrecording +set $stoprec --no-startup-id dmenurecord kill set $shutdown sudo -A shutdown -h now set $reboot sudo -A reboot set $netrefresh --no-startup-id sudo -A systemctl restart NetworkManager diff --git a/.scripts/dmenurecord b/.scripts/dmenurecord index 26b26b3..8e9adc8 100755 --- a/.scripts/dmenurecord +++ b/.scripts/dmenurecord @@ -1,25 +1,95 @@ -#!/bin/bash +#!/bin/sh -# A dmenu recording prompt for my different recording scripts. +# Usage: +# `record`: Ask for recording type via dmenu +# `record screencast`: Record both audio and screen +# `record video`: Record only screen +# `record audio`: Record only audio +# `record kill`: Kill existing recording +# +# If there is already a running instance, user will be prompted to end it. -# Asks for type of recording and uses one of my three different scripts. -asktype() { \ -case $(echo -e "Screencast\nVideo only\nAudio only" | dmenu -i -p "Select recording style:") in - Screencast) screencast ;; - "Audio only") audio ;; - "Video only") video ;; -esac ;} +updateicon() { \ + echo "$1" > ~/.recordingicon + pkill -RTMIN+9 i3blocks + } +killrecording() { + kill -9 "$(cat ~/.recordingpid)" + rm -f ~/.recordingpid + updateicon "" + pkill -RTMIN+9 i3blocks + exit + } -# If already running, will ask to end previous recording. +screencastpulse() { \ + 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 \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > ~/.recordingpid + updateicon "⏺️🎙️" + } + +screencastalsa() { \ + 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 \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > ~/.recordingpid + updateicon "⏺️" + } + +video() { ffmpeg \ + -f x11grab \ + -s $(xdpyinfo | grep dimensions | awk '{print $2;}') \ + -i :0.0 \ + -c:v libx264 -qp 0 -r 30 \ + "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > ~/.recordingpid + updateicon "⏺️" + } + +audiopulse() { \ + ffmpeg \ + -f alsa -i default \ + -c:a flac \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > ~/.recordingpid + updateicon "🎙️" + } + +audioalsa() { \ + ffmpeg -y \ + -f alsa -ar 44100 -i hw:1 \ + "$HOME/audio-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > ~/.recordingpid + updateicon "🎙️" + } + +askrecording() { \ + printf "screencast\\nvideo\\naudio" | dmenu -i -p "Select recording style:" + } asktoend() { \ -response=$(echo -e "No\nYes" | dmenu -i -p "Recording still active. End recording?") && -if [[ "$response" = "Yes" ]]; then killall ffmpeg; fi ;} + response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") && + [ "$response" = "Yes" ] && killrecording + } -if (( $(pgrep dmenurecord | wc -l) > 2 )); then -asktoend; -else -asktype; -fi -echo "$response" + +case "$1" in + screencast) screencastpulse;; + audio) audiopulse;; + video) video;; + kill) killrecording;; + *) ([ -f ~/.recordingpid ] && asktoend && exit) || askrecording;; +esac