From f61ab667856a6896a0395a84c85cc4c1f139c630 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Tue, 10 Apr 2018 23:08:43 -0700 Subject: [PATCH] Overhaul of screencasting scripts --- .config/i3/config | 4 +--- .scripts/audio | 27 +++++++++++++++++++++++++++ .scripts/audio_alsa.sh | 18 ------------------ .scripts/audio_pulse.sh | 18 ------------------ .scripts/dmenurecord | 24 ++++++++++++++++++++++++ .scripts/record | 8 -------- .scripts/screencast | 36 ++++++++++++++++++++++++++++++++++++ .scripts/screencast_alsa.sh | 22 ---------------------- .scripts/screencast_pulse.sh | 25 ------------------------- .scripts/{video.sh => video} | 11 ++++------- 10 files changed, 92 insertions(+), 101 deletions(-) create mode 100755 .scripts/audio delete mode 100755 .scripts/audio_alsa.sh delete mode 100755 .scripts/audio_pulse.sh create mode 100755 .scripts/dmenurecord delete mode 100755 .scripts/record create mode 100755 .scripts/screencast delete mode 100755 .scripts/screencast_alsa.sh delete mode 100755 .scripts/screencast_pulse.sh rename .scripts/{video.sh => video} (51%) diff --git a/.config/i3/config b/.config/i3/config index a14498b..021e330 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -26,8 +26,6 @@ set $term --no-startup-id st set $stoprec --no-startup-id killall ffmpeg # #---Starting External Scripts---# # -#Increase key rate -exec --no-startup-id xset r rate 300 50 #Music player daemon: exec --no-startup-id mpd #Torrent daemon: @@ -367,7 +365,7 @@ bindsym $mod+Shift+bracketright exec $bigfor # For screenshots and recording bindsym Print exec --no-startup-id scrot bindsym Shift+Print exec --no-startup-id scrot -u -bindsym $mod+Print exec --no-startup-id record +bindsym $mod+Print exec --no-startup-id dmenurecord bindsym $mod+Scroll_Lock exec --no-startup-id "killall screenkey || screenkey" bindsym $mod+Delete exec $stoprec bindsym XF86Launch1 exec $stoprec & xset dpms force off diff --git a/.scripts/audio b/.scripts/audio new file mode 100755 index 0000000..cb630c8 --- /dev/null +++ b/.scripts/audio @@ -0,0 +1,27 @@ +#!/bin/bash + +# This script records audio. +# It runs an appropriate record script for either ALSA and Pulseaudio. +# It also names files smartly to prevent overwrites. + +# Picks a file name for the output file based on availability: +while [[ -f $HOME/screencast$n.mkv ]] +do + n=$((n+1)) +done +filename="$HOME/screencast$n.mkv" + +# For Pulseaudio with ALSA: +record_pulse() { \ +ffmpeg \ +-f alsa -i default \ +-c:a flac \ +$filename ;} + +# For ALSA: +record_alsa() { \ +ffmpeg -y \ +-f alsa -ar 44100 -i hw:1 \ +$filename ;} + +if [[ $(pgrep -x pulseaudio) ]]; then record_pulse; else record_alsa; fi diff --git a/.scripts/audio_alsa.sh b/.scripts/audio_alsa.sh deleted file mode 100755 index cda07a2..0000000 --- a/.scripts/audio_alsa.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -#This is the ffmpeg command that the screencast shortcut in i3 will run. - -#Picks a file name for the output file based on availability: - -while [[ -f $HOME/audio$n.flac ]] -do - n=$((n+1)) -done -filename="$HOME/audio$n.flac" - -#The actual ffmpeg command: - -ffmpeg -y \ - -f alsa -ar 44100 -i hw:1 \ - $filename - diff --git a/.scripts/audio_pulse.sh b/.scripts/audio_pulse.sh deleted file mode 100755 index 21e46ea..0000000 --- a/.scripts/audio_pulse.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -#This is the ffmpeg command that the audio shortcut in i3 will run. - -#Picks a file name for the output file based on availability: - -while [[ -f $HOME/audio$n.flac ]] -do - n=$((n+1)) -done -filename="$HOME/audio$n.flac" - -#The actual ffmpeg command: - -ffmpeg \ --f alsa -i default \ --c:a flac \ -$filename diff --git a/.scripts/dmenurecord b/.scripts/dmenurecord new file mode 100755 index 0000000..75cc6ff --- /dev/null +++ b/.scripts/dmenurecord @@ -0,0 +1,24 @@ +#!/bin/bash + +# A dmenu recording prompt for my different recording scripts. + +# 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 ;} + +# If already running, will ask to end previous recording. + +asktoend() { \ +response=$(echo -e "No\nYes" | dmenu -i -p "Recording still active. End recording?") && +if [[ "$response" = "Yes" ]]; then killall ffmpeg; fi ;} + +if (( $(pgrep dmenurecord | wc -l) > 2 )); then +asktoend; +else +asktype; +fi +echo $response diff --git a/.scripts/record b/.scripts/record deleted file mode 100755 index df1926f..0000000 --- a/.scripts/record +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# A dmenu recording prompt for my different - -case $(echo -e "Screencast\nVideo only\nAudio only" | dmenu -i -p "Select recording style:") in - Screencast) (pgrep -x pulseaudio && screencast_pulse.sh) || screencast_alsa.sh ;; - "Audio only") (pgrep -x pulseaudio && audio_pulse.sh) || audio_alsa.sh ;; - "Video only") video.sh ;; -esac diff --git a/.scripts/screencast b/.scripts/screencast new file mode 100755 index 0000000..cd37ab9 --- /dev/null +++ b/.scripts/screencast @@ -0,0 +1,36 @@ +#!/bin/bash + +# This script records a screencast with audio and video. +# It runs an appropriate record script for either ALSA and Pulseaudio. +# It also names files smartly to prevent overwrites. + +# Picks a file name for the output file based on availability: +while [[ -f $HOME/screencast$n.mkv ]] +do + n=$((n+1)) +done +filename="$HOME/screencast$n.mkv" + +# For Pulseaudio with ALSA: +record_pulse() { \ +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 ;} + +# For ALSA: +record_alsa() { \ +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 ;} + + +if [[ $(pgrep -x pulseaudio) ]]; then record_pulse; else record_alsa; fi diff --git a/.scripts/screencast_alsa.sh b/.scripts/screencast_alsa.sh deleted file mode 100755 index 95c1d5d..0000000 --- a/.scripts/screencast_alsa.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -#This is the ffmpeg command that the screencast shortcut in i3 will run. - -#Picks a file name for the output file based on availability: - -while [[ -f $HOME/screencast$n.mkv ]] -do - n=$((n+1)) -done -filename="$HOME/screencast$n.mkv" - -#The actual ffmpeg command: - -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 - #-c:v ffvhuff -r 30 -c:a flac $filename diff --git a/.scripts/screencast_pulse.sh b/.scripts/screencast_pulse.sh deleted file mode 100755 index 871a5b9..0000000 --- a/.scripts/screencast_pulse.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -#This is the ffmpeg command that the screencast shortcut in i3 will run. - -#Picks a file name for the output file based on availability: - -while [[ -f $HOME/screencast$n.mkv ]] -do - n=$((n+1)) -done -filename="$HOME/screencast$n.mkv" - -#The actual ffmpeg command: - -ffmpeg -y \ --f x11grab \ --framerate 60 \ --s $(xdpyinfo | grep dimensions | awk '{print $2;}') \ --i :0.0 \ --thread_queue_size 2048 \ --f alsa -i default \ --r 30 \ - -c:v libx264 -r 30 -c:a flac $filename - #-c:v ffvhuff -r 30 -c:a flac $filename - #-f pulse -ac 1 -ar 44100 -i default \ diff --git a/.scripts/video.sh b/.scripts/video similarity index 51% rename from .scripts/video.sh rename to .scripts/video index ac3dc5c..357464f 100755 --- a/.scripts/video.sh +++ b/.scripts/video @@ -1,21 +1,18 @@ #!/bin/bash -#This is the ffmpeg command that the screencast shortcut in i3 will run. - -#Picks a file name for the output file based on availability: +# This script records video. +# It also names files smartly to prevent overwrites. +# Picks a file name for the output file based on availability: while [[ -f $HOME/video$n.mkv ]] do n=$((n+1)) done filename="$HOME/video$n.mkv" - -#The actual ffmpeg command: - +# The actual ffmpeg command: ffmpeg \ -f x11grab \ -s $(xdpyinfo | grep dimensions | awk '{print $2;}') \ -i :0.0 \ -c:v libx264 -qp 0 -r 30 $filename - #-c:v ffvhuff -r 30 -c:a flac $filename