aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.local/bin/record
diff options
context:
space:
mode:
authorLibravatar Arnold Sommerfeld <sommerfeld@strisemarx.com>2023-05-17 18:44:48 +0100
committerLibravatar Arnold Sommerfeld <sommerfeld@strisemarx.com>2023-10-18 11:16:43 +0100
commitb487984ecc61c6229cf92550030745c192fd3d0b (patch)
tree937e598c941fc1172467aeeed8ef51cbfceaca62 /home/.local/bin/record
downloaddotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.tar.gz
dotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.tar.bz2
dotfiles-b487984ecc61c6229cf92550030745c192fd3d0b.zip
first commit
Diffstat (limited to 'home/.local/bin/record')
-rwxr-xr-xhome/.local/bin/record86
1 files changed, 86 insertions, 0 deletions
diff --git a/home/.local/bin/record b/home/.local/bin/record
new file mode 100755
index 0000000..0789769
--- /dev/null
+++ b/home/.local/bin/record
@@ -0,0 +1,86 @@
+#!/usr/bin/env sh
+
+pid_file="/tmp/recordpid"
+log_file="/tmp/record.log"
+
+pid_exists() {
+ test -r "$pid_file"
+}
+
+is_running() {
+ if pid_exists; then
+ ps "$(cat "$pid_file")" >/dev/null 2>&1 || return 1
+ else
+ return 1
+ fi
+}
+
+start() {
+ ffmpeg \
+ -threads 0 \
+ -thread_queue_size 512 -f x11grab -s 1920x1080 -framerate 60 -i "$DISPLAY" \
+ -thread_queue_size 1024 -f pulse -itsoffset 0.350 -i "alsa_output.usb-SteelSeries_SteelSeries_Arctis_7-00.analog-stereo.monitor" \
+ -thread_queue_size 1024 -f pulse -itsoffset 0.350 -i "alsa_input.usb-SteelSeries_SteelSeries_Arctis_7-00.analog-mono" \
+ -c:a aac \
+ -init_hw_device vaapi=va:/dev/dri/renderD128,driver=i965 -filter_hw_device va \
+ -vf format=nv12,hwupload \
+ -c:v h264_vaapi \
+ -r:v 60 -g:v 120 -bf:v 3 -refs:v 16 \
+ "$HOME/vids/$(date '+%y%m%d-%H%M-%S').mkv" >"$log_file" 2>&1 &
+ echo "$!" >"$pid_file"
+
+ notify-send "Record started!"
+}
+
+stop() {
+ pid_exists || exit 1
+ pid="$(cat "$pid_file")"
+ # kill with SIGTERM, allowing finishing touches.
+ kill "$pid"
+ # even after SIGTERM, ffmpeg may still run, so SIGKILL it.
+ sleep 3
+ is_running && kill -9 "$pid"
+ rm -f "$pid_file"
+ notify-send "Record stopped!"
+}
+
+toggle() {
+ if is_running; then
+ echo "Stopping record"
+ stop
+ else
+ echo "Starting record"
+ start
+ fi
+ echo
+ status
+}
+
+status() {
+ if is_running; then
+ echo "Recording with PID $(cat "$pid_file")"
+ echo "Check the logs at"
+ echo
+ echo "$log_file"
+ echo
+ else
+ echo "Record inactive"
+ fi
+}
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ toggle)
+ toggle
+ ;;
+ status)
+ status
+ ;;
+ *)
+ toggle
+ ;;
+esac