From 98dcf236873257df262789d1320bee1aa9035ff4 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 23 Apr 2026 02:34:26 +0000 Subject: [PATCH] 4-seasons: replace size-rejection with 1MB fast-skip for grey filter File size can't reliably reject bad frames (200KB can be good or bad). Remove SEASONS_MIN_FRAME_BYTES. Instead, the grey/green uniform-colour filter (SEASONS_GREY_STDDEV_MIN) now skips the expensive ImageMagick check for files above SEASONS_LARGE_FRAME_BYTES (default 1 MB) since those are always good. Only sub-1MB files get the content check, making the filter practical on days with 40k+ images. https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ --- 4-seasons.sh | 30 ++++++++++++++++++------------ sky-cam.conf | 15 ++++++++++----- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/4-seasons.sh b/4-seasons.sh index d051a55..7429505 100755 --- a/4-seasons.sh +++ b/4-seasons.sh @@ -95,11 +95,14 @@ trap cleanup EXIT mapfile -t all_images < <(find "$image_dir" -type f -name "*.jpg" | sort) -# Validate each frame: skip empty files, corrupt JPEGs, and optionally grey/uniform frames. -# SEASONS_GREY_STDDEV_MIN=0 (default) disables the grey filter. -# Set to e.g. 5 in sky-cam.conf to drop uniform grey frames (bad-signal captures). +# Validate each frame: skip empty files and optionally uniform-colour bad-signal frames. +# SEASONS_GREY_STDDEV_MIN=0 (default) disables the content check entirely. +# When enabled, large files (> SEASONS_LARGE_FRAME_BYTES, default 1 MB) are trusted +# as good without running the expensive ImageMagick check — only sub-1MB frames +# are inspected. This keeps the filter fast even on days with 40k+ images. GREY_MIN="${SEASONS_GREY_STDDEV_MIN:-0}" -GREY_DARK_FLOOR="${SEASONS_GREY_DARK_FLOOR:-30}" # frames darker than this are never skipped +GREY_DARK_FLOOR="${SEASONS_GREY_DARK_FLOOR:-30}" +LARGE_BYTES="${SEASONS_LARGE_FRAME_BYTES:-1048576}" # files above this skip content check images=(); bad=0; grey=0 for img in "${all_images[@]}"; do # Skip empty or unreadable files (0-byte writes from camera reconnects) @@ -107,15 +110,18 @@ for img in "${all_images[@]}"; do echo "WARNING: skipping empty/missing frame: $(basename "$img")" ((bad++)) || true; continue fi - # Optional: skip uniform-grey bad-signal frames. - # A frame is bad-signal if it is BOTH uniform (low stddev) AND not dark. - # Night frames are dark so they pass even with low stddev. + # Optional: skip uniform-colour bad-signal frames (green, grey, etc.). + # Only runs ImageMagick on files below SEASONS_LARGE_FRAME_BYTES — large files + # are always good and skip the check entirely. if [ "$GREY_MIN" != "0" ] && command -v convert &>/dev/null; then - read -r stddev mean < <(convert "$img" -colorspace Gray \ - -format "%[fx:int(standard_deviation*255)] %[fx:int(mean*255)]" \ - info: 2>/dev/null || echo "255 128") - if [ "${stddev:-255}" -lt "$GREY_MIN" ] && [ "${mean:-0}" -gt "$GREY_DARK_FLOOR" ]; then - ((grey++)) || true; continue + fsize=$(stat -c%s "$img" 2>/dev/null || echo 0) + if [ "$fsize" -lt "$LARGE_BYTES" ]; then + read -r stddev mean < <(convert "$img" -colorspace Gray \ + -format "%[fx:int(standard_deviation*255)] %[fx:int(mean*255)]" \ + info: 2>/dev/null || echo "255 128") + if [ "${stddev:-255}" -lt "$GREY_MIN" ] && [ "${mean:-0}" -gt "$GREY_DARK_FLOOR" ]; then + ((grey++)) || true; continue + fi fi fi images+=("$img") diff --git a/sky-cam.conf b/sky-cam.conf index ed9d92b..597a8b1 100644 --- a/sky-cam.conf +++ b/sky-cam.conf @@ -256,18 +256,23 @@ ENCODE_PRESET=slow # ffmpeg preset for all encodes (slow/medium/fast) AUDIO_BITRATE=192k # montage-mvt.sh — music track on movement montages # ── Frame validation (4-seasons.sh) ────────────────────────────────────────── -# Corrupt or empty frames (e.g. first frame after a camera reconnect) are always -# skipped automatically via ffprobe. No config needed. +# Empty (0-byte) frames are always skipped. No config needed for that. # # SEASONS_GREY_STDDEV_MIN / SEASONS_GREY_DARK_FLOOR — optional bad-signal filter. +# Catches uniform-colour frames caused by a bad RTSP signal: solid green, grey, etc. +# These are valid JPEGs but contain no real image content. # Uncomment both lines to enable. A frame is dropped only when BOTH are true: # 1. pixel standard deviation (0–255) < SEASONS_GREY_STDDEV_MIN (frame is uniform) # 2. mean brightness (0–255) > SEASONS_GREY_DARK_FLOOR (frame is not dark) -# This keeps genuine night frames (dark + low variation) while dropping -# solid-grey bad-signal frames (mid-bright + no variation). +# Night frames are dark so they always pass even if stddev is low. # Requires ImageMagick (convert). Start with these values and tune from there: -#SEASONS_GREY_STDDEV_MIN=5 # skip if stdev < 5 (very uniform) +#SEASONS_GREY_STDDEV_MIN=5 # skip if stdev < 5 (very uniform colour) #SEASONS_GREY_DARK_FLOOR=30 # …but only if mean brightness > 30 (not a night frame) +# +# Performance: ImageMagick is only called on files below SEASONS_LARGE_FRAME_BYTES. +# Files above that threshold are always good and skip the check entirely. +# Default 1 MB — adjust if your camera produces larger bad-signal frames. +#SEASONS_LARGE_FRAME_BYTES=1048576 # ── Montage attribution overlay ─────────────────────────────────────────────── # A translucent bar across the top of each movement montage, naming the