diff --git a/4-seasons.sh b/4-seasons.sh index f308b29..344ada0 100755 --- a/4-seasons.sh +++ b/4-seasons.sh @@ -86,14 +86,26 @@ temp_video="$output_dir/${yesterday}_Mvt${MVT_NUM}-temp.mp4" cleanup() { rm -f "$temp_file" "$temp_video" 2>/dev/null || true; } trap cleanup EXIT -mapfile -t images < <(find "$image_dir" -type f -name "*.jpg" | sort) +mapfile -t all_images < <(find "$image_dir" -type f -name "*.jpg" | sort) +images=() +bad=0 +for img in "${all_images[@]}"; do + if [ -r "$img" ] && [ -s "$img" ]; then + images+=("$img") + else + echo "WARNING: skipping unreadable/empty frame: $img" + ((bad++)) || true + fi +done +[ "$bad" -gt 0 ] && echo "WARNING: skipped $bad bad frame(s) out of ${#all_images[@]} found" + for img in "${images[@]}"; do printf "file '%s'\nduration %s\n" "$img" "$INTERVAL" done > "$temp_file" printf "file '%s'\n" "${images[-1]}" >> "$temp_file" # ── Step 1: Build raw video ─────────────────────────────────────────────────── -echo "Step 1/2: encoding raw video from ${#images[@]} frames..." +echo "Step 1/2: encoding raw video from ${#images[@]} frames ($(( ${#images[@]} * INTERVAL / 3600 ))h coverage)..." ffmpeg -loglevel warning \ -f concat -safe 0 -i "$temp_file" \ -c:v libx264 -pix_fmt yuv420p -preset "$ENCODE_PRESET" -crf "$CRF_SEASONS_RAW" -vsync 2 -an \ @@ -101,6 +113,14 @@ ffmpeg -loglevel warning \ raw_duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$temp_video") echo "Raw duration: $raw_duration s" +# Warn if raw video covers less than 50% of expected image count (big gap or camera outage) +expected_dur=$(echo "scale=0; ${#images[@]} * $INTERVAL" | bc) +coverage_pct=$(echo "scale=0; $raw_duration * 100 / $expected_dur" | bc 2>/dev/null || echo "?") +if [ "$coverage_pct" != "?" ] && [ "$coverage_pct" -lt 50 ]; then + echo "WARNING: raw video is ${coverage_pct}% of expected ${expected_dur}s — significant image gap detected" + "$SCRIPT_DIR/notify.sh" "WARNING: [$CAM_NAME] $SEASON Mvt$MVT_NUM Day$DAY_OF_MVT — only ${coverage_pct}% coverage ($yesterday)" \ + "Raw video ${raw_duration}s of expected ${expected_dur}s — check camera logs for gaps" || true +fi # ── Step 2: Speed-adjust to target clip duration ────────────────────────────── speed_factor=$(echo "scale=6; $raw_duration / $target_per_clip" | bc)