dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.local/bin/grabar

106 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# Usage:
# `$0`: Ask for recording type via dmenu
# `$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.
killrecording() {
recpid="$(cat /tmp/recordingpid)"
# kill with SIGTERM, allowing finishing touches.
kill -15 "$recpid"
rm -f /tmp/recordingpid
# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
sleep 3
kill -9 "$recpid"
exit
}
screencast() { \
ffmpeg -y \
-thread_queue_size 4096 \
-f x11grab \
-framerate 60 \
-s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
-i "$DISPLAY" \
-f alsa -ac 2 -i pulse \
-r 30 \
-c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \
"$HOME/Videos/Screen/$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid
}
jacka() { \
ffmpeg -y \
-thread_queue_size 4096 \
-f jack -i jack_out.monitor \
-ac 2 -channel_layout stereo -async 1 \
-c:a flac "$HOME/Videos/Tape/$(date '+%y%m%d-%H%M-%S').flac"
echo $! > /tmp/recordingpid
}
jackv() {
ffmpeg -y \
-thread_queue_size 4096 \
-f jack -i ffmpeg \
-f x11grab \
-framerate 60 \
-s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
-i "$DISPLAY" \
-r 30 \
-c:v libx264 -qp 0 -r 30 -c:a flac \
"$HOME/Videos/Screen/$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid
}
mute() {
ffmpeg -y \
-f x11grab \
-thread_queue_size 4096 \
-s "$(xdpyinfo | grep dimensions | awk '{print $2;}')" \
-i "$DISPLAY" \
-c:v libx264 -qp 0 -r 30 \
"$HOME/Videos/$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > /tmp/recordingpid
}
audio() { \
ffmpeg -y \
-thread_queue_size 4096 \
-f pulse -i default \
-ac 2 -channel_layout stereo -async 1 \
-c:a flac \
"$HOME/Music/Tape/$(date '+%y%m%d-%H%M-%S').mp3" &
echo $! > /tmp/recordingpid
}
askrecording() { \
choice=$(printf "screencast\\nvideo\\naudio\\njack video\\njack audio" | dmenu -i -p "Select recording style ")
case "$choice" in
screencast) screencast;;
video) mute;;
audio) audio;;
"jack video") jackv;;
"jack audio") jacka;;
esac
}
asktoend() { \
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording? ") &&
[ "$response" = "Yes" ] && killrecording
}
case "$1" in
screencast) screencast;;
video) mute;;
audio) audio;;
"jack video") jackv;;
"jack audio") jacka;;
kill) killrecording;;
*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;;
esac