Restructure audio into AUDIO_DIR with per-camera retention

New AUDIO_DIR variable (like BASE_DIR/MOVIES_DIR) is the root for all
audio recordings.  Set in .env to put audio on a separate drive.

Directory layout:
  AUDIO_DIR/<cam>/YYYY-MM-DD/HH-MM-SS.m4a        — ambient recordings
  AUDIO_DIR/sunrise/<cam>/YYYY-MM-DD/sunrise-audio.m4a — sunrise clips

sky-cam.conf:
- Add AUDIO_DIR="${AUDIO_DIR:-$BASE_DIR/audio}" in storage section
- Remove AMBIENT_DIR (replaced by AUDIO_DIR)
- Add SUNRISE_AUDIO_RETENTION_DAYS=7 (sunrise clips kept separately from ambient)
- Add per-camera ambient retention examples:
    AMBIENT_RETENTION_DAYS_south=60  (keep bird recordings longer)

ambient-record.sh:
- Use AUDIO_DIR instead of AMBIENT_DIR
- Per-camera retention: AMBIENT_RETENTION_DAYS_<cam> overrides global default

sunrise-audio-capture.sh:
- Save clips to AUDIO_DIR/sunrise/<cam>/<date>/sunrise-audio.m4a
- Rolling retention of sunrise clips (SUNRISE_AUDIO_RETENTION_DAYS)

daily_sunrise_video.sh:
- Look for cam_audio in new AUDIO_DIR/sunrise path first, fall back to
  old BASE_DIR path so existing recordings keep working

install.sh:
- Pre-create AUDIO_DIR/<cam> and AUDIO_DIR/sunrise/<SUNRISE_CAM> dirs
- Add AUDIO_DIR to .env.example storage section

https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
Claude
2026-04-22 14:43:05 +00:00
parent a63a42ee46
commit 11d4630197
5 changed files with 32 additions and 6 deletions
+3 -2
View File
@@ -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/"
+4 -1
View File
@@ -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/<cam>/<date>/sunrise-audio.m4a
# Fallback to old path (BASE_DIR/<cam>/<date>/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"
+4
View File
@@ -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 ────────────────────────────────────────────────────────"
+12 -2
View File
@@ -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/<cam>/YYYY-MM-DD/HH-MM-SS.m4a (ambient)
# AUDIO_DIR/sunrise/<cam>/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/<cam>/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; 6496k 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).
+9 -1
View File
@@ -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