Merge pull request #4 from outis1one/claude/seasonal-sunrise-montage-nn268
Claude/seasonal sunrise montage nn268
This commit is contained in:
+7
-5
@@ -11,10 +11,11 @@ set -euo pipefail
|
||||
set -x
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
source "$SCRIPT_DIR/sky-cam.conf"
|
||||
|
||||
# ── Configuration ──────────────────────────────────────────────────────────────
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
music_base_dir="$base_dir/music/4 Seasons"
|
||||
base_dir="$BASE_DIR"
|
||||
music_base_dir="$MUSIC_DIR"
|
||||
[ ! -d "$music_base_dir" ] && music_base_dir="$SCRIPT_DIR/music"
|
||||
|
||||
# ── Date setup ────────────────────────────────────────────────────────────────
|
||||
@@ -23,8 +24,9 @@ echo "Processing: $yesterday"
|
||||
|
||||
# ── 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"
|
||||
# Provides: SEASON MVT_NUM DAY_OF_MVT DAYS_IN_MVT MVT_START MVT_END
|
||||
# IS_LAST_DAY ASTRO_YEAR
|
||||
echo "Season=$SEASON Mvt=$MVT_NUM Year=$ASTRO_YEAR Day=$DAY_OF_MVT/$DAYS_IN_MVT LastDay=$IS_LAST_DAY"
|
||||
|
||||
# ── Locate music file and get its duration ────────────────────────────────────
|
||||
music_file=$(find "$music_base_dir" -type f -iname "*${SEASON}*Mvt*${MVT_NUM}*" | sort | head -n 1)
|
||||
@@ -57,7 +59,7 @@ fi
|
||||
echo "Images found: $total_images"
|
||||
|
||||
# ── Prepare output directory ──────────────────────────────────────────────────
|
||||
output_dir="$base_dir/movies/$script_name/$SEASON/Mvt$MVT_NUM"
|
||||
output_dir="$base_dir/movies/$script_name/$ASTRO_YEAR/$SEASON/Mvt$MVT_NUM"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
# ── Build sorted image list ───────────────────────────────────────────────────
|
||||
|
||||
+2
-1
@@ -8,9 +8,10 @@
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
source "$SCRIPT_DIR/sky-cam.conf"
|
||||
|
||||
# ── Configuration ──────────────────────────────────────────────────────────────
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
base_dir="$BASE_DIR"
|
||||
FULLDAY_FPS=5 # timelapse frame rate — adjust to taste
|
||||
RETENTION_DAYS=10 # full-day videos older than this are deleted
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 368 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 406 KiB |
+109
-97
@@ -1,52 +1,57 @@
|
||||
#!/bin/bash
|
||||
# montage-mvt.sh — compile all daily clips for the current Vivaldi movement into
|
||||
# a single montage that exactly matches the music duration, with 2-second
|
||||
# audio/video fade in/out and a 7-second attribution card appended.
|
||||
# montage-mvt.sh — compile one Vivaldi movement's daily clips into a montage.
|
||||
#
|
||||
# Duration matches the movement's music exactly. Attribution is overlaid as a
|
||||
# translucent bar across the top of the video for the first ATTR_DUR seconds
|
||||
# (fade in/out) — no separate card appended, so year-end joining is a plain
|
||||
# concat with no duplicate attribution concerns.
|
||||
#
|
||||
# Called automatically by 4-seasons.sh on the last day of each movement.
|
||||
# Can also be run manually (e.g. to build a partial mid-season preview).
|
||||
# Can also be run manually for a mid-season preview.
|
||||
#
|
||||
# On the last day of Autumn Mvt 3, automatically triggers year-end-join.sh.
|
||||
#
|
||||
# Music: "The Four Seasons" by Antonio Vivaldi
|
||||
# Performed by John Harrison with the Wichita State University Chamber Players
|
||||
# Source: Free Music Archive — freemusicarchive.org
|
||||
# License: CC BY-SA 3.0 — creativecommons.org/licenses/by-sa/3.0
|
||||
# License: CC BY-SA 3.0
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
source "$SCRIPT_DIR/sky-cam.conf"
|
||||
|
||||
# ── Configuration ──────────────────────────────────────────────────────────────
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
music_base_dir="$base_dir/music/4 Seasons"
|
||||
base_dir="$BASE_DIR"
|
||||
music_base_dir="$MUSIC_DIR"
|
||||
[ ! -d "$music_base_dir" ] && music_base_dir="$SCRIPT_DIR/music"
|
||||
|
||||
FADE_DUR=2.0 # seconds for video + audio fade in/out
|
||||
ATTR_DUR=7 # duration of attribution card in seconds
|
||||
FADE_DUR=2.0 # video + audio fade in/out (seconds)
|
||||
ATTR_DUR=6 # attribution overlay duration (seconds from start)
|
||||
ATTR_FADE=1 # attribution fade in / fade out duration
|
||||
|
||||
# ── Season / movement info ────────────────────────────────────────────────────
|
||||
# Optional first argument: YYYY-MM-DD of the last day of the movement to compile.
|
||||
# Used when called automatically from 4-seasons.sh (which processes yesterday's
|
||||
# images the next morning, so "today" would already be the next movement).
|
||||
# When run manually with no argument, uses today — correct for same-day runs.
|
||||
DATE_ARG="${1:-}"
|
||||
eval "$(python3 "$SCRIPT_DIR/season_info.py" ${DATE_ARG:+"$DATE_ARG"})"
|
||||
echo "Season=$SEASON Mvt=$MVT_NUM Day=$DAY_OF_MVT/$DAYS_IN_MVT (ref date: ${DATE_ARG:-today})"
|
||||
# Provides: SEASON MVT_NUM DAY_OF_MVT DAYS_IN_MVT MVT_START MVT_END
|
||||
# IS_LAST_DAY ASTRO_YEAR
|
||||
echo "Season=$SEASON Mvt=$MVT_NUM Year=$ASTRO_YEAR (ref: ${DATE_ARG:-today})"
|
||||
|
||||
# ── Locate files ──────────────────────────────────────────────────────────────
|
||||
script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1)
|
||||
video_dir="$base_dir/movies/$script_name/$SEASON/Mvt$MVT_NUM"
|
||||
video_dir="$base_dir/movies/$script_name/$ASTRO_YEAR/$SEASON/Mvt$MVT_NUM"
|
||||
output_dir="$video_dir/montage"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
music_file=$(find "$music_base_dir" -type f -iname "*${SEASON}*Mvt*${MVT_NUM}*" | sort | head -n 1)
|
||||
if [ -z "$music_file" ]; then
|
||||
echo "ERROR: Music file not found for $SEASON Mvt $MVT_NUM"
|
||||
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)"
|
||||
echo "Music: $(basename "$music_file") (${music_duration}s)"
|
||||
|
||||
# ── Collect sorted daily clips ─────────────────────────────────────────────────
|
||||
# ── Collect sorted daily clips ────────────────────────────────────────────────
|
||||
mapfile -d '' daily_clips < <(find "$video_dir" -maxdepth 1 -name "*-final.mp4" -print0 | sort -z)
|
||||
if [ "${#daily_clips[@]}" -eq 0 ]; then
|
||||
echo "ERROR: No *-final.mp4 clips in $video_dir"
|
||||
@@ -54,65 +59,13 @@ if [ "${#daily_clips[@]}" -eq 0 ]; then
|
||||
fi
|
||||
echo "Found ${#daily_clips[@]} daily clips"
|
||||
|
||||
# ── Detect source resolution from first clip ──────────────────────────────────
|
||||
# The attribution card is created at this same resolution so nothing is resized.
|
||||
# ── Source resolution ─────────────────────────────────────────────────────────
|
||||
VIDEO_W=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 "${daily_clips[0]}")
|
||||
VIDEO_H=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 "${daily_clips[0]}")
|
||||
echo "Source resolution: ${VIDEO_W}x${VIDEO_H}"
|
||||
|
||||
# ── Temp-file tracking ────────────────────────────────────────────────────────
|
||||
TMPFILES=()
|
||||
cleanup() { rm -f "${TMPFILES[@]}" 2>/dev/null || true; }
|
||||
trap cleanup EXIT
|
||||
|
||||
concat_list=$(mktemp --suffix=.txt); TMPFILES+=("$concat_list")
|
||||
printf "file '%s'\n" "${daily_clips[@]}" > "$concat_list"
|
||||
|
||||
# ── Step 1: Concatenate clips, normalising to source resolution ───────────────
|
||||
# Normalise in case any clip differs (e.g. camera settings changed on one day).
|
||||
temp_concat=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_concat")
|
||||
echo "Step 1/5: concatenating ${#daily_clips[@]} clips..."
|
||||
ffmpeg -loglevel warning \
|
||||
-f concat -safe 0 -i "$concat_list" \
|
||||
-vf "scale=${VIDEO_W}:${VIDEO_H}:force_original_aspect_ratio=decrease,\
|
||||
pad=${VIDEO_W}:${VIDEO_H}:(ow-iw)/2:(oh-ih)/2,setsar=1" \
|
||||
-c:v libx264 -pix_fmt yuv420p -crf 26 -an \
|
||||
-y "$temp_concat"
|
||||
|
||||
# ── Step 2: Speed-adjust to match music duration exactly ──────────────────────
|
||||
concat_dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$temp_concat")
|
||||
speed_factor=$(echo "scale=6; $concat_dur / $music_duration" | bc)
|
||||
echo "Step 2/5: speed factor $speed_factor (raw=${concat_dur}s music=${music_duration}s)"
|
||||
|
||||
temp_sped=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_sped")
|
||||
ffmpeg -loglevel warning \
|
||||
-i "$temp_concat" \
|
||||
-vf "setpts=PTS/$speed_factor" \
|
||||
-c:v libx264 -pix_fmt yuv420p -crf 26 -an \
|
||||
-t "$music_duration" -y "$temp_sped"
|
||||
rm "$temp_concat"
|
||||
|
||||
# ── Step 3: Merge with music + 2-second video/audio fade in/out ───────────────
|
||||
fade_out_start=$(echo "scale=3; $music_duration - $FADE_DUR" | bc)
|
||||
echo "Step 3/5: adding music and fades..."
|
||||
|
||||
temp_main=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_main")
|
||||
ffmpeg -loglevel warning \
|
||||
-i "$temp_sped" -i "$music_file" \
|
||||
-filter_complex \
|
||||
"[0:v]fade=t=in:st=0:d=${FADE_DUR},fade=t=out:st=${fade_out_start}:d=${FADE_DUR}[vout];\
|
||||
[1:a]afade=t=in:st=0:d=${FADE_DUR},afade=t=out:st=${fade_out_start}:d=${FADE_DUR}[aout]" \
|
||||
-map "[vout]" -map "[aout]" \
|
||||
-c:v libx264 -pix_fmt yuv420p -c:a aac -b:a 192k \
|
||||
-t "$music_duration" -y "$temp_main"
|
||||
rm "$temp_sped"
|
||||
|
||||
# ── Step 4: Create 7-second attribution card at source resolution ─────────────
|
||||
# Resolution matches the video — no resizing of the main montage required.
|
||||
echo "Step 4/5: creating attribution card at ${VIDEO_W}x${VIDEO_H}..."
|
||||
|
||||
FONT=""
|
||||
FONT_BOLD=""
|
||||
# ── Font detection ────────────────────────────────────────────────────────────
|
||||
FONT=""; FONT_BOLD=""
|
||||
if command -v fc-match &>/dev/null; then
|
||||
FONT=$(fc-match "DejaVu Sans:style=Regular" --format="%{file}" 2>/dev/null || true)
|
||||
FONT_BOLD=$(fc-match "DejaVu Sans:style=Bold" --format="%{file}" 2>/dev/null || true)
|
||||
@@ -128,32 +81,91 @@ if [ -z "$FONT" ]; then
|
||||
fi
|
||||
[ -z "$FONT_BOLD" ] && FONT_BOLD="$FONT"
|
||||
|
||||
# Font sizes are proportional to frame height so they look right at any resolution.
|
||||
# Colons inside drawtext text values must be escaped as \: (\\: in bash double-quotes).
|
||||
DT="drawtext=fontfile='${FONT_BOLD}':text='The Four Seasons - Antonio Vivaldi':fontcolor=white:fontsize=h/19:x=(w-text_w)/2:y=h*0.15"
|
||||
DT="${DT},drawtext=fontfile='${FONT}':text='Performed by John Harrison':fontcolor=0xDDDDDD:fontsize=h/26:x=(w-text_w)/2:y=h*0.32"
|
||||
DT="${DT},drawtext=fontfile='${FONT}':text='with the Wichita State University Chamber Players':fontcolor=0xDDDDDD:fontsize=h/30:x=(w-text_w)/2:y=h*0.43"
|
||||
DT="${DT},drawtext=fontfile='${FONT}':text='Source\\: Free Music Archive':fontcolor=white:fontsize=h/32:x=(w-text_w)/2:y=h*0.57"
|
||||
DT="${DT},drawtext=fontfile='${FONT}':text='freemusicarchive.org':fontcolor=0xFFFF88:fontsize=h/32:x=(w-text_w)/2:y=h*0.66"
|
||||
DT="${DT},drawtext=fontfile='${FONT}':text='License\\: CC BY-SA 3.0':fontcolor=0xCCCCCC:fontsize=h/34:x=(w-text_w)/2:y=h*0.76"
|
||||
DT="${DT},fade=t=in:st=0:d=1,fade=t=out:st=$((ATTR_DUR-1)):d=1"
|
||||
# ── Temp files ────────────────────────────────────────────────────────────────
|
||||
TMPFILES=()
|
||||
cleanup() { rm -f "${TMPFILES[@]}" 2>/dev/null || true; }
|
||||
trap cleanup EXIT
|
||||
|
||||
temp_attr=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_attr")
|
||||
concat_list=$(mktemp --suffix=.txt); TMPFILES+=("$concat_list")
|
||||
printf "file '%s'\n" "${daily_clips[@]}" > "$concat_list"
|
||||
|
||||
# ── Step 1: Concatenate + normalise resolution ────────────────────────────────
|
||||
temp_concat=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_concat")
|
||||
echo "Step 1/3: concatenating ${#daily_clips[@]} clips..."
|
||||
ffmpeg -loglevel warning \
|
||||
-f lavfi -i "color=c=black:s=${VIDEO_W}x${VIDEO_H}:r=25:d=${ATTR_DUR}" \
|
||||
-f lavfi -i "anullsrc=r=44100:cl=stereo" \
|
||||
-vf "$DT" \
|
||||
-f concat -safe 0 -i "$concat_list" \
|
||||
-vf "scale=${VIDEO_W}:${VIDEO_H}:force_original_aspect_ratio=decrease,\
|
||||
pad=${VIDEO_W}:${VIDEO_H}:(ow-iw)/2:(oh-ih)/2,setsar=1" \
|
||||
-c:v libx264 -pix_fmt yuv420p -crf 26 -an \
|
||||
-y "$temp_concat"
|
||||
|
||||
# ── Step 2: Speed-adjust to match music duration exactly ──────────────────────
|
||||
concat_dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$temp_concat")
|
||||
speed_factor=$(echo "scale=6; $concat_dur / $music_duration" | bc)
|
||||
echo "Step 2/3: speed $speed_factor (raw=${concat_dur}s → music=${music_duration}s)"
|
||||
|
||||
temp_sped=$(mktemp --suffix=.mp4); TMPFILES+=("$temp_sped")
|
||||
ffmpeg -loglevel warning \
|
||||
-i "$temp_concat" \
|
||||
-vf "setpts=PTS/$speed_factor" \
|
||||
-c:v libx264 -pix_fmt yuv420p -crf 26 -an \
|
||||
-t "$music_duration" -y "$temp_sped"
|
||||
rm "$temp_concat"
|
||||
|
||||
# ── Step 3: Music + fades + attribution overlay ───────────────────────────────
|
||||
# Attribution overlay: semi-transparent bar across the top for the first
|
||||
# ATTR_DUR seconds, text fades in over ATTR_FADE s and out over ATTR_FADE s.
|
||||
# alpha expression: 0→1 over first ATTR_FADE s, 1 in the middle, 1→0 over
|
||||
# the last ATTR_FADE s before ATTR_DUR.
|
||||
ATTR_FADE_END=$(echo "$ATTR_DUR - $ATTR_FADE" | bc)
|
||||
ALPHA="if(lt(t,${ATTR_FADE}),t/${ATTR_FADE},if(gt(t,${ATTR_FADE_END}),(${ATTR_DUR}-t)/${ATTR_FADE},1))"
|
||||
ENABLE="between(t,0,${ATTR_DUR})"
|
||||
|
||||
fade_out_start=$(echo "scale=3; $music_duration - $FADE_DUR" | bc)
|
||||
echo "Step 3/3: music + fades + attribution overlay..."
|
||||
|
||||
# Build attribution drawtext filters (box=1 gives a per-line background).
|
||||
# Colons inside text values are escaped as \: (\\: in bash double-quoted strings).
|
||||
DT="drawtext=fontfile='${FONT_BOLD}'"
|
||||
DT="${DT}:text='The Four Seasons \: Antonio Vivaldi'"
|
||||
DT="${DT}:fontcolor=white:fontsize=h/22:x=(w-text_w)/2:y=h*0.012"
|
||||
DT="${DT}:box=1:boxcolor=black@0.55:boxborderw=8"
|
||||
DT="${DT}:alpha='${ALPHA}':enable='${ENABLE}'"
|
||||
|
||||
DT="${DT},drawtext=fontfile='${FONT}'"
|
||||
DT="${DT}:text='John Harrison / Wichita State University Chamber Players'"
|
||||
DT="${DT}:fontcolor=0xEEEEEE:fontsize=h/30:x=(w-text_w)/2:y=h*0.068"
|
||||
DT="${DT}:box=1:boxcolor=black@0.55:boxborderw=6"
|
||||
DT="${DT}:alpha='${ALPHA}':enable='${ENABLE}'"
|
||||
|
||||
DT="${DT},drawtext=fontfile='${FONT}'"
|
||||
DT="${DT}:text='Free Music Archive \: freemusicarchive.org \: CC BY-SA 3.0'"
|
||||
DT="${DT}:fontcolor=0xCCCCCC:fontsize=h/36:x=(w-text_w)/2:y=h*0.113"
|
||||
DT="${DT}:box=1:boxcolor=black@0.55:boxborderw=5"
|
||||
DT="${DT}:alpha='${ALPHA}':enable='${ENABLE}'"
|
||||
|
||||
output_file="$output_dir/${MVT_START}_${SEASON}_Mvt${MVT_NUM}-Montage.mp4"
|
||||
|
||||
ffmpeg -loglevel warning \
|
||||
-i "$temp_sped" -i "$music_file" \
|
||||
-filter_complex \
|
||||
"[0:v]fade=t=in:st=0:d=${FADE_DUR},fade=t=out:st=${fade_out_start}:d=${FADE_DUR},${DT}[vout];\
|
||||
[1:a]afade=t=in:st=0:d=${FADE_DUR},afade=t=out:st=${fade_out_start}:d=${FADE_DUR}[aout]" \
|
||||
-map "[vout]" -map "[aout]" \
|
||||
-c:v libx264 -pix_fmt yuv420p -c:a aac -b:a 192k \
|
||||
-t "$ATTR_DUR" -y "$temp_attr"
|
||||
|
||||
# ── Step 5: Join montage + attribution card ───────────────────────────────────
|
||||
echo "Step 5/5: joining montage and attribution card..."
|
||||
final_list=$(mktemp --suffix=.txt); TMPFILES+=("$final_list")
|
||||
printf "file '%s'\n" "$temp_main" "$temp_attr" > "$final_list"
|
||||
|
||||
output_file="$output_dir/$(date +%Y-%m-%d)_${SEASON}_Mvt${MVT_NUM}-Montage.mp4"
|
||||
ffmpeg -loglevel warning \
|
||||
-f concat -safe 0 -i "$final_list" \
|
||||
-c copy -y "$output_file"
|
||||
-t "$music_duration" -y "$output_file"
|
||||
rm "$temp_sped"
|
||||
|
||||
echo "Done: $output_file"
|
||||
|
||||
# ── Notify ────────────────────────────────────────────────────────────────────
|
||||
"$SCRIPT_DIR/notify.sh" \
|
||||
"Montage ready: $SEASON Mvt $MVT_NUM ($ASTRO_YEAR)" \
|
||||
"$(basename "$output_file") — ${music_duration}s" \
|
||||
|| true # notifications are best-effort
|
||||
|
||||
# ── Trigger year-end join on last Autumn movement ────────────────────────────
|
||||
if [ "$SEASON" = "Autumn" ] && [ "$MVT_NUM" = "3" ]; then
|
||||
echo "Last movement of astronomical year $ASTRO_YEAR — triggering year-end join..."
|
||||
"$SCRIPT_DIR/year-end-join.sh" "$ASTRO_YEAR"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
# notify.sh — send a notification via ntfy, email, and/or Mattermost.
|
||||
#
|
||||
# Usage: notify.sh "Title" "Body message"
|
||||
#
|
||||
# Reads notify_config.txt from the same directory as this script.
|
||||
# All methods are independently enabled/disabled in the config.
|
||||
# Exits 0 even if all methods fail (notifications are best-effort).
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
CONFIG="$SCRIPT_DIR/sky-cam.conf"
|
||||
|
||||
TITLE="${1:-Sky-Cam notification}"
|
||||
BODY="${2:-}"
|
||||
|
||||
# ── Load config ───────────────────────────────────────────────────────────────
|
||||
if [ ! -f "$CONFIG" ]; then
|
||||
echo "notify.sh: sky-cam.conf not found — skipping notifications" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
source "$CONFIG"
|
||||
|
||||
NTFY_ENABLED="${NTFY_ENABLED:-false}"
|
||||
NTFY_URL="${NTFY_URL:-}"
|
||||
|
||||
EMAIL_ENABLED="${EMAIL_ENABLED:-false}"
|
||||
EMAIL_TO="${EMAIL_TO:-}"
|
||||
EMAIL_FROM="${EMAIL_FROM:-skycam@localhost}"
|
||||
|
||||
MM_NOTIFY_ENABLED="${MM_NOTIFY_ENABLED:-false}"
|
||||
MM_NOTIFY_CHANNEL_ID="${MM_NOTIFY_CHANNEL_ID:-}"
|
||||
|
||||
# ── ntfy ─────────────────────────────────────────────────────────────────────
|
||||
if [ "$NTFY_ENABLED" = "true" ] && [ -n "$NTFY_URL" ]; then
|
||||
curl -s \
|
||||
-H "Title: $TITLE" \
|
||||
-d "$BODY" \
|
||||
"$NTFY_URL" > /dev/null \
|
||||
&& echo "notify: ntfy sent" \
|
||||
|| echo "notify: ntfy failed" >&2
|
||||
fi
|
||||
|
||||
# ── Email ─────────────────────────────────────────────────────────────────────
|
||||
if [ "$EMAIL_ENABLED" = "true" ] && [ -n "$EMAIL_TO" ]; then
|
||||
echo "$BODY" | mail -s "$TITLE" -r "$EMAIL_FROM" "$EMAIL_TO" \
|
||||
&& echo "notify: email sent to $EMAIL_TO" \
|
||||
|| echo "notify: email failed" >&2
|
||||
fi
|
||||
|
||||
# ── Mattermost text post ──────────────────────────────────────────────────────
|
||||
# mattermost_url and access_token come from sky-cam.conf (sourced above).
|
||||
if [ "$MM_NOTIFY_ENABLED" = "true" ] && [ -n "$MM_NOTIFY_CHANNEL_ID" ]; then
|
||||
curl -s \
|
||||
-H "Authorization: Bearer $access_token" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"channel_id\":\"$MM_NOTIFY_CHANNEL_ID\",\"message\":\"**$TITLE**\n$BODY\"}" \
|
||||
"${mattermost_url}/api/v4/posts" > /dev/null \
|
||||
&& echo "notify: mattermost sent" \
|
||||
|| echo "notify: mattermost failed" >&2
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -28,6 +28,9 @@ Outputs (shell-sourceable):
|
||||
SEASON_START YYYY-MM-DD of season start (local date)
|
||||
SEASON_END YYYY-MM-DD of season end (local date)
|
||||
IS_LAST_DAY true | false
|
||||
ASTRO_YEAR year when the current cycle's Winter solstice occurred
|
||||
(Spring/Summer/Autumn of 2026 all return 2025 if Winter
|
||||
started Dec 2025; Winter 2025 itself also returns 2025)
|
||||
"""
|
||||
|
||||
import sys
|
||||
@@ -148,6 +151,11 @@ def get_info(date: datetime.date, tz_name: str = DEFAULT_TZ) -> dict:
|
||||
else:
|
||||
mvt, mvt_start, mvt_end, days_in_mvt = 3, m2_end + datetime.timedelta(1), m3_end, m3
|
||||
|
||||
# Astronomical year: the calendar year in which the current cycle's Winter
|
||||
# solstice occurred. Spring/Summer/Autumn belong to the Winter that preceded
|
||||
# them; Winter belongs to the solstice that started it.
|
||||
astro_year = s_start.year if season == "Winter" else prev["Winter"].year
|
||||
|
||||
return {
|
||||
"SEASON": season,
|
||||
"MVT_NUM": mvt,
|
||||
@@ -158,6 +166,7 @@ def get_info(date: datetime.date, tz_name: str = DEFAULT_TZ) -> dict:
|
||||
"SEASON_START": s_start.isoformat(),
|
||||
"SEASON_END": s_end.isoformat(),
|
||||
"IS_LAST_DAY": str(date == mvt_end).lower(),
|
||||
"ASTRO_YEAR": str(astro_year),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# sky-cam.conf — single config for all sky-cam scripts and Python helpers.
|
||||
#
|
||||
# Bash scripts source this file:
|
||||
# source "$(dirname "$(realpath "$0")")/sky-cam.conf"
|
||||
#
|
||||
# Python reads it with key=value parsing (same format, quotes stripped).
|
||||
#
|
||||
# Copy this file to your scripts directory and fill in every value.
|
||||
# Lines starting with # are comments and are ignored.
|
||||
|
||||
# ── Paths ─────────────────────────────────────────────────────────────────────
|
||||
BASE_DIR=/home/motion/drives/local-2tb
|
||||
MUSIC_DIR=/home/motion/drives/local-2tb/music/4 Seasons
|
||||
TIMEZONE=America/New_York
|
||||
|
||||
# ── Mattermost — daily sunrise upload ────────────────────────────────────────
|
||||
mattermost_url=https://your-mattermost-server.example.com
|
||||
access_token=your-access-token-here
|
||||
channel_id=your-daily-upload-channel-id-here
|
||||
|
||||
# ── Notifications — movement montage + year-end video complete / job failure ──
|
||||
# ntfy: https://ntfy.sh (cloud) or self-hosted. Set topic URL below.
|
||||
NTFY_ENABLED=false
|
||||
NTFY_URL=https://ntfy.sh/your-topic-here
|
||||
|
||||
# Email: requires the 'mail' command (mailutils / s-nail).
|
||||
EMAIL_ENABLED=false
|
||||
EMAIL_TO=you@example.com
|
||||
EMAIL_FROM=skycam@localhost
|
||||
|
||||
# Mattermost text post (can be same channel as daily upload or a private one).
|
||||
MM_NOTIFY_ENABLED=false
|
||||
MM_NOTIFY_CHANNEL_ID=your-notify-channel-id-here
|
||||
+149
-55
@@ -1,79 +1,173 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Final stitch: north left, sunrise right.
|
||||
Translation from phase-correlation (tx=-3324, ty=-85).
|
||||
Feathered gradient blend across the overlap zone.
|
||||
Stitch north (cylindrical warp) + sunrise (unmodified).
|
||||
|
||||
Usage:
|
||||
python3 stitch-cameras.py north.jpg sunrise.jpg out_prefix [focal_px]
|
||||
|
||||
focal_px: cylindrical focal length in pixels (default: auto-search).
|
||||
Approx guide: 1920 = ~90° HFOV for a 3840px-wide sensor.
|
||||
|
||||
Pipeline
|
||||
--------
|
||||
1. Cylindrical-warp north only; sunrise is never modified.
|
||||
2. Build a soft validity mask for the warped north so black-corner
|
||||
pixels fade out smoothly.
|
||||
3. Phase-correlate edge-enhanced treeline strips to find tx, ty.
|
||||
4. Colour-match north's overlap strip to sunrise's (per-channel gain)
|
||||
so the two cameras' exposure/WB differences don't leave a visible seam.
|
||||
5. Feathered alpha blend in the overlap zone, weighted by north's validity.
|
||||
6. Crop black margins; output full-res panorama + half-size preview.
|
||||
"""
|
||||
import sys, cv2, numpy as np
|
||||
|
||||
north_p, sunrise_p, out_p = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
tx_arg = int(sys.argv[4]) if len(sys.argv) > 4 else -3324
|
||||
ty_arg = int(sys.argv[5]) if len(sys.argv) > 5 else -85
|
||||
north_p = sys.argv[1]
|
||||
sunrise_p= sys.argv[2]
|
||||
prefix = sys.argv[3]
|
||||
forced_f = float(sys.argv[4]) if len(sys.argv) > 4 else None
|
||||
|
||||
north = cv2.imread(north_p)
|
||||
sunrise = cv2.imread(sunrise_p)
|
||||
assert north is not None, f"Cannot read {north_p}"
|
||||
assert sunrise is not None, f"Cannot read {sunrise_p}"
|
||||
H, W = north.shape[:2]
|
||||
cx, cy = W / 2.0, H / 2.0
|
||||
|
||||
tx, ty = tx_arg, ty_arg # north → sunrise translation
|
||||
print(f"Using tx={tx} ty={ty}")
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
# ── Canvas ────────────────────────────────────────────────────────────────────
|
||||
# Sunrise is at the canvas origin (0,0).
|
||||
# North is at (tx, ty) relative to sunrise — tx is negative so north is LEFT.
|
||||
canvas_x0 = min(0, tx) # leftmost pixel
|
||||
canvas_y0 = min(0, ty)
|
||||
canvas_x1 = max(W, W + tx)
|
||||
canvas_y1 = max(H, H + ty)
|
||||
cW = int(canvas_x1 - canvas_x0)
|
||||
cH = int(canvas_y1 - canvas_y0)
|
||||
def cylindrical_warp(img, f):
|
||||
xc = np.arange(W, dtype=np.float32) - cx
|
||||
yc = np.arange(H, dtype=np.float32) - cy
|
||||
XC, YC = np.meshgrid(xc, yc)
|
||||
theta = XC / f
|
||||
map_x = (f * np.tan(theta) + cx).astype(np.float32)
|
||||
map_y = (YC / np.cos(theta) + cy).astype(np.float32)
|
||||
warped = cv2.remap(img, map_x, map_y, cv2.INTER_LINEAR,
|
||||
borderMode=cv2.BORDER_CONSTANT, borderValue=0)
|
||||
valid = ((map_x >= 0) & (map_x < W) &
|
||||
(map_y >= 0) & (map_y < H)).astype(np.float32)
|
||||
return warped, valid
|
||||
|
||||
# Canvas offsets for each image
|
||||
s_ox, s_oy = int(-canvas_x0), int(-canvas_y0) # sunrise top-left in canvas
|
||||
n_ox, n_oy = s_ox + tx, s_oy + ty # north top-left in canvas
|
||||
def phase_corr(n_cyl):
|
||||
"""Return (peak_score, tx, ty) aligning warped-north to sunrise."""
|
||||
bw = int(W * 0.35)
|
||||
y0, y1 = int(H * 0.60), int(H * 0.92)
|
||||
n_strip = cv2.cvtColor(n_cyl [:, W-bw:], cv2.COLOR_BGR2GRAY)[y0:y1].astype(np.float64)
|
||||
s_strip = cv2.cvtColor(sunrise[:, :bw], cv2.COLOR_BGR2GRAY)[y0:y1].astype(np.float64)
|
||||
ne = cv2.Laplacian(n_strip, cv2.CV_64F, ksize=3)
|
||||
se = cv2.Laplacian(s_strip, cv2.CV_64F, ksize=3)
|
||||
N = np.fft.fft2(ne); S = np.fft.fft2(se)
|
||||
R = N * np.conj(S); nrm = np.abs(R); nrm[nrm == 0] = 1
|
||||
corr = np.fft.ifft2(R / nrm).real
|
||||
peak_val = corr.max()
|
||||
dy_r, dx_r = [int(v) for v in np.unravel_index(np.argmax(corr), corr.shape)]
|
||||
rh, rw = corr.shape
|
||||
if dy_r > rh // 2: dy_r -= rh
|
||||
if dx_r > rw // 2: dx_r -= rw
|
||||
return peak_val, -(W - bw + dx_r), -dy_r
|
||||
|
||||
canvas = np.zeros((cH, cW, 3), dtype=np.uint8)
|
||||
def colour_match(src, ref_strip_src, ref_strip_ref):
|
||||
"""Scale each BGR channel of src so strip means match between the two strips."""
|
||||
out = src.astype(np.float32)
|
||||
for c in range(3):
|
||||
s_mean = ref_strip_src[..., c].astype(np.float32).mean()
|
||||
r_mean = ref_strip_ref[..., c].astype(np.float32).mean()
|
||||
gain = np.clip(r_mean / s_mean if s_mean > 1e-3 else 1.0, 0.5, 2.0)
|
||||
out[..., c] = np.clip(out[..., c] * gain, 0, 255)
|
||||
return out
|
||||
|
||||
# Paint north first (background)
|
||||
nx0, ny0 = int(n_ox), int(n_oy)
|
||||
canvas[ny0:ny0+H, nx0:nx0+W] = north
|
||||
# ── Focal length search (or forced) ──────────────────────────────────────────
|
||||
focal_candidates = [forced_f] if forced_f else [1400, 1550, 1700, 1800, 1920, 2100, 2300, 2600]
|
||||
print(f"{'focal':>6} {'score':>8} {'tx':>7} {'ty':>5}")
|
||||
best_score, best_f, best_tx, best_ty = -1.0, 1920.0, 0, 0
|
||||
for f in focal_candidates:
|
||||
n_cyl, _ = cylindrical_warp(north, f)
|
||||
score, tx, ty = phase_corr(n_cyl)
|
||||
print(f"{f:6.0f} {score:8.5f} {tx:7d} {ty:5d}")
|
||||
if score > best_score:
|
||||
best_score, best_f, best_tx, best_ty = score, f, tx, ty
|
||||
|
||||
# Paint sunrise on top (base)
|
||||
sx0, sy0 = int(s_ox), int(s_oy)
|
||||
canvas[sy0:sy0+H, sx0:sx0+W] = sunrise
|
||||
f = best_f
|
||||
tx = best_tx
|
||||
ty = best_ty
|
||||
print(f"\nBest focal={f:.0f} score={best_score:.5f} tx={tx} ty={ty}")
|
||||
|
||||
# ── Feathered blend in overlap zone ──────────────────────────────────────────
|
||||
# Overlap: columns where both images exist in the canvas
|
||||
ov_x0 = max(sx0, nx0)
|
||||
ov_x1 = min(sx0 + W, nx0 + W)
|
||||
ov_y0 = max(sy0, ny0)
|
||||
ov_y1 = min(sy0 + H, ny0 + H)
|
||||
# ── Warp + validity mask ──────────────────────────────────────────────────────
|
||||
n_cyl, valid_raw = cylindrical_warp(north, f)
|
||||
|
||||
kernel = np.ones((31, 31), np.float32) / (31 * 31)
|
||||
valid_soft = cv2.filter2D(valid_raw, -1, kernel).clip(0, 1)
|
||||
|
||||
# First column of north with >50% valid pixels in the central band
|
||||
central_y0, central_y1 = int(H * 0.10), int(H * 0.90)
|
||||
col_valid = valid_raw[central_y0:central_y1, :].mean(axis=0)
|
||||
first_valid_col = int(np.argmax(col_valid > 0.5))
|
||||
|
||||
# ── Canvas geometry ───────────────────────────────────────────────────────────
|
||||
xmin = min(0, tx); ymin = min(0, ty)
|
||||
xmax = max(W, W + tx); ymax = max(H, H + ty)
|
||||
cW, cH = int(xmax - xmin), int(ymax - ymin)
|
||||
sx0, sy0 = int(-xmin), int(-ymin)
|
||||
nx0, ny0 = int(sx0 + tx), int(sy0 + ty)
|
||||
|
||||
ov_x0 = max(sx0, nx0); ov_x1 = min(sx0 + W, nx0 + W)
|
||||
ov_y0 = max(sy0, ny0); ov_y1 = min(sy0 + H, ny0 + H)
|
||||
|
||||
# ── Colour-match north → sunrise in the overlap strip ────────────────────────
|
||||
# Use a central vertical slice of the overlap (avoid the edge-feather zones).
|
||||
ov_w = ov_x1 - ov_x0
|
||||
# Sample the middle half of the overlap, treeline rows only (avoid sky + timestamp)
|
||||
y_lo, y_hi = int(H * 0.55), int(H * 0.88)
|
||||
mid_n_x0 = ov_x0 - nx0 + ov_w // 4
|
||||
mid_n_x1 = ov_x0 - nx0 + 3 * ov_w // 4
|
||||
mid_s_x0 = ov_x0 - sx0 + ov_w // 4
|
||||
mid_s_x1 = ov_x0 - sx0 + 3 * ov_w // 4
|
||||
n_sample = n_cyl [y_lo:y_hi, mid_n_x0:mid_n_x1]
|
||||
s_sample = sunrise[y_lo:y_hi, mid_s_x0:mid_s_x1]
|
||||
n_cyl_matched = colour_match(n_cyl, n_sample, s_sample)
|
||||
print(f"Colour-matched north to sunrise (overlap centre rows {y_lo}-{y_hi})")
|
||||
|
||||
# ── Composite ────────────────────────────────────────────────────────────────
|
||||
canvas = np.zeros((cH, cW, 3), dtype=np.float32)
|
||||
|
||||
# 1. Paint north (valid content only, black corners excluded)
|
||||
nv = valid_soft[..., np.newaxis]
|
||||
c_s = nx0 + first_valid_col
|
||||
c_e = min(nx0 + W, cW)
|
||||
canvas[ny0:ny0 + H, c_s:c_e] = (
|
||||
n_cyl_matched[:, first_valid_col:c_e - nx0].astype(np.float32)
|
||||
* nv[:, first_valid_col:c_e - nx0]
|
||||
)
|
||||
|
||||
# 2. Sunrise overwrites its entire area (completely unmodified)
|
||||
canvas[sy0:sy0 + H, sx0:sx0 + W] = sunrise.astype(np.float32)
|
||||
|
||||
# 3. Feathered blend in overlap: when north is invalid, fall back to sunrise
|
||||
if ov_x1 > ov_x0 and ov_y1 > ov_y0:
|
||||
ov_w = ov_x1 - ov_x0
|
||||
ov_h = ov_y1 - ov_y0
|
||||
print(f"Overlap zone: {ov_w}x{ov_h}px at canvas x=[{ov_x0},{ov_x1}]")
|
||||
alpha = np.linspace(0.0, 1.0, ov_w, dtype=np.float32)[np.newaxis, :, np.newaxis]
|
||||
n_patch = n_cyl_matched[ov_y0 - ny0:ov_y1 - ny0, ov_x0 - nx0:ov_x1 - nx0].astype(np.float32)
|
||||
s_patch = sunrise [ov_y0 - sy0:ov_y1 - sy0, ov_x0 - sx0:ov_x1 - sx0].astype(np.float32)
|
||||
nv_patch = valid_soft [ov_y0 - ny0:ov_y1 - ny0, ov_x0 - nx0:ov_x1 - nx0][..., np.newaxis]
|
||||
s_weight = np.maximum(alpha, 1.0 - nv_patch)
|
||||
canvas[ov_y0:ov_y1, ov_x0:ov_x1] = s_patch * s_weight + n_patch * (1.0 - s_weight)
|
||||
print(f"Overlap blend: {ov_w}x{ov_y1 - ov_y0}px")
|
||||
|
||||
# Horizontal gradient: sunrise fades OUT on the left (where north takes over)
|
||||
# north fades OUT on the right (where sunrise takes over)
|
||||
alpha = np.linspace(0.0, 1.0, ov_w, dtype=np.float32) # 0=north, 1=sunrise
|
||||
alpha = alpha[np.newaxis, :, np.newaxis] # shape (1, ov_w, 1)
|
||||
out = canvas.clip(0, 255).astype(np.uint8)
|
||||
|
||||
n_patch = north [ov_y0-ny0:ov_y1-ny0, ov_x0-nx0:ov_x1-nx0].astype(np.float32)
|
||||
s_patch = sunrise[ov_y0-sy0:ov_y1-sy0, ov_x0-sx0:ov_x1-sx0].astype(np.float32)
|
||||
blended = (s_patch * alpha + n_patch * (1.0 - alpha)).astype(np.uint8)
|
||||
canvas[ov_y0:ov_y1, ov_x0:ov_x1] = blended
|
||||
# Vertical crop to rows where both images exist
|
||||
top = max(sy0, ny0); bot = min(sy0 + H, ny0 + H)
|
||||
out = out[top:bot, :]
|
||||
|
||||
# ── Crop off the black margin at top/bottom from the ty offset ───────────────
|
||||
# After the shift there may be a thin black bar top or bottom — crop it.
|
||||
top_crop = max(sy0, ny0) # first row where BOTH images exist
|
||||
bottom_crop = min(sy0+H, ny0+H) # last row where either image exists
|
||||
canvas = canvas[top_crop:bottom_crop, :]
|
||||
# Left-crop black corner columns
|
||||
col_has_content = out.max(axis=(0, 2)) > 0
|
||||
left_crop = int(np.argmax(col_has_content))
|
||||
out = out[:, left_crop:]
|
||||
print(f"Final size: {out.shape[1]}x{out.shape[0]}")
|
||||
|
||||
cv2.imwrite(out_p, canvas, [cv2.IMWRITE_JPEG_QUALITY, 92])
|
||||
print(f"Output: {out_p} size={canvas.shape[1]}x{canvas.shape[0]}")
|
||||
cv2.imwrite(f"{prefix}-panorama.jpg", out, [cv2.IMWRITE_JPEG_QUALITY, 93])
|
||||
half = cv2.resize(out, (out.shape[1] // 2, out.shape[0] // 2))
|
||||
cv2.imwrite(f"{prefix}-preview.jpg", half, [cv2.IMWRITE_JPEG_QUALITY, 88])
|
||||
|
||||
# ── Save a 50% scaled preview for quick viewing ───────────────────────────────
|
||||
preview = cv2.resize(canvas, (canvas.shape[1]//2, canvas.shape[0]//2))
|
||||
cv2.imwrite(out_p.replace(".jpg", "-preview.jpg"), preview,
|
||||
[cv2.IMWRITE_JPEG_QUALITY, 85])
|
||||
print(f"Preview saved.")
|
||||
with open(f"{prefix}-params.txt", "w") as fh:
|
||||
fh.write(f"focal={f:.0f}\ntx={tx}\nty={ty}\n")
|
||||
|
||||
+5
-2
@@ -2,8 +2,11 @@ import requests
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# Configuration file path (update the path to where your mattermost_config.txt is located)
|
||||
config_file_path = '/home/motion/drives/local-2tb/sunrise-scripts/mattermost_config.txt'
|
||||
import pathlib
|
||||
|
||||
# Locate sky-cam.conf next to this script (works regardless of cwd).
|
||||
_here = pathlib.Path(__file__).resolve().parent
|
||||
config_file_path = str(_here / 'sky-cam.conf')
|
||||
|
||||
# Function to read configuration from the config file
|
||||
def read_config(config_file_path):
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
Installing systemd timers
|
||||
========================
|
||||
|
||||
1. Edit the ExecStart paths in each .service file to match where your scripts live.
|
||||
|
||||
2. Copy units to the systemd user directory (no root needed):
|
||||
|
||||
mkdir -p ~/.config/systemd/user
|
||||
cp sky-cam-*.service sky-cam-*.timer ~/.config/systemd/user/
|
||||
|
||||
Or system-wide (root required):
|
||||
|
||||
sudo cp sky-cam-*.service sky-cam-*.timer /etc/systemd/system/
|
||||
|
||||
3. Reload and enable:
|
||||
|
||||
# User-level
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now sky-cam-sunrise.timer
|
||||
systemctl --user enable --now sky-cam-4seasons.timer
|
||||
systemctl --user enable --now sky-cam-fullday.timer
|
||||
|
||||
# System-level (replace --user with no flag, add sudo)
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now sky-cam-sunrise.timer
|
||||
...
|
||||
|
||||
4. Check status:
|
||||
|
||||
systemctl --user list-timers sky-cam-*
|
||||
journalctl --user -u sky-cam-4seasons.service -f
|
||||
|
||||
Notes
|
||||
-----
|
||||
- Persistent=true means missed runs (e.g. system was off at 01:00) are
|
||||
caught up on next boot, within the same day.
|
||||
- montage-mvt.sh and year-end-join.sh are NOT scheduled directly — they
|
||||
are triggered automatically by 4-seasons.sh on the appropriate days.
|
||||
- notify.sh fires inside montage-mvt.sh and year-end-join.sh; it is not
|
||||
a separate scheduled job.
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam Four Seasons daily clip (+ montage trigger on last day)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
OnFailure=sky-cam-notify-failure@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/home/motion/drives/local-2tb/sunrise-scripts/4-seasons.sh
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam Four Seasons daily clip — 01:00
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 01:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam full-day timelapse (10-day retention)
|
||||
OnFailure=sky-cam-notify-failure@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/home/motion/drives/local-2tb/sunrise-scripts/fullday-video.sh
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam full-day timelapse — 02:00
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 02:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam failure notification for %i
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
# %i is the name of the failed unit (passed by OnFailure=)
|
||||
# Edit ExecStart path to match your install location.
|
||||
ExecStart=/home/motion/drives/local-2tb/sunrise-scripts/notify.sh \
|
||||
"sky-cam job failed: %i" \
|
||||
"systemd unit %i exited with failure. Check logs: journalctl -u %i"
|
||||
@@ -0,0 +1,12 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam daily sunrise video → Mattermost
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
OnFailure=sky-cam-notify-failure@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
# ── Edit this path ────────────────────────────────────────────────────────────
|
||||
ExecStart=/home/motion/drives/local-2tb/sunrise-scripts/sunrise_video.10s.sh
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Sky-Cam sunrise video — daily at 09:00
|
||||
|
||||
[Timer]
|
||||
# Run at 09:00 every day (after sunrise window has ended).
|
||||
OnCalendar=*-*-* 09:00:00
|
||||
# If the system was off at 09:00, run as soon as it boots (within 1 hour).
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
# year-end-join.sh — concatenate all 12 movement montages for one astronomical
|
||||
# year into a single "Four Seasons" video.
|
||||
#
|
||||
# Called automatically by montage-mvt.sh after the last Autumn movement finishes.
|
||||
# Can also be run manually: ./year-end-join.sh 2025
|
||||
#
|
||||
# The 12 individual movement videos already carry their own attribution overlay
|
||||
# (first 6 seconds of each), so no extra card is appended here.
|
||||
#
|
||||
# Output: $base_dir/movies/$script_name/$ASTRO_YEAR/$script_name-$ASTRO_YEAR.mp4
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
|
||||
source "$SCRIPT_DIR/sky-cam.conf"
|
||||
|
||||
ASTRO_YEAR="${1:-}"
|
||||
if [ -z "$ASTRO_YEAR" ]; then
|
||||
echo "Usage: $0 <ASTRO_YEAR> (e.g. $0 2025)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
base_dir="$BASE_DIR"
|
||||
script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1)
|
||||
year_dir="$base_dir/movies/$script_name/$ASTRO_YEAR"
|
||||
|
||||
echo "Assembling Four Seasons $ASTRO_YEAR from $year_dir ..."
|
||||
|
||||
# ── Collect the 12 montage files in season/movement order ────────────────────
|
||||
concat_list=$(mktemp --suffix=.txt)
|
||||
trap 'rm -f "$concat_list"' EXIT
|
||||
|
||||
missing=0
|
||||
for season in Winter Spring Summer Autumn; do
|
||||
for mvt in 1 2 3; do
|
||||
mvt_dir="$year_dir/$season/Mvt$mvt/montage"
|
||||
# Pick the newest (or only) montage file for this movement
|
||||
f=$(find "$mvt_dir" -maxdepth 1 -name "*-Montage.mp4" 2>/dev/null | sort | tail -1)
|
||||
if [ -z "$f" ]; then
|
||||
echo "WARNING: missing montage for $season Mvt$mvt ($mvt_dir)"
|
||||
missing=$((missing + 1))
|
||||
else
|
||||
echo " $season Mvt$mvt → $(basename "$f")"
|
||||
printf "file '%s'\n" "$f" >> "$concat_list"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
found=$(wc -l < "$concat_list")
|
||||
echo "$found of 12 movements found ($missing missing)"
|
||||
|
||||
if [ "$found" -eq 0 ]; then
|
||||
echo "ERROR: no montage files found — aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$missing" -gt 0 ]; then
|
||||
echo "WARNING: joining with $missing movement(s) absent."
|
||||
fi
|
||||
|
||||
# ── Join ──────────────────────────────────────────────────────────────────────
|
||||
output_file="$year_dir/${script_name}-${ASTRO_YEAR}.mp4"
|
||||
echo "Output: $output_file"
|
||||
|
||||
ffmpeg -loglevel warning \
|
||||
-f concat -safe 0 -i "$concat_list" \
|
||||
-c copy -y "$output_file"
|
||||
|
||||
total_dur=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$output_file")
|
||||
total_min=$(echo "scale=1; $total_dur / 60" | bc)
|
||||
echo "Done: $output_file (${total_min} min)"
|
||||
|
||||
# ── Notify ────────────────────────────────────────────────────────────────────
|
||||
"$SCRIPT_DIR/notify.sh" \
|
||||
"Four Seasons $ASTRO_YEAR complete" \
|
||||
"${script_name}-${ASTRO_YEAR}.mp4 — ${total_min} minutes ($found movements)" \
|
||||
|| true
|
||||
Reference in New Issue
Block a user