Add year-based folders, attribution overlay, notifications, crontab/systemd
season_info.py - Add ASTRO_YEAR: year of the Winter solstice that started the current cycle (Spring/Summer/Autumn 2026 → 2025; Winter Dec-2026 → 2026) 4-seasons.sh - Daily clip output path now includes ASTRO_YEAR: movies/$name/$ASTRO_YEAR/$SEASON/Mvt$N/ montage-mvt.sh (full rewrite) - Attribution is now a drawtext overlay (top 6 s of the video, fade in/out) instead of an appended black card — no frame-size matching needed, and year-end join requires no special handling - Output path mirrors the new year-based folder structure - Sends notification via notify.sh when done - Automatically triggers year-end-join.sh after Autumn Mvt 3 year-end-join.sh (new) - Concatenates all 12 movement montages for a given ASTRO_YEAR - Output: movies/$name/$ASTRO_YEAR/$name-$ASTRO_YEAR.mp4 - Sends notification when done notify.sh + notify_config.txt (new) - Generic best-effort notification helper: ntfy, email, Mattermost text post - All methods disabled by default; user fills in notify_config.txt sky-cam.crontab + systemd/ (new) - Crontab file: sunrise at 09:00, 4-seasons at 01:00, fullday at 02:00 - systemd .service + .timer units for all three daily jobs - montage/year-end triggered internally, not by cron https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
+106
-95
@@ -1,15 +1,20 @@
|
||||
#!/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
|
||||
|
||||
@@ -20,33 +25,32 @@ base_dir="/home/motion/drives/local-2tb"
|
||||
music_base_dir="$base_dir/music/4 Seasons"
|
||||
[ ! -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 +58,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 +80,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
|
||||
|
||||
Reference in New Issue
Block a user