sky-cam.conf - Add SCRIPT_DIR (install location) and CAM_NAME (camera/folder name) - These are the only values that change when deploying to a new machine install.sh (new) - Sources sky-cam.conf, generates all systemd .service and .timer units with correct ExecStart paths, then enables and starts the timers - Run once after editing sky-cam.conf; run again if paths change - Supports --system flag for system-wide install All .sh scripts + sunrise2mm.py - No hardcoded paths remain - script_name=$(basename ...) derivation replaced by $CAM_NAME from conf - sunrise_video.10s.sh now sources sky-cam.conf for BASE_DIR, CAM_NAME, and SCRIPT_DIR (replaces all /home/motion/... references) - sunrise2mm.py builds video path from BASE_DIR + CAM_NAME in conf systemd/ template files kept as reference but no longer need editing https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
69 lines
3.3 KiB
Bash
Executable File
69 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# 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")")"
|
|
source "$SCRIPT_DIR/sky-cam.conf"
|
|
|
|
# ── Configuration ──────────────────────────────────────────────────────────────
|
|
base_dir="$BASE_DIR"
|
|
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)
|
|
image_dir="$base_dir/$CAM_NAME/$yesterday"
|
|
output_dir="$base_dir/movies/$CAM_NAME/fullday"
|
|
mkdir -p "$output_dir"
|
|
|
|
# ── Purge old full-day videos ─────────────────────────────────────────────────
|
|
echo "Removing full-day videos older than $RETENTION_DAYS days..."
|
|
find "$output_dir" -maxdepth 1 -name "*-fullday.mp4" -mtime "+$RETENTION_DAYS" -delete
|
|
|
|
# ── Sanity checks ─────────────────────────────────────────────────────────────
|
|
if [ ! -d "$image_dir" ]; then
|
|
echo "WARNING: Image directory $image_dir not found — skipping."
|
|
exit 0
|
|
fi
|
|
|
|
num_images=$(find "$image_dir" -type f -name "*.jpg" | wc -l)
|
|
if [ "$num_images" -lt 1 ]; then
|
|
echo "WARNING: No images in $image_dir — skipping."
|
|
exit 0
|
|
fi
|
|
|
|
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 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
|
|
|
|
find "$image_dir" -type f -name "*.jpg" | sort | while read -r img; do
|
|
printf "file '%s'\nduration %s\n" "$img" "$frame_dur"
|
|
done > "$temp_list"
|
|
|
|
# Append last image again (required by ffmpeg concat demuxer for images)
|
|
last_img=$(find "$image_dir" -type f -name "*.jpg" | sort | tail -n 1)
|
|
printf "file '%s'\n" "$last_img" >> "$temp_list"
|
|
|
|
# ── Encode — native camera resolution, no audio ───────────────────────────────
|
|
output_file="$output_dir/${yesterday}-fullday.mp4"
|
|
echo "Creating: $output_file"
|
|
|
|
ffmpeg -loglevel warning \
|
|
-f concat -safe 0 -i "$temp_list" \
|
|
-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 "scale=1; $actual_dur/60" | bc) min)"
|