Files
sky-cam/montage-mvt.sh
T
2026-04-17 22:48:48 -04:00

109 lines
3.6 KiB
Bash

#!/bin/bash
# Set parameters dynamically based on the current date
current_date=$(date +%Y-%m-%d)
current_year=$(date +%Y)
day_of_year=$(date +%j) # The day of the year (e.g., 1-365)
# Define season and movement parameters based on the current date
if [ $day_of_year -ge 265 ] && [ $day_of_year -le 355 ]; then
season="Autumn"
movement_num=3
season_start_date=265
season_end_date=355
days_in_season=91
day_of_season=$((day_of_year - season_start_date + 1)) # Calculate the day of the season
elif [ $day_of_year -ge 1 ] && [ $day_of_year -le 79 ]; then
season="Winter"
movement_num=1
season_start_date=1
season_end_date=79
days_in_season=79
day_of_season=$((day_of_year - season_start_date + 1))
elif [ $day_of_year -ge 80 ] && [ $day_of_year -le 171 ]; then
season="Spring"
movement_num=2
season_start_date=80
season_end_date=171
days_in_season=92
day_of_season=$((day_of_year - season_start_date + 1))
elif [ $day_of_year -ge 172 ] && [ $day_of_year -le 264 ]; then
season="Summer"
movement_num=4
season_start_date=172
season_end_date=264
days_in_season=93
day_of_season=$((day_of_year - season_start_date + 1))
else
echo "Season not found for the current date"
exit 1
fi
# Debugging info: Print dynamic parameters
echo "Season: $season"
echo "Movement: $movement_num"
echo "Day of Year: $day_of_year"
# Set the directory for the videos dynamically based on the season and movement
video_base_dir="/home/motion/drives/local-2tb/movies/sunrise/$season/Mvt$movement_num"
echo "Looking for video files in: $video_base_dir"
# Ensure the video directory exists
if [ ! -d "$video_base_dir" ]; then
echo "Video directory $video_base_dir not found"
exit 1
fi
# Find the music file for the current season and movement
music_file=$(find "/home/motion/drives/local-2tb/music/4 Seasons" -type f -iname "*$season Mvt $movement_num*" | head -n 1)
# Ensure the music file exists
if [ ! -f "$music_file" ]; then
echo "Music file for $season Mvt $movement_num not found"
exit 1
fi
# Get the duration of the music file in seconds
music_duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$music_file")
echo "Music duration: $music_duration seconds"
# Find all video files ending in "-final.mp4" using ls and grep
video_files=()
echo "Looking for video files in: $video_base_dir"
for video_file in $(ls "$video_base_dir" | grep -i "Mvt${movement_num}.*-final.mp4"); do
full_path="$video_base_dir/$video_file"
if [ -f "$full_path" ]; then
video_files+=("$full_path")
fi
done
# Check if video files were found
if [ ${#video_files[@]} -eq 0 ]; then
echo "No video files found for $season Mvt$movement_num in $video_base_dir"
exit 1
else
echo "Found ${#video_files[@]} video files for $season Mvt$movement_num"
fi
# Prepare a temporary file for concatenation
temp_file=$(mktemp)
for video_file in "${video_files[@]}"; do
echo "file '$video_file'" >> "$temp_file"
done
# Set the output directory and file for the montage
output_dir="$video_base_dir/$current_year-$month"
mkdir -p "$output_dir"
output_file="$output_dir/$(date +"%Y-%m-%d")_Mvt$movement_num-Montage.mp4"
# Create the final montage by concatenating the video files with the music
echo "Creating montage for $season Mvt $movement_num..."
# Use ffmpeg to concatenate the video files and overlay the music
ffmpeg -f concat -safe 0 -i "$temp_file" -i "$music_file" -c:v libx264 -pix_fmt yuv420p -c:a aac -strict experimental -shortest "$output_file"
# Clean up temporary file
rm "$temp_file"
echo "Montage created: $output_file"