screenrecord (1774B)
1 #!/bin/sh 2 lockfile=/tmp/screenrecord.pid 3 screen=eDP-1 4 5 startrecording() { 6 7 fname="screenrecord-$(date '+%Y-%m-%d_%H:%M:%S')" 8 out="$HOME/tmp/${fname}.mkv" 9 10 if test -x /usr/bin/sndioctl; then 11 sndioctl -q input.level=1.0 12 snddrv="sndio" 13 else 14 snddrv="alsa" 15 fi 16 17 if test "$(xdpyinfo | awk '/dimensions/ {sub(/.*x/, "", $2); print $2}')" -gt 1500; then 18 xrandr --output "$screen" --mode 1920x1080 19 fi 20 21 if command -v stopwatch >/dev/null 2>&1; then 22 pkill spoon 23 nohup stopwatch -x >/dev/null 2>&1 & 24 fi 25 26 ffmpeg -y \ 27 -f x11grab \ 28 -framerate 60 \ 29 -s "$(xdpyinfo | awk '/dimensions/ {print $2}')" \ 30 -i $DISPLAY \ 31 -thread_queue_size 2048 \ 32 -f "$snddrv" -i default \ 33 -r 30 \ 34 -c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \ 35 "$out" >/dev/null 2>&1 & 36 printf '%s\n%s\n' "$!" "$out" > "$lockfile" 37 38 sleep 1 39 if [ ! -f "$out" ]; then 40 echo 'error: ffmpeg recording did not start' >&2 41 notify -u CRITICAL "${0##*/}" 'ffmpeg recording did not start' 42 rm -f "$lockfile" 43 exit 1 44 fi 45 } 46 47 stoprecording() { 48 out="$(tail -1 "$lockfile")" 49 kill "$(head -1 "$lockfile")" 50 rm -f "$lockfile" 51 52 if ! pgrep spoon; then 53 pkill stopwatch 54 nohup spoon >/dev/null 2>&1 & 55 fi 56 57 xrandr --output "$screen" --auto 58 59 c="$(printf 'encode\ncancel\ndelete\n' | dmenu -i -p "${out}")" 60 case "$c" in 61 encode) 62 ffmpeg -y \ 63 -i "${out}" \ 64 -itsoffset 0.300 -i "${out}" \ 65 -map 0:v -map 1:a \ 66 -c:v libx264 -threads 0 -preset faster -pix_fmt yuv420p \ 67 -c:a aac -crf 23 \ 68 "${out%.mkv}.mp4" 69 notify "${0##*}" "encoding complete: ${out%.mkv}.mp4";; 70 delete) 71 rm -f "${out}";; 72 cancel) 73 break;; 74 *) 75 notify -u CRITICAL "${0##*/}" "choice ${c} not understood" 76 exit 1;; 77 esac 78 } 79 80 if [ -f "$lockfile" ]; then 81 stoprecording 82 else 83 startrecording 84 fi