bin/record-window 996 B raw
1
#!/usr/bin/env sh
2
set -eu
3
4
FPS=${FPS:-16}
5
SCALE=${SCALE:-1}
6
CRF=${CRF:-21}
7
NAME=${1:-capture}
8
DISPLAY=${DISPLAY:-:0.0}
9
SLOP_OPTS=${SLOP_OPTS:-}
10
11
need() {
12
  command -v "$1" >/dev/null 2>&1 || {
13
    printf "fatal: %s not found\n" "$1"; exit 1;
14
  };
15
}
16
17
need slop
18
need ffmpeg
19
20
# Pick region/window: "x y w h"
21
set -- $(slop $SLOP_OPTS -f '%x %y %w %h') || { printf "aborted\n"; exit 1; }
22
x=$1 y=$2 w=$3 h=$4
23
24
VF="crop=iw-2:ih-2:1:1,fps=${FPS},scale=trunc(iw*${SCALE}/2)*2:trunc(ih*${SCALE}/2)*2"
25
ts=$(date +"%Y%m%d-%H%M%S")
26
out="${NAME}-${ts}.webm"
27
28
printf "recording… to %s (Ctrl-C)\n" "$out"
29
30
# Run ffmpeg in the foreground so it handles Ctrl-C itself and finalizes cleanly
31
exec ffmpeg -v warning \
32
  -video_size "${w}x${h}" \
33
  -framerate "${FPS}" \
34
  -f x11grab -i "${DISPLAY}+${x},${y}" \
35
  -vf "${VF}" \
36
  -c:v libvpx-vp9 -crf "${CRF}" -b:v 0 \
37
  -row-mt 1 -tile-columns 2 -tile-rows 1 \
38
  -pix_fmt yuv420p \
39
  "${out}"
40
41
# TIP: convert FILE.gif -strip -coalesce -layers Optimize OPTIMIZED.gif