2020-02-08 23:43:37 +00:00
|
|
|
#!/bin/sh
|
2018-04-11 06:08:43 +00:00
|
|
|
|
2018-09-24 15:23:46 +00:00
|
|
|
# Usage:
|
2019-05-22 14:04:39 +00:00
|
|
|
# `$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
|
2018-09-24 15:23:46 +00:00
|
|
|
#
|
|
|
|
# If there is already a running instance, user will be prompted to end it.
|
2018-04-11 06:08:43 +00:00
|
|
|
|
2018-09-24 15:23:46 +00:00
|
|
|
updateicon() { \
|
2019-01-02 16:06:15 +00:00
|
|
|
echo "$1" > /tmp/recordingicon
|
2019-11-24 13:10:31 +00:00
|
|
|
pkill -RTMIN+9 "${STATUSBAR:?}"
|
2018-09-24 15:23:46 +00:00
|
|
|
}
|
2018-08-04 17:49:54 +00:00
|
|
|
|
2018-09-24 15:23:46 +00:00
|
|
|
killrecording() {
|
2019-01-02 16:06:15 +00:00
|
|
|
recpid="$(cat /tmp/recordingpid)"
|
2018-09-29 19:52:05 +00:00
|
|
|
# kill with SIGTERM, allowing finishing touches.
|
|
|
|
kill -15 "$recpid"
|
2019-01-02 16:06:15 +00:00
|
|
|
rm -f /tmp/recordingpid
|
2018-09-24 15:23:46 +00:00
|
|
|
updateicon ""
|
2019-11-24 13:10:31 +00:00
|
|
|
pkill -RTMIN+9 "${STATUSBAR:?}"
|
2018-09-29 19:52:05 +00:00
|
|
|
# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
|
|
|
|
sleep 3
|
|
|
|
kill -9 "$recpid"
|
2018-09-24 15:23:46 +00:00
|
|
|
exit
|
|
|
|
}
|
2018-04-11 06:08:43 +00:00
|
|
|
|
2018-12-01 15:12:02 +00:00
|
|
|
screencast() { \
|
2018-09-24 15:23:46 +00:00
|
|
|
ffmpeg -y \
|
|
|
|
-f x11grab \
|
|
|
|
-framerate 60 \
|
|
|
|
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
|
2019-06-17 20:37:29 +00:00
|
|
|
-i $DISPLAY \
|
2018-09-24 15:23:46 +00:00
|
|
|
-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" &
|
2019-01-02 16:06:15 +00:00
|
|
|
echo $! > /tmp/recordingpid
|
2018-09-24 15:23:46 +00:00
|
|
|
updateicon "⏺️🎙️"
|
|
|
|
}
|
|
|
|
|
|
|
|
video() { ffmpeg \
|
|
|
|
-f x11grab \
|
|
|
|
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
|
2019-06-17 20:37:29 +00:00
|
|
|
-i $DISPLAY \
|
2018-09-24 15:23:46 +00:00
|
|
|
-c:v libx264 -qp 0 -r 30 \
|
|
|
|
"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
|
2019-01-02 16:06:15 +00:00
|
|
|
echo $! > /tmp/recordingpid
|
2018-09-24 15:23:46 +00:00
|
|
|
updateicon "⏺️"
|
|
|
|
}
|
|
|
|
|
2018-12-01 15:12:02 +00:00
|
|
|
webcamhidef() { ffmpeg \
|
2019-01-01 22:07:33 +00:00
|
|
|
-f v4l2 \
|
2018-12-01 15:12:02 +00:00
|
|
|
-i /dev/video0 \
|
|
|
|
-video_size 1920x1080 \
|
|
|
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
2019-01-02 16:06:15 +00:00
|
|
|
echo $! > /tmp/recordingpid
|
2018-12-01 15:12:02 +00:00
|
|
|
updateicon "🎥"
|
2018-09-24 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 15:12:02 +00:00
|
|
|
webcam() { ffmpeg \
|
2019-01-01 22:07:33 +00:00
|
|
|
-f v4l2 \
|
2018-12-01 15:12:02 +00:00
|
|
|
-i /dev/video0 \
|
|
|
|
-video_size 640x480 \
|
|
|
|
"$HOME/webcam-$(date '+%y%m%d-%H%M-%S').mkv" &
|
2019-01-02 16:06:15 +00:00
|
|
|
echo $! > /tmp/recordingpid
|
2018-12-01 15:12:02 +00:00
|
|
|
updateicon "🎥"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
audio() { \
|
|
|
|
ffmpeg \
|
|
|
|
-f alsa -i default \
|
|
|
|
-c:a flac \
|
2018-09-29 19:51:45 +00:00
|
|
|
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
|
2019-01-02 16:06:15 +00:00
|
|
|
echo $! > /tmp/recordingpid
|
2018-09-24 15:23:46 +00:00
|
|
|
updateicon "🎙️"
|
|
|
|
}
|
|
|
|
|
|
|
|
askrecording() { \
|
2018-12-01 15:12:02 +00:00
|
|
|
choice=$(printf "screencast\\nvideo\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:")
|
2018-09-29 19:51:45 +00:00
|
|
|
case "$choice" in
|
2018-12-01 15:12:02 +00:00
|
|
|
screencast) screencast;;
|
|
|
|
audio) audio;;
|
2018-09-29 19:51:45 +00:00
|
|
|
video) video;;
|
2019-01-01 22:07:33 +00:00
|
|
|
webcam) webcam;;
|
|
|
|
"webcam (hi-def)") webcamhidef;;
|
2018-09-29 19:51:45 +00:00
|
|
|
esac
|
2018-09-24 15:23:46 +00:00
|
|
|
}
|
2018-04-11 06:08:43 +00:00
|
|
|
|
|
|
|
asktoend() { \
|
2018-09-24 15:23:46 +00:00
|
|
|
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
|
|
|
|
[ "$response" = "Yes" ] && killrecording
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
2018-12-01 15:12:02 +00:00
|
|
|
screencast) screencast;;
|
|
|
|
audio) audio;;
|
2018-09-24 15:23:46 +00:00
|
|
|
video) video;;
|
|
|
|
kill) killrecording;;
|
2019-01-02 16:06:15 +00:00
|
|
|
*) ([ -f /tmp/recordingpid ] && asktoend && exit) || askrecording;;
|
2018-09-24 15:23:46 +00:00
|
|
|
esac
|