Skip to content

Instantly share code, notes, and snippets.

@KylePDavis
Created September 12, 2026 07:04
Show Gist options
  • Select an option

  • Save KylePDavis/472bcbbdf1c6f96b2fa3cd84bd3a9e64 to your computer and use it in GitHub Desktop.

Select an option

Save KylePDavis/472bcbbdf1c6f96b2fa3cd84bd3a9e64 to your computer and use it in GitHub Desktop.
convert_screencapture.sh
#!/bin/bash
# Convert macOS screencapture recording to variable frame rate to better compress low motion sequences (reduces size by ~90%).
set -e -u -o pipefail
: "${INPUT:=${1:-}}"
: "${OUTPUT:=${2:-"${INPUT%.*}-$(date +%Y%m%dT%H%M%S).${INPUT##*.}"}}"
: "${Q:=55}" # video quality (0-100)
: "${G:=300}" # max I-frame gap in frames
: "${BF:=1}" # use B-frames -- videotoolbox defaults to 0 which wastes a lot on mostly static content
: "${ABR:=96k}" # audio bitrate
[ -f "$INPUT" ] || { echo "Expected input file."; exit 1; }
ffmpeg \
-hwaccel videotoolbox \
-i "$INPUT" \
-map 0:v:0 \
-map '0:a?' -c:a aac_at -b:a "$ABR" \
-map_metadata 0 \
-c:v hevc_videotoolbox -q:v "$Q" -g "$G" -bf "$BF" \
-fps_mode:v vfr -enc_time_base:v demux \
-prio_speed 0 -spatial_aq 1 \
-tag:v hvc1 \
-movflags +faststart+use_metadata_tags \
"$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment