wrds-download

TUI/CLI tool for browsing and downloading WRDS data
Log | Files | Refs | README

redact-demo.sh (2049B)


      1 #!/usr/bin/env bash
      2 # redact-demo.sh — Blur the WRDS username on the login screen of a VHS-recorded GIF.
      3 #
      4 # Usage:
      5 #   ./scripts/redact-demo.sh                                        # default paths
      6 #   ./scripts/redact-demo.sh raw.gif clean.gif                      # explicit paths
      7 #
      8 # All blur parameters can be overridden via environment variables.
      9 # Record once, inspect the raw GIF, then tweak BLUR_X/Y/W/H if needed.
     10 #
     11 # Requires: ffmpeg
     12 
     13 set -euo pipefail
     14 
     15 INPUT="${1:-demo-wrds-download-raw.gif}"
     16 OUTPUT="${2:-demo-wrds-download.gif}"
     17 
     18 if [[ ! -f "$INPUT" ]]; then
     19   echo "Error: $INPUT not found. Run 'vhs demo-wrds-download.tape' first." >&2
     20   exit 1
     21 fi
     22 
     23 if ! command -v ffmpeg &>/dev/null; then
     24   echo "Error: ffmpeg is required. Install with: brew install ffmpeg" >&2
     25   exit 1
     26 fi
     27 
     28 # ── Blur region (pixels) ──
     29 # These cover the username text inside the "Login as <user>  [enter]" button.
     30 # Calibrated from the login frame at t≈2s (1400x700, FontSize 18, Padding 20).
     31 BLUR_X="${BLUR_X:-490}"
     32 BLUR_Y="${BLUR_Y:-210}"
     33 BLUR_W="${BLUR_W:-100}"
     34 BLUR_H="${BLUR_H:-20}"
     35 
     36 # ── Time window (seconds) ──
     37 # The login screen is visible from launch until schemas load.
     38 BLUR_START="${BLUR_START:-0}"
     39 BLUR_END="${BLUR_END:-5}"
     40 
     41 # ── Pixelation factor (higher = more pixelated, less readable) ──
     42 PIXEL_FACTOR="${PIXEL_FACTOR:-10}"
     43 
     44 TEMP=$(mktemp -d)
     45 trap 'rm -rf "$TEMP"' EXIT
     46 
     47 echo "Pixelating region (${BLUR_X},${BLUR_Y}) ${BLUR_W}x${BLUR_H} during t=${BLUR_START}s-${BLUR_END}s (factor=${PIXEL_FACTOR})..."
     48 
     49 ffmpeg -y -loglevel error -i "$INPUT" -filter_complex \
     50   "[0:v]crop=${BLUR_W}:${BLUR_H}:${BLUR_X}:${BLUR_Y}, \
     51    scale=iw/${PIXEL_FACTOR}:ih/${PIXEL_FACTOR}, \
     52    scale=${BLUR_W}:${BLUR_H}:flags=neighbor[px]; \
     53    [0:v][px]overlay=${BLUR_X}:${BLUR_Y}:enable='between(t,${BLUR_START},${BLUR_END})'[v]; \
     54    [v]split[s0][s1]; \
     55    [s0]palettegen=max_colors=256:stats_mode=diff[p]; \
     56    [s1][p]paletteuse=dither=bayer:bayer_scale=3" \
     57   "$TEMP/out.gif"
     58 
     59 mv "$TEMP/out.gif" "$OUTPUT"
     60 echo "Done: $INPUT -> $OUTPUT"