diff --git a/ambient-record.sh b/ambient-record.sh index 7aed9d4..eb60f5f 100755 --- a/ambient-record.sh +++ b/ambient-record.sh @@ -37,8 +37,9 @@ fi CHUNK="${AMBIENT_CHUNK_SECS:-1800}" BITRATE="${AMBIENT_BITRATE:-96k}" -RETAIN="${AMBIENT_RETENTION_DAYS:-30}" -SAVE_DIR="${AMBIENT_DIR:-$BASE_DIR/ambient}" +retain_var="AMBIENT_RETENTION_DAYS_${CAM}" +RETAIN="${!retain_var:-${AMBIENT_RETENTION_DAYS:-30}}" +SAVE_DIR="${AUDIO_DIR:-$BASE_DIR/audio}" echo "Ambient recorder started: cam=$CAM chunk=${CHUNK}s bitrate=$BITRATE retain=${RETAIN}d" echo "Saving to: $SAVE_DIR/$CAM/" diff --git a/daily_sunrise_video.sh b/daily_sunrise_video.sh index 0bee487..9782bfc 100755 --- a/daily_sunrise_video.sh +++ b/daily_sunrise_video.sh @@ -242,7 +242,10 @@ if $TEST_MODE; then echo "Audio: CAM_RTSP_${CAM_NAME} not set — skipping" fi else - cam_audio="$image_dir/sunrise-audio.m4a" + # New path: AUDIO_DIR/sunrise///sunrise-audio.m4a + # Fallback to old path (BASE_DIR///sunrise-audio.m4a) for migration + cam_audio="${AUDIO_DIR:-$BASE_DIR/audio}/sunrise/$CAM_NAME/$current_date/sunrise-audio.m4a" + [ ! -f "$cam_audio" ] && cam_audio="$image_dir/sunrise-audio.m4a" if [ "${AUDIO_ENABLED:-false}" = "true" ]; then if [ -f "$cam_audio" ]; then audio_src="$cam_audio" diff --git a/install.sh b/install.sh index c5b08f3..a02dae2 100755 --- a/install.sh +++ b/install.sh @@ -37,10 +37,13 @@ echo "Creating data directories..." for cam in "${CAMERAS[@]}"; do mkdir -p "$BASE_DIR/$cam" mkdir -p "$MOVIES_DIR/$cam" + mkdir -p "$AUDIO_DIR/$cam" echo " $BASE_DIR/$cam" echo " $MOVIES_DIR/$cam" + echo " $AUDIO_DIR/$cam" done mkdir -p "$BASE_DIR/$SUNRISE_CAM" +mkdir -p "$AUDIO_DIR/sunrise/$SUNRISE_CAM" echo "" # ── Helper: write a oneshot service unit ───────────────────────────────────── @@ -262,6 +265,7 @@ env_example="$HERE/.env.example" echo "# different drive. Leave commented to use the defaults next to the scripts." echo "#BASE_DIR=/path/to/images # default: ~/sky-cam/data" echo "#MOVIES_DIR=/path/to/videos # default: \$BASE_DIR/movies" + echo "#AUDIO_DIR=/path/to/audio # default: \$BASE_DIR/audio" echo "#MUSIC_DIR=/path/to/music/4Seasons # default: ~/sky-cam/music" echo "" echo "# ── RTSP stream URLs ────────────────────────────────────────────────────────" diff --git a/sky-cam.conf b/sky-cam.conf index 2039ef0..e617e29 100644 --- a/sky-cam.conf +++ b/sky-cam.conf @@ -150,6 +150,9 @@ SCRIPT_DIR="${SCRIPT_DIR:-$(dirname "$(realpath "${BASH_SOURCE[0]}")")}" BASE_DIR="${BASE_DIR:-$SCRIPT_DIR/data}" MOVIES_DIR="${MOVIES_DIR:-$BASE_DIR/movies}" # override if videos live on a different drive MUSIC_DIR="${MUSIC_DIR:-$SCRIPT_DIR/music}" +AUDIO_DIR="${AUDIO_DIR:-$BASE_DIR/audio}" # root for all audio recordings; override in .env +# Structure: AUDIO_DIR//YYYY-MM-DD/HH-MM-SS.m4a (ambient) +# AUDIO_DIR/sunrise//YYYY-MM-DD/sunrise-audio.m4a (sunrise clips) # ── Location & timezone ─────────────────────────────────────────────────────── # Used by sunrise.py to calculate sunrise time each day. @@ -321,6 +324,9 @@ AUDIO_ENABLED=false # set true if your camera has a working mic CAPTURE_AUDIO_BITRATE=96k # bitrate for the sunrise audio recording # Audio is recorded for exactly SUNRISE_TARGET_SECS, centred on actual sunrise: # floor(TARGET/2) seconds before, ceil(TARGET/2) after (odd second → post-sunrise). +# Clips are saved to AUDIO_DIR/sunrise//YYYY-MM-DD/sunrise-audio.m4a. +# After mixing into the video the clip is kept for SUNRISE_AUDIO_RETENTION_DAYS, then deleted. +SUNRISE_AUDIO_RETENTION_DAYS=7 # ── Ambient audio library ────────────────────────────────────────────────────── # Continuously records natural sounds (birds, rain, wind) from AMBIENT_CAMS to @@ -330,10 +336,14 @@ CAPTURE_AUDIO_BITRATE=96k # bitrate for the sunrise audio recording # AMBIENT_ENABLED=false AMBIENT_CAMS=(south) # cameras to record from -AMBIENT_DIR="${BASE_DIR}/ambient" # root storage directory AMBIENT_CHUNK_SECS=1800 # seconds per file (default 30 min) AMBIENT_BITRATE=96k # AAC bitrate; 64–96k is plenty at 8 kHz -AMBIENT_RETENTION_DAYS=30 # delete files older than this; 0 = keep forever +# Retention — global default, then optional per-camera overrides. +# Uncomment and set per-cam lines to keep different cameras for different durations. +AMBIENT_RETENTION_DAYS=30 # global default; 0 = keep forever +#AMBIENT_RETENTION_DAYS_east=14 +#AMBIENT_RETENTION_DAYS_north=30 +#AMBIENT_RETENTION_DAYS_south=60 # keep south longer for nature sound library # ── Mattermost — daily sunrise upload ───────────────────────────────────────── # mattermost_url, access_token, channel_id go in .env (see bottom of this file). diff --git a/sunrise-audio-capture.sh b/sunrise-audio-capture.sh index 6dfff83..3fdc129 100755 --- a/sunrise-audio-capture.sh +++ b/sunrise-audio-capture.sh @@ -64,7 +64,7 @@ if [ "$wait_sec" -gt 0 ]; then fi today=$(date +%Y-%m-%d) -dir="$BASE_DIR/$CAM/$today" +dir="${AUDIO_DIR:-$BASE_DIR/audio}/sunrise/$CAM/$today" mkdir -p "$dir" output="$dir/sunrise-audio.m4a" @@ -84,3 +84,11 @@ fi size=$(du -h "$output" | cut -f1) echo "Audio capture complete: $output (${record_dur_sec}s, $size)" + +# Rolling retention for sunrise audio clips +retain="${SUNRISE_AUDIO_RETENTION_DAYS:-7}" +if [ "$retain" -gt 0 ]; then + audio_root="${AUDIO_DIR:-$BASE_DIR/audio}/sunrise/$CAM" + deleted=$(find "$audio_root" -name "sunrise-audio.m4a" -mtime +"$retain" -print -delete 2>/dev/null | wc -l) + [ "$deleted" -gt 0 ] && echo "Retention: deleted $deleted sunrise audio clip(s) older than ${retain}d" +fi