Audio capture records exactly SUNRISE_TARGET_SECS centred on sunrise
Previously sunrise-audio-capture.sh recorded the entire capture window (70+ minutes) and daily_sunrise_video.sh sought to the right position with a complex offset calculation. Now: record floor(TARGET/2) seconds before sunrise and ceil(TARGET/2) after — odd second goes to post-sunrise. The file is exactly SUNRISE_TARGET_SECS long and already centred, so no offset is needed when mixing. AUDIO_PRE_BUFFER_MIN removed — it was part of the old whole-window scheme and is no longer meaningful. https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
This commit is contained in:
@@ -171,10 +171,9 @@ audio_offset="0"
|
||||
cam_audio="$image_dir/sunrise-audio.m4a"
|
||||
if [ "${AUDIO_ENABLED:-false}" = "true" ]; then
|
||||
if [ -f "$cam_audio" ]; then
|
||||
buffer_sec=$(( ${AUDIO_PRE_BUFFER_MIN:-2} * 60 ))
|
||||
audio_offset=$(echo "scale=1; $SUNRISE_PRE_MIN * 60 + $buffer_sec - $SUNRISE_TARGET_SECS / 2" | bc)
|
||||
# Already exactly SUNRISE_TARGET_SECS, centred on sunrise — no offset needed
|
||||
audio_src="$cam_audio"
|
||||
echo "Audio: camera recording offset=${audio_offset}s"
|
||||
echo "Audio: camera recording (centred on sunrise)"
|
||||
else
|
||||
library_dir="$SCRIPT_DIR/sunrise-sounds"
|
||||
if [ -d "$library_dir" ]; then
|
||||
|
||||
+2
-1
@@ -283,8 +283,9 @@ CAPTURE_INTERVAL=10
|
||||
# The audio file is deleted automatically after it is mixed into the video.
|
||||
#
|
||||
AUDIO_ENABLED=false # set true if your camera has a working mic
|
||||
AUDIO_PRE_BUFFER_MIN=2 # extra minutes to start before the capture window
|
||||
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).
|
||||
|
||||
# ── Mattermost — daily sunrise upload ─────────────────────────────────────────
|
||||
# mattermost_url, access_token, channel_id go in .env (see bottom of this file).
|
||||
|
||||
+16
-11
@@ -1,13 +1,15 @@
|
||||
#!/bin/bash
|
||||
# sunrise-audio-capture.sh — record the camera's RTSP audio stream during the
|
||||
# sunrise window so daily_sunrise_video.sh can mix in natural ambient sound
|
||||
# (birds, rain, wind) at real speed while the video plays as a timelapse.
|
||||
# sunrise-audio-capture.sh — record exactly SUNRISE_TARGET_SECS of audio
|
||||
# centred on the actual sunrise moment, so daily_sunrise_video.sh can mix in
|
||||
# real ambient sound (birds, rain, wind) at natural speed.
|
||||
#
|
||||
# Triggered daily at 03:00 by sky-cam-audio-capture.timer.
|
||||
# Waits internally until (sunrise − SUNRISE_PRE_MIN − AUDIO_PRE_BUFFER_MIN),
|
||||
# then records for the full window. Exits immediately if AUDIO_ENABLED≠true.
|
||||
# Triggered at 03:00 by sky-cam-audio-capture.timer; waits internally until
|
||||
# the right moment before recording. Exits immediately if AUDIO_ENABLED≠true.
|
||||
#
|
||||
# Output: BASE_DIR/SUNRISE_CAM/YYYY-MM-DD/sunrise-audio.m4a
|
||||
# Recording window: floor(TARGET/2) seconds before sunrise,
|
||||
# ceil(TARGET/2) seconds after (odd second goes to post).
|
||||
#
|
||||
# Output: BASE_DIR/<cam>/YYYY-MM-DD/sunrise-audio.m4a
|
||||
# Deleted automatically by daily_sunrise_video.sh after mixing.
|
||||
|
||||
set -euo pipefail
|
||||
@@ -40,13 +42,16 @@ fi
|
||||
sunrise_time_local=$(TZ="$TIMEZONE" date -d "$sunrise_time" +"%H:%M:%S")
|
||||
echo "Sunrise (local): $sunrise_time_local"
|
||||
|
||||
# ── Calculate wait and record duration ───────────────────────────────────────
|
||||
# ── Calculate recording window centred on sunrise ─────────────────────────────
|
||||
time_to_seconds() { IFS=':' read -r h m s <<< "$1"; echo $((10#$h*3600 + 10#$m*60 + 10#$s)); }
|
||||
|
||||
sunrise_sec=$(time_to_seconds "$sunrise_time_local")
|
||||
buffer_sec=$(( ${AUDIO_PRE_BUFFER_MIN:-2} * 60 ))
|
||||
record_start_sec=$(( sunrise_sec - SUNRISE_PRE_MIN * 60 - buffer_sec ))
|
||||
record_dur_sec=$(( (SUNRISE_PRE_MIN + SUNRISE_POST_MIN) * 60 + buffer_sec ))
|
||||
half_pre=$(( SUNRISE_TARGET_SECS / 2 )) # floor — pre-sunrise portion
|
||||
half_post=$(( SUNRISE_TARGET_SECS - half_pre )) # ceil — post-sunrise gets odd second
|
||||
record_start_sec=$(( sunrise_sec - half_pre ))
|
||||
record_dur_sec=$SUNRISE_TARGET_SECS
|
||||
|
||||
echo "Audio window: ${half_pre}s before → ${half_post}s after sunrise (${record_dur_sec}s total)"
|
||||
|
||||
midnight=$(date -d "today 00:00:00" +%s)
|
||||
now_day_sec=$(( $(date +%s) - midnight ))
|
||||
|
||||
Reference in New Issue
Block a user