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:
+22
-36
@@ -1,24 +1,22 @@
|
||||
#!/bin/bash
|
||||
# fullday-video.sh — create an ~30-minute timelapse of yesterday's full day of
|
||||
# images. Files older than 10 days are deleted automatically to save space.
|
||||
# Run once per day (e.g. from cron at 02:00, after 4-seasons.sh).
|
||||
# fullday-video.sh — create a natural-speed timelapse of yesterday's full day of
|
||||
# images at a fixed frame rate. Files older than RETENTION_DAYS are deleted
|
||||
# automatically. Sunrise 10-second uploads and montage videos are NOT touched.
|
||||
#
|
||||
# Run once per day from cron (e.g. 02:00 daily, after 4-seasons.sh).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
|
||||
# ── Configuration ──────────────────────────────────────────────────────────────
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
script_name=$(basename "$(dirname "$(realpath "$0")")" | cut -d'-' -f1)
|
||||
|
||||
TARGET_DURATION=1800 # target video length in seconds (~30 min)
|
||||
MIN_FRAME_DUR=0.016667 # max 60 fps
|
||||
MAX_FRAME_DUR=10.0 # min 0.1 fps (10 s per frame)
|
||||
RETENTION_DAYS=10
|
||||
|
||||
TARGET_W=1280
|
||||
TARGET_H=720
|
||||
FULLDAY_FPS=5 # timelapse frame rate — adjust to taste
|
||||
RETENTION_DAYS=10 # full-day videos older than this are deleted
|
||||
|
||||
# ── Date / paths ──────────────────────────────────────────────────────────────
|
||||
yesterday=$(date --date="yesterday" +%Y-%m-%d)
|
||||
script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1)
|
||||
image_dir="$base_dir/$script_name/$yesterday"
|
||||
output_dir="$base_dir/movies/$script_name/fullday"
|
||||
mkdir -p "$output_dir"
|
||||
@@ -35,48 +33,36 @@ fi
|
||||
|
||||
num_images=$(find "$image_dir" -type f -name "*.jpg" | wc -l)
|
||||
if [ "$num_images" -lt 1 ]; then
|
||||
echo "WARNING: No images found in $image_dir — skipping."
|
||||
echo "WARNING: No images in $image_dir — skipping."
|
||||
exit 0
|
||||
fi
|
||||
echo "Images: $num_images"
|
||||
|
||||
# ── Calculate per-frame duration to hit TARGET_DURATION ───────────────────────
|
||||
frame_dur=$(echo "scale=6; $TARGET_DURATION / $num_images" | bc)
|
||||
|
||||
# Clamp to [MIN_FRAME_DUR, MAX_FRAME_DUR]
|
||||
if (( $(echo "$frame_dur < $MIN_FRAME_DUR" | bc -l) )); then frame_dur=$MIN_FRAME_DUR; fi
|
||||
if (( $(echo "$frame_dur > $MAX_FRAME_DUR" | bc -l) )); then frame_dur=$MAX_FRAME_DUR; fi
|
||||
|
||||
fps=$(echo "scale=4; 1 / $frame_dur" | bc)
|
||||
approx_min=$(echo "scale=1; $num_images * $frame_dur / 60" | bc)
|
||||
echo "Frame duration: ${frame_dur}s (fps=${fps}) ≈ ${approx_min} min"
|
||||
frame_dur=$(echo "scale=6; 1 / $FULLDAY_FPS" | bc)
|
||||
approx_min=$(echo "scale=1; $num_images / $FULLDAY_FPS / 60" | bc)
|
||||
echo "Images: $num_images at ${FULLDAY_FPS} fps ≈ ${approx_min} min"
|
||||
|
||||
# ── Build concat list with per-frame duration ─────────────────────────────────
|
||||
# The concat demuxer requires the last file to be repeated without a duration.
|
||||
# The concat demuxer needs an explicit duration per image; the last file is
|
||||
# repeated without a duration to correctly anchor the final frame's pts.
|
||||
temp_list=$(mktemp --suffix=.txt)
|
||||
trap 'rm -f "$temp_list"' EXIT
|
||||
|
||||
last_img=""
|
||||
find "$image_dir" -type f -name "*.jpg" | sort | while read -r img; do
|
||||
echo "file '$img'"
|
||||
echo "duration $frame_dur"
|
||||
last_img="$img"
|
||||
printf "file '%s'\nduration %s\n" "$img" "$frame_dur"
|
||||
done > "$temp_list"
|
||||
|
||||
# Append last image again (required by concat demuxer to set final frame pts)
|
||||
# Append last image again (required by ffmpeg concat demuxer for images)
|
||||
last_img=$(find "$image_dir" -type f -name "*.jpg" | sort | tail -n 1)
|
||||
echo "file '$last_img'" >> "$temp_list"
|
||||
printf "file '%s'\n" "$last_img" >> "$temp_list"
|
||||
|
||||
# ── Encode ────────────────────────────────────────────────────────────────────
|
||||
# ── Encode — native camera resolution, no audio ───────────────────────────────
|
||||
output_file="$output_dir/${yesterday}-fullday.mp4"
|
||||
echo "Creating full-day video: $output_file"
|
||||
echo "Creating: $output_file"
|
||||
|
||||
ffmpeg -loglevel warning \
|
||||
-f concat -safe 0 -i "$temp_list" \
|
||||
-vf "scale=${TARGET_W}:${TARGET_H}:force_original_aspect_ratio=decrease,\
|
||||
pad=${TARGET_W}:${TARGET_H}:(ow-iw)/2:(oh-ih)/2,setsar=1" \
|
||||
-c:v libx264 -pix_fmt yuv420p -crf 28 \
|
||||
-an -y "$output_file"
|
||||
|
||||
actual_dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$output_file")
|
||||
echo "Done: $output_file (${actual_dur}s)"
|
||||
echo "Done: $output_file (${actual_dur}s / $(echo "scale=1; $actual_dur/60" | bc) min)"
|
||||
|
||||
Reference in New Issue
Block a user