| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -eo pipefail |
|
|
| DRY=0 |
| for arg in "$@"; do |
| case "$arg" in |
| --dry-run) DRY=1 ;; |
| -h|--help) sed -n '2,15p' "$0"; exit 0 ;; |
| *) echo "Unknown arg: $arg" >&2; exit 1 ;; |
| esac |
| done |
|
|
| |
| RULES=( |
| |
| "videos/youtube/tennis/0001_pt*.mp4|drawbox=x=32:y=306:w=134:h=38:color=black:t=fill" |
| |
| "videos/youtube/tennis/0002_pt*.mp4|drawbox=x=32:y=306:w=134:h=38:color=black:t=fill" |
| |
| "videos/youtube/basketball/0002_pt*.mp4|drawbox=x=98:y=323:w=443:h=37:color=black:t=fill" |
| |
| "videos/youtube/basketball/0003_pt*.mp4|drawbox=x=22:y=285:w=125:h=63:color=black:t=fill" |
| |
| "videos/youtube/soccer/0002_pt*.mp4|drawbox=x=0:y=0:w=122:h=19:color=black:t=fill,drawbox=x=140:y=320:w=360:h=40:color=black:t=fill" |
| ) |
|
|
| if ! command -v ffmpeg >/dev/null 2>&1; then |
| echo "ERROR: ffmpeg not installed. brew install ffmpeg / apt install ffmpeg" >&2 |
| exit 1 |
| fi |
|
|
| |
| |
| |
| canonical_paths_for_glob() { |
| glob="$1" |
| dir=$(dirname "$glob") |
| pat=$(basename "$glob") |
| shopt -s nullglob |
| results="" |
| for f in "$dir"/$pat "$dir"/${pat%.mp4}_redacted.mp4; do |
| [ -e "$f" ] || continue |
| case "$f" in |
| *_redacted.mp4) base="${f%_redacted.mp4}.mp4" ;; |
| *) base="$f" ;; |
| esac |
| results="${results}${base}"$'\n' |
| done |
| shopt -u nullglob |
| printf '%s' "$results" | sort -u | sed '/^$/d' |
| } |
|
|
| total=0; ok=0; fail=0; missing=0 |
|
|
| for rule in "${RULES[@]}"; do |
| glob="${rule%%|*}" |
| filt="${rule#*|}" |
| echo |
| echo "=== $glob ===" |
| echo " filter: $filt" |
|
|
| paths=$(canonical_paths_for_glob "$glob") |
| if [ -z "$paths" ]; then |
| echo " (no matching files)" |
| continue |
| fi |
|
|
| while IFS= read -r canon; do |
| [ -z "$canon" ] && continue |
| total=$((total+1)) |
| redacted_sibling="${canon%.mp4}_redacted.mp4" |
|
|
| |
| if [ -f "$redacted_sibling" ]; then |
| input="$redacted_sibling" |
| elif [ -f "$canon" ]; then |
| input="$canon" |
| else |
| echo " ! missing both $canon and $redacted_sibling" |
| missing=$((missing+1)) |
| continue |
| fi |
|
|
| if [ "$DRY" -eq 1 ]; then |
| echo " [DRY] $input =[$filt]=> $canon" |
| ok=$((ok+1)) |
| continue |
| fi |
|
|
| |
| |
| |
| tmp="${canon%.mp4}.redact.tmp.mp4" |
| if ! ffmpeg -y -loglevel error -nostdin -i "$input" -vf "$filt" -c:a copy "$tmp"; then |
| echo " ! ffmpeg failed: $input" |
| fail=$((fail+1)) |
| continue |
| fi |
| if cp -f "$tmp" "$canon" && rm -f "$tmp"; then |
| : |
| else |
| echo " ! could not write $canon (kept tmp at $tmp)" |
| fail=$((fail+1)) |
| continue |
| fi |
| |
| |
| if [ -f "$redacted_sibling" ] && [ "$redacted_sibling" != "$canon" ]; then |
| rm -f "$redacted_sibling" 2>/dev/null || true |
| fi |
| ok=$((ok+1)) |
| echo " -> $canon" |
| done <<< "$paths" |
| done |
|
|
| echo |
| echo "============================================================" |
| echo " total: $total ok: $ok fail: $fail missing: $missing" |
| echo "============================================================" |
| [ "$fail" -eq 0 ] && [ "$missing" -eq 0 ] |
|
|