Fix season dates, resolution, attribution, retention policies, montage trigger

season_info.py (new):
- Computes actual equinox/solstice dates via Jean Meeus approximation
- Converts to LOCAL timezone (pytz / zoneinfo) so the calendar date reflects
  what the camera sees on the ground, including DST transitions
- Timezone defaults to America/New_York; override via $TIMEZONE env or 2nd arg
- Divides each season into 3 equal movements; handles Winter's year boundary
- Outputs IS_LAST_DAY=true on the final day of each movement

4-seasons.sh:
- Uses season_info.py for all date/season logic (no hardcoded day-of-year)
- Passes $yesterday to season_info.py so astronomical dates are correct
- Removed forced 1280x720 scale; clips stay at native camera resolution
- Auto-triggers montage-mvt.sh "$yesterday" on last day of movement so the
  correct movement (not the next day's) is compiled

montage-mvt.sh:
- Accepts optional YYYY-MM-DD argument (passed by 4-seasons.sh) so it
  resolves the correct season/movement when run the morning after last day
- Detects source resolution from first daily clip via ffprobe; attribution
  card is generated at that exact resolution — no resizing of main video
- Font sizes proportional to frame height so text looks right at any res
- License corrected to CC BY-SA 3.0 (was CC BY-NC-SA 4.0)

fullday-video.sh:
- Removed 30-minute target; video length is natural (num_images / FPS)
- Default FULLDAY_FPS=5 (configurable at top of script)
- Retains RETENTION_DAYS=10 auto-delete for full-day videos only
- Sunrise 10s uploads and montage videos are never auto-deleted

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
Claude
2026-04-18 03:36:34 +00:00
parent 009f6b4b64
commit 9403e3ca46
4 changed files with 305 additions and 178 deletions
+47 -66
View File
@@ -1,123 +1,104 @@
#!/bin/bash
# 4-seasons.sh — create one daily clip from yesterday's images, sized to its
# share of the corresponding Vivaldi movement's music duration.
# Run once per day (e.g. from cron at 01:00).
#
# On the last day of a movement period, automatically runs montage-mvt.sh to
# compile the full movement montage.
#
# Run once per day from cron (e.g. 01:00 daily).
set -euo pipefail
set -x
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
# ── Configuration ──────────────────────────────────────────────────────────────
base_dir="/home/motion/drives/local-2tb"
music_base_dir="$base_dir/music/4 Seasons"
# Fallback: use music/ directory next to this script (repo copy)
[ ! -d "$music_base_dir" ] && music_base_dir="$(dirname "$(realpath "$0")")/music"
TARGET_W=1280
TARGET_H=720
[ ! -d "$music_base_dir" ] && music_base_dir="$SCRIPT_DIR/music"
# ── Date setup ────────────────────────────────────────────────────────────────
yesterday=$(date --date="yesterday" +%Y-%m-%d)
day_of_year=$(date --date="$yesterday" +%j | sed 's/^0*//') # strip leading zeros
echo "Processing: $yesterday"
# ── Season / movement detection ────────────────────────────────────────────────
if [ "$day_of_year" -ge 80 ] && [ "$day_of_year" -le 172 ]; then
season="Spring"; season_start=80; days_in_season=93
elif [ "$day_of_year" -ge 173 ] && [ "$day_of_year" -le 264 ]; then
season="Summer"; season_start=173; days_in_season=92
elif [ "$day_of_year" -ge 265 ] && [ "$day_of_year" -le 355 ]; then
season="Autumn"; season_start=265; days_in_season=91
else
season="Winter"; days_in_season=90
if [ "$day_of_year" -ge 356 ]; then season_start=356; else season_start=0; fi
fi
# ── Season / movement info from astronomical calculation ──────────────────────
eval "$(python3 "$SCRIPT_DIR/season_info.py" "$yesterday")"
# Provides: SEASON MVT_NUM DAY_OF_MVT DAYS_IN_MVT MVT_START MVT_END IS_LAST_DAY
echo "Season=$SEASON Mvt=$MVT_NUM Day=$DAY_OF_MVT/$DAYS_IN_MVT LastDay=$IS_LAST_DAY"
# Day within the season (1-based)
if [ "$season" = "Winter" ] && [ "$day_of_year" -lt 80 ]; then
day_of_season=$(( day_of_year + 365 - 355 ))
elif [ "$season" = "Winter" ]; then
day_of_season=$(( day_of_year - 355 ))
else
day_of_season=$(( day_of_year - season_start + 1 ))
fi
# Each season: three movements of ~30 days; Mvt 3 takes the remainder
if [ "$day_of_season" -le 30 ]; then movement_num=1; days_in_movement=30
elif [ "$day_of_season" -le 60 ]; then movement_num=2; days_in_movement=30
else movement_num=3; days_in_movement=$(( days_in_season - 60 ))
fi
echo "Date=$yesterday Season=$season Mvt=$movement_num DayOfSeason=$day_of_season DaysInMvt=$days_in_movement"
# ── Locate music file ─────────────────────────────────────────────────────────
music_file=$(find "$music_base_dir" -type f -iname "*${season}*Mvt*${movement_num}*" | sort | head -n 1)
# ── Locate music file and get its duration ────────────────────────────────────
music_file=$(find "$music_base_dir" -type f -iname "*${SEASON}*Mvt*${MVT_NUM}*" | sort | head -n 1)
if [ -z "$music_file" ] || [ ! -f "$music_file" ]; then
echo "ERROR: Music file not found for $season Mvt $movement_num in $music_base_dir"
echo "ERROR: Music file not found for $SEASON Mvt $MVT_NUM in $music_base_dir"
exit 1
fi
music_duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$music_file")
echo "Music: $(basename "$music_file") ($music_duration s)"
# Each daily clip should cover music_duration / days_in_movement seconds so that
# the full movement montage sums to exactly the music duration.
target_duration_per_video=$(echo "scale=6; $music_duration / $days_in_movement" | bc)
echo "Target duration per daily clip: $target_duration_per_video s"
# Each daily clip covers music_duration / DAYS_IN_MVT seconds so that
# concatenating all clips for the movement sums to the exact music duration.
target_per_clip=$(echo "scale=6; $music_duration / $DAYS_IN_MVT" | bc)
echo "Target clip duration: $target_per_clip s ($DAYS_IN_MVT days in movement)"
# ── Locate images ─────────────────────────────────────────────────────────────
script_name=$(basename "$(dirname "$(realpath "$0")")" | cut -d'-' -f1)
# ── Locate yesterday's images ─────────────────────────────────────────────────
script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1)
image_dir="$base_dir/$script_name/$yesterday"
if [ ! -d "$image_dir" ]; then
echo "WARNING: Image directory $image_dir not found for $yesterday — skipping."
echo "WARNING: Image directory $image_dir not found — skipping $yesterday."
exit 0
fi
total_images=$(find "$image_dir" -type f -name "*.jpg" | wc -l)
if [ "$total_images" -lt 1 ]; then
echo "WARNING: No images in $image_dir for $yesterday — skipping."
echo "WARNING: No images in $image_dir — skipping $yesterday."
exit 0
fi
echo "Images found: $total_images"
# ── Prepare output directory ──────────────────────────────────────────────────
output_dir="$base_dir/movies/$script_name/$season/Mvt$movement_num"
output_dir="$base_dir/movies/$script_name/$SEASON/Mvt$MVT_NUM"
mkdir -p "$output_dir"
# ── Build sorted image list ───────────────────────────────────────────────────
# ── Build sorted image list ───────────────────────────────────────────────────
temp_file=$(mktemp --suffix=.txt)
trap 'rm -f "$temp_file" "$temp_video"' EXIT
temp_video="$output_dir/${yesterday}_Mvt${MVT_NUM}-temp.mp4"
cleanup() { rm -f "$temp_file" "$temp_video" 2>/dev/null || true; }
trap cleanup EXIT
find "$image_dir" -type f -name "*.jpg" | sort | while read -r img; do
echo "file '$img'"
done > "$temp_file"
num_images=$(wc -l < "$temp_file")
echo "Images: $num_images"
# ── Step 1: Build raw video at default frame rate ─────────────────────────────
temp_video="$output_dir/${yesterday}_Mvt${movement_num}-temp.mp4"
echo "Creating raw video..."
echo "Step 1/2: encoding raw video..."
ffmpeg -loglevel warning \
-f concat -safe 0 -i "$temp_file" \
-c:v libx264 -pix_fmt yuv420p -crf 28 -vsync 2 -an \
-y "$temp_video"
raw_duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$temp_video")
echo "Raw video duration: $raw_duration s"
echo "Raw duration: $raw_duration s"
# ── Step 2: Speed-adjust to target duration + normalise resolution ─────────────
speed_factor=$(echo "scale=6; $raw_duration / $target_duration_per_video" | bc)
echo "Speed factor: $speed_factor"
# ── Step 2: Speed-adjust to target clip duration ──────────────────────────────
speed_factor=$(echo "scale=6; $raw_duration / $target_per_clip" | bc)
echo "Step 2/2: speed factor $speed_factor..."
final_file="$output_dir/${yesterday}_Mvt${movement_num}-Day${day_of_season}of${days_in_movement}-final.mp4"
final_file="$output_dir/${yesterday}_Mvt${MVT_NUM}-Day${DAY_OF_MVT}of${DAYS_IN_MVT}-final.mp4"
ffmpeg -loglevel warning \
-i "$temp_video" \
-vf "setpts=PTS/$speed_factor,\
scale=${TARGET_W}:${TARGET_H}:force_original_aspect_ratio=decrease,\
pad=${TARGET_W}:${TARGET_H}:(ow-iw)/2:(oh-ih)/2,setsar=1" \
-vf "setpts=PTS/$speed_factor" \
-c:v libx264 -pix_fmt yuv420p -crf 26 \
-t "$target_duration_per_video" \
-t "$target_per_clip" -an \
-y "$final_file"
rm "$temp_video"
adjusted=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$final_file")
echo "Daily clip: $final_file ($adjusted s)"
adjusted_duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$final_file")
echo "Daily clip created: $final_file ($adjusted_duration s)"
# ── Auto-trigger montage on last day of movement ──────────────────────────────
if [ "$IS_LAST_DAY" = "true" ]; then
echo "Last day of $SEASON Mvt $MVT_NUM — triggering montage compilation..."
# Pass $yesterday so montage-mvt.sh looks up the correct movement
# (running the next morning, "today" would already be the next movement).
"$SCRIPT_DIR/montage-mvt.sh" "$yesterday"
fi