record (2308B)
1 #!/bin/sh 2 3 # v4l2-ctl -c exposure_time_absolute=250 4 5 case "$(printf "%s\n" change screenkey record stop camera last-video | dmenu)" in 6 change) 7 set -- $(printf "%s\n" 1920x1080 1080x1920 720x1280 480x848 | dmenu | tr x ' ') 8 video_width=$1 9 video_height=$2 10 screen_width=$(echo "16 * ${video_height} / 9" | bc) 11 offset=$(echo "($(echo "scale=16; (${screen_width} - ${video_width}) / 2.0" | bc) + 0.5)/1" | bc) 12 dpi=$(echo "${video_height} / 8.88888888888889" | bc) 13 14 xrandr --delmonitor my-monitor-0 15 xrandr --output eDP-1 --scale-from "${screen_width}x${video_height}" 16 xrandr --setmonitor my-monitor-0 "${video_width}/${video_width}x${video_height}/${video_height}+${offset}+0" eDP-1 17 echo "Xft.dpi: ${dpi}" | xrdb -m 18 xrandr --dpi "${dpi}" 19 ;; 20 21 screenkey) 22 screenkey --mods-mode=emacs --font=monospace --font-size=small --mouse --opacity=0 23 ;; 24 25 record) 26 [ -f /tmp/recordingpid ] && exit 27 set -- $(xrandr --listactivemonitors | grep -oP '(?<=my-monitor-0 ).*(?= )' | sed 's/\([[:digit:]]\+\)\/[[:digit:]]\+x\([[:digit:]]\+\)\/[[:digit:]]\++\([[:digit:]]\+\)+0/\1 \2 \3/') 28 video_width=$1 29 video_height=$2 30 offset=$3 31 ffmpeg \ 32 -f x11grab \ 33 -s "${video_width}x${video_height}" \ 34 -i "${DISPLAY}.0+${offset},0" \ 35 -f pulse \ 36 -i default \ 37 -c:v libx264 \ 38 -b:v 1000k \ 39 -minrate:v 500k \ 40 -maxrate:v 2500k \ 41 -bufsize:v 5000k \ 42 -pix_fmt yuv422p \ 43 "${HOME}/vids/$(date +%Y-%m-%d_%H-%M-%S || true).mp4" & 44 echo $! > /tmp/recordingpid 45 ;; 46 stop) 47 [ ! -f /tmp/recordingpid ] && exit 48 recpid="$(cat /tmp/recordingpid)" 49 kill -15 "$recpid" 50 rm -f /tmp/recordingpid 51 ;; 52 53 camera) 54 set -- $(xrandr --listactivemonitors | grep -oP '(?<=my-monitor-0 ).*(?= )' | sed 's/\([[:digit:]]\+\)\/[[:digit:]]\+x\([[:digit:]]\+\)\/[[:digit:]]\++\([[:digit:]]\+\)+0/\1 \2 \3/') 55 video_width=$1 56 video_height=$2 57 camera_height=$(echo "9 * ${video_width} / 16" | bc) 58 v4l2-ctl -d /dev/video0 --try-fmt-video width="${video_width}",height="${camera_height}",pixelformat=MJPG 59 mpv --no-osc --profile=low-latency --untimed --demuxer-lavf-format=video4linux2 --demuxer-lavf-o-set="input_format=mjpeg" /dev/video0 60 ;; 61 62 last-video) 63 last_video="$(find ~/vids -printf "%T@\t%p\n" | sort -r | head -n 1 | awk '{ print $2 }' || true)" 64 printf '%s' "${last_video}" | xclip -sel clip 65 mpv "${last_video}" 66 67 ;; 68 *) 69 ;; 70 esac