2022-07-04 21:36:33 +02:00
|
|
|
#!/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.
|
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
updateicon() {
|
2024-01-02 19:09:46 +01:00
|
|
|
echo "$1" >/tmp/recordingicon
|
|
|
|
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
|
|
|
killrecording() {
|
2024-01-02 19:09:46 +01:00
|
|
|
recpid="$(cat /tmp/recordingpid)"
|
|
|
|
# kill with SIGTERM, allowing finishing touches.
|
|
|
|
kill -15 "$recpid"
|
|
|
|
rm -f /tmp/recordingpid
|
|
|
|
updateicon ""
|
|
|
|
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"
|
|
|
|
# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
|
|
|
|
sleep 3
|
|
|
|
kill -9 "$recpid"
|
|
|
|
exit
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
screencast() {
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg -y \
|
|
|
|
-f x11grab \
|
|
|
|
-framerate 60 \
|
|
|
|
-s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \
|
|
|
|
-i "$DISPLAY" \
|
|
|
|
-f alsa -i default \
|
|
|
|
-r 30 \
|
|
|
|
-c:v h264 -crf 0 -preset ultrafast -c:a aac \
|
|
|
|
"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon "ﲠ"
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
video() {
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg \
|
|
|
|
-f x11grab \
|
|
|
|
-s "$(xdpyinfo | awk '/dimensions/ {print $2;}')" \
|
|
|
|
-i "$DISPLAY" \
|
|
|
|
-c:v libx264 -qp 0 -r 30 \
|
|
|
|
"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon "ﲣ"
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
webcamhidef() {
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg \
|
|
|
|
-f v4l2 \
|
|
|
|
-i /dev/video0 \
|
|
|
|
-video_size 1920x1080 \
|
|
|
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon ""
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
webcam() {
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg \
|
|
|
|
-f v4l2 \
|
|
|
|
-i /dev/video0 \
|
|
|
|
-video_size 640x480 \
|
|
|
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon ""
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
audio() {
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg \
|
|
|
|
-f alsa -i default \
|
|
|
|
-c:a flac \
|
|
|
|
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon ""
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
askrecording() {
|
2024-01-02 19:09:46 +01:00
|
|
|
choice=$(printf "screencast\\nvideo\\nvideo selected\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:")
|
|
|
|
case "$choice" in
|
|
|
|
screencast) screencast ;;
|
|
|
|
audio) audio ;;
|
|
|
|
video) video ;;
|
|
|
|
*selected) videoselected ;;
|
|
|
|
webcam) webcam ;;
|
|
|
|
"webcam (hi-def)") webcamhidef ;;
|
|
|
|
esac
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
asktoend() {
|
2024-01-02 19:09:46 +01:00
|
|
|
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
|
|
|
|
[ "$response" = "Yes" ] && killrecording
|
2023-02-07 17:19:53 +01:00
|
|
|
}
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2023-02-07 17:19:53 +01:00
|
|
|
videoselected() {
|
2024-01-02 19:09:46 +01:00
|
|
|
slop -f "%x %y %w %h" >/tmp/slop
|
|
|
|
read -r X Y W H </tmp/slop
|
|
|
|
rm /tmp/slop
|
2022-07-04 21:36:33 +02:00
|
|
|
|
2024-01-02 19:09:46 +01:00
|
|
|
ffmpeg \
|
|
|
|
-f x11grab \
|
|
|
|
-framerate 60 \
|
|
|
|
-video_size "$W"x"$H" \
|
|
|
|
-i :0.0+"$X,$Y" \
|
|
|
|
-c:v libx264 -qp 0 -r 30 \
|
|
|
|
"$HOME/box-$(date '+%y%m%d-%H%M-%S').mkv" &
|
|
|
|
echo $! >/tmp/recordingpid
|
|
|
|
updateicon "ﲣ"
|
2022-07-04 21:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
2023-02-07 17:19:53 +01:00
|
|
|
screencast) screencast ;;
|
|
|
|
audio) audio ;;
|
|
|
|
video) video ;;
|
|
|
|
*selected) videoselected ;;
|
|
|
|
kill) killrecording ;;
|
|
|
|
*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording ;;
|
2022-07-04 21:36:33 +02:00
|
|
|
esac
|