123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #!/bin/sh --
- set -ue
- # better version of Luke Smith script :^)
- # https://github.com/LukeSmithxyz/voidrice/raw/master/.local/bin/dmenurecord
- PID="${TMP}/.recordingpid"
- alias dpy='xdpyinfo | sed -n "s/^\s\+dimensions:\s*\([0-9]\+x[0-9]\+\).*/\1/p"'
- killrecording() {
- read -r recpid <"${PID}"
- # kill with SIGTERM, allowing finishing touches.
- kill -15 "${recpid}"
- rm -f -- "${PID}"
- # even after SIGTERM, ffmpeg may still run, so SIGKILL it.
- sleep 3
- kill -9 "${recpid}" || :
- }
- screencast() {
- ffmpeg -y \
- -f x11grab \
- -framerate 60 \
- -s "$(dpy)" \
- -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 "${!}" >"${PID}"
- }
- video() {
- ffmpeg \
- -f x11grab \
- -s "$(dpy)" \
- -i "${DISPLAY}" \
- -c:v libx264 -qp 0 -r 30 \
- "${HOME}/video-$(date '+%y%m%d-%H%M-%S').mkv" &
- echo "${!}" >"${PID}"
- }
- videoselected() {
- read -r X Y W H <<-EOF
- $(slop -f "%x %y %w %h")
- EOF
- ffmpeg \
- -f x11grab \
- -framerate 60 \
- -video_size "${W}x${H}" \
- -i "${DISPLAY}+${X},${Y}" \
- -c:v libx264 -qp 0 -r 30 \
- "${HOME}/box-$(date '+%y%m%d-%H%M-%S').mkv" &
- echo "${!}" >"${PID}"
- }
- audio() {
- ffmpeg \
- -f alsa -i default \
- -c:a flac \
- "${HOME}/audio-$(date '+%y%m%d-%H%M-%S').flac" &
- echo "${!}" >"${PID}"
- }
- choices() {
- printf '%s\n' \
- 'video selected' \
- video \
- screencast \
- audio
- }
- asktoend() {
- response="$(
- printf '%s\n' No Yes \
- | dmenu -i -p "Recording still active. End recording?"
- )"
- case "${response}" in
- Y* | y*) killrecording ;;
- esac
- }
- main() {
- [ ! -f "${PID}" ] || {
- asktoend && exit
- }
- case "${1:-$(choices | dmenu -i -p 'Record:')}" in
- *selected) videoselected ;;
- video) video ;;
- screencast) screencast ;;
- audio) audio ;;
- kill) killrecording ;;
- *)
- echo 1>&2 "invalid action"
- exit 1
- ;;
- esac
- }
- main "${@}"
|