Add files via upload
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 261 KiB |
+182
@@ -0,0 +1,182 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# Get yesterday's date
|
||||
yesterday=$(date --date="yesterday" +%Y-%m-%d)
|
||||
current_year=$(date +%Y)
|
||||
day_of_year=$(date --date="$yesterday" +%j) # Day of the year (1 to 366)
|
||||
|
||||
# Define base directory and music directory
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
music_base_dir="/home/motion/drives/local-2tb/music/4 Seasons"
|
||||
|
||||
# Determine the season based on the day of the year
|
||||
if [ "$day_of_year" -ge 80 ] && [ "$day_of_year" -le 172 ]; then
|
||||
season="Spring"
|
||||
season_start_date=80
|
||||
season_end_date=172
|
||||
days_in_season=92
|
||||
elif [ "$day_of_year" -ge 173 ] && [ "$day_of_year" -le 264 ]; then
|
||||
season="Summer"
|
||||
season_start_date=173
|
||||
season_end_date=264
|
||||
days_in_season=92
|
||||
elif [ "$day_of_year" -ge 265 ] && [ "$day_of_year" -le 355 ]; then
|
||||
season="Autumn"
|
||||
season_start_date=265
|
||||
season_end_date=355
|
||||
days_in_season=91
|
||||
else
|
||||
season="Winter"
|
||||
season_start_date=356
|
||||
season_end_date=79
|
||||
days_in_season=90
|
||||
fi
|
||||
|
||||
# Calculate the day of the season (from 1 to days_in_season)
|
||||
if [ "$season" == "Winter" ]; then
|
||||
if [ "$day_of_year" -ge 355 ]; then
|
||||
# Winter season starts at day 1 on Dec 21st
|
||||
day_of_season=$(($day_of_year - 354)) # Day 1 of Winter starts on Dec 21st
|
||||
else
|
||||
# Before Dec 21st, Winter starts on Dec 21st in the previous year
|
||||
day_of_season=$((365 - 354 + $day_of_year)) # Adjust for the 365th day (Dec 20th) in the previous year
|
||||
fi
|
||||
else
|
||||
day_of_season=$(($day_of_year - $season_start_date + 1))
|
||||
fi
|
||||
|
||||
# Determine the movement based on the day of the season
|
||||
if [ "$season" == "Winter" ]; then
|
||||
# Winter typically has three movements, so we calculate the movement number
|
||||
if [ "$day_of_season" -le 30 ]; then
|
||||
movement_num=1
|
||||
elif [ "$day_of_season" -le 60 ]; then
|
||||
movement_num=2
|
||||
else
|
||||
movement_num=3
|
||||
fi
|
||||
else
|
||||
# Other seasons follow the same calculation for movement
|
||||
if [ "$day_of_season" -le 30 ]; then
|
||||
movement_num=1
|
||||
elif [ "$day_of_season" -le 60 ]; then
|
||||
movement_num=2
|
||||
else
|
||||
movement_num=3
|
||||
fi
|
||||
fi
|
||||
|
||||
# Determine the music file based on the season and movement
|
||||
music_file=$(find "$music_base_dir" -type f -iname "*$season Mvt $movement_num*" | head -n 1)
|
||||
|
||||
# Check if the music file exists
|
||||
if [ ! -f "$music_file" ]; then
|
||||
echo "Music file for $season, Movement $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" # Printing the music duration for verification
|
||||
|
||||
# Define the directory where images are stored (using yesterday's date)
|
||||
first_word_of_script_folder=$(basename "$(dirname "$(realpath "$0")")" | cut -d'-' -f1)
|
||||
image_dir="$base_dir/$first_word_of_script_folder/$yesterday"
|
||||
|
||||
# Check if the image directory exists
|
||||
if [ ! -d "$image_dir" ]; then
|
||||
echo "Error: Image directory $image_dir not found for $yesterday!"
|
||||
echo "Skipping this day's video generation."
|
||||
# Log the missing day
|
||||
echo "No images for $yesterday" >> /path/to/missing_days.log
|
||||
# Skip to the next day
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get today's date in yyyy-mm format for output directory
|
||||
output_date=$(date +"%Y-%m") # yyyy-mm format
|
||||
|
||||
# Dynamically generate the output directory based on season and movement
|
||||
output_dir="$base_dir/movies/$first_word_of_script_folder/$season/Mvt$movement_num"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
# Count the total number of images (JPEG files)
|
||||
total_images=$(find "$image_dir" -type f -name "*.jpg" | wc -l)
|
||||
|
||||
# If there are no images, log it and move to the next day
|
||||
if [ "$total_images" -lt 1 ]; then
|
||||
echo "Error: No images found in $image_dir for $yesterday."
|
||||
echo "Skipping this day's video generation."
|
||||
# Log the missing day
|
||||
echo "No images for $yesterday" >> /path/to/missing_days.log
|
||||
# Skip to the next day
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Create a temporary text file with the sorted list of image paths
|
||||
temp_file=$(mktemp)
|
||||
find "$image_dir" -type f -name "*.jpg" | sort -n | while read image; do
|
||||
echo "file '$image'" >> "$temp_file"
|
||||
done
|
||||
|
||||
# Calculate the number of images
|
||||
num_images=$(wc -l < "$temp_file")
|
||||
echo "Total images found for the video: $num_images"
|
||||
|
||||
# Calculate the target total duration (music duration + 3 seconds for transitions)
|
||||
target_total_duration=$(echo "$music_duration + 3" | bc)
|
||||
echo "Target total video duration (music + 3 seconds): $target_total_duration seconds"
|
||||
|
||||
# Calculate the target duration per video (based on number of days in the season)
|
||||
target_duration_per_video=$(echo "$target_total_duration / $days_in_season" | bc -l)
|
||||
echo "Each day's target video length: $target_duration_per_video seconds"
|
||||
|
||||
# Check if the daily video length is too short (less than 1.67 seconds)
|
||||
if (( $(echo "$target_duration_per_video < 1.67" | bc -l) )); then
|
||||
echo "Daily video length is less than 1.67 seconds. Doubling the music duration."
|
||||
music_duration=$(echo "$music_duration * 2" | bc)
|
||||
target_total_duration=$(echo "$music_duration + 3" | bc)
|
||||
target_duration_per_video=$(echo "$target_total_duration / $days_in_season" | bc -l)
|
||||
echo "New target total video duration (after doubling music): $target_total_duration seconds"
|
||||
echo "New target duration per video: $target_duration_per_video seconds"
|
||||
fi
|
||||
|
||||
# First, create the video using default frame rate (no speed-up or slow-down yet)
|
||||
temp_video="$output_dir/${yesterday}_Mvt${movement_num}-temp.mp4"
|
||||
echo "Creating video at default frame rate..."
|
||||
ffmpeg -f concat -safe 0 -i "$temp_file" -c:v libx264 -pix_fmt yuv420p -crf 28 -vsync 2 -y "$temp_video"
|
||||
|
||||
# Check the duration of the created video
|
||||
video_duration=$(ffmpeg -i "$temp_video" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//)
|
||||
echo "Initial video duration: $video_duration"
|
||||
|
||||
# Get the video duration in seconds (from HH:MM:SS format)
|
||||
IFS=':' read -r hours minutes seconds <<< $(echo $video_duration | cut -d '.' -f1) # Extract time
|
||||
total_seconds=$(($hours * 3600 + $minutes * 60 + $seconds)) # Convert to total seconds
|
||||
|
||||
# Calculate the speed-up factor to make the video fit into the target duration
|
||||
speed_up_factor=$(echo "scale=3; $total_seconds / $target_duration_per_video" | bc)
|
||||
echo "Calculated speed-up factor: $speed_up_factor"
|
||||
|
||||
# Adjust the playback speed using the setpts filter to make the video fit into the target duration
|
||||
final_file_name="${yesterday}_Mvt${movement_num}-Day${day_of_season}of${days_in_season}-final.mp4"
|
||||
final_video="$output_dir/$final_file_name"
|
||||
ffmpeg -i "$temp_video" -filter:v "setpts=PTS/$speed_up_factor" -y "$final_video"
|
||||
|
||||
# Check the duration of the adjusted video
|
||||
adjusted_duration=$(ffmpeg -i "$final_video" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//)
|
||||
echo "Adjusted video duration: $adjusted_duration"
|
||||
|
||||
# Check for ffmpeg success
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ffmpeg failed to create the final video."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Inform user the video has been created
|
||||
echo "Video created at $final_video"
|
||||
|
||||
# Clean up the temporary file
|
||||
rm "$temp_file"
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#!/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"
|
||||
@@ -0,0 +1,96 @@
|
||||
import requests
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# Configuration file path (update the path to where your mattermost_config.txt is located)
|
||||
config_file_path = '/home/motion/drives/local-2tb/sunrise-scripts/mattermost_config.txt'
|
||||
|
||||
# Function to read configuration from the config file
|
||||
def read_config(config_file_path):
|
||||
config = {}
|
||||
try:
|
||||
with open(config_file_path, 'r') as f:
|
||||
for line in f:
|
||||
# Ignore comments and empty lines
|
||||
if line.strip() and not line.startswith('#'):
|
||||
key, value = line.strip().split('=', 1)
|
||||
config[key.strip()] = value.strip()
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The configuration file {config_file_path} was not found.")
|
||||
exit(1)
|
||||
except Exception as e:
|
||||
print(f"Error reading the configuration file: {e}")
|
||||
exit(1)
|
||||
return config
|
||||
|
||||
# Read configuration from the file
|
||||
config = read_config(config_file_path)
|
||||
|
||||
# Get the values from the configuration file
|
||||
mattermost_url = config.get('mattermost_url')
|
||||
access_token = config.get('access_token')
|
||||
channel_id = config.get('channel_id')
|
||||
|
||||
# Check if all required values are provided
|
||||
if not mattermost_url or not access_token or not channel_id:
|
||||
print("Error: Missing one or more configuration values.")
|
||||
exit(1)
|
||||
|
||||
# Get today's date
|
||||
today = datetime.now()
|
||||
today_date_str = today.strftime("%Y-%m-%d") # e.g., "2024-11-05"
|
||||
today_month_str = today.strftime("%Y-%m") # e.g., "2024-11"
|
||||
|
||||
# Set the full folder path for today's video
|
||||
base_video_folder = "/home/motion/drives/local-2tb/movies/sunrise" # Correct base folder for videos
|
||||
output_dir = os.path.join(base_video_folder, today_month_str, "sunrise-only") # Subfolder for final videos
|
||||
|
||||
# Check if the directory exists
|
||||
if not os.path.isdir(output_dir):
|
||||
print(f"Error: The directory {output_dir} does not exist. The video may not have been created yet.")
|
||||
exit(1)
|
||||
|
||||
# Find the sunrise video file for today (e.g., 2024-11-05-sunrise-10s.mp4)
|
||||
final_video_file = os.path.join(output_dir, f"{today_date_str}-sunrise-10s.mp4")
|
||||
|
||||
# Debugging: print the full path of the video file to make sure it's correct
|
||||
print(f"Looking for video file: {final_video_file}")
|
||||
|
||||
# Check if the video file exists
|
||||
if os.path.isfile(final_video_file):
|
||||
# Upload the video file
|
||||
with open(final_video_file, 'rb') as f:
|
||||
response = requests.post(
|
||||
f"{mattermost_url}/api/v4/files",
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
files={'files': f},
|
||||
data={'channel_id': channel_id}
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
print(f"Successfully uploaded {final_video_file}")
|
||||
|
||||
# Get the file ID from the response
|
||||
file_id = response.json().get('file_infos', [{}])[0].get('id')
|
||||
|
||||
# Send a message with the file reference
|
||||
message_data = {
|
||||
'channel_id': channel_id,
|
||||
'message': f"Here is a video of the sunrise for {today_date_str}",
|
||||
'file_ids': [file_id] # Attach the uploaded file
|
||||
}
|
||||
|
||||
message_response = requests.post(
|
||||
f"{mattermost_url}/api/v4/posts",
|
||||
headers={'Authorization': f'Bearer {access_token}'},
|
||||
json=message_data
|
||||
)
|
||||
|
||||
if message_response.status_code == 201:
|
||||
print("Message posted successfully.")
|
||||
else:
|
||||
print(f"Failed to post message: {message_response.text}")
|
||||
else:
|
||||
print(f"Failed to upload {final_video_file}: {response.text}")
|
||||
else:
|
||||
print(f"No video file found at {final_video_file}.")
|
||||
@@ -0,0 +1,156 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get today's date in the format YYYY-MM-DD
|
||||
current_date=$(date +%Y-%m-%d)
|
||||
output_date=$(date +%Y-%m)
|
||||
|
||||
# Extract the base directory and the first word of the script's folder name
|
||||
base_dir="/home/motion/drives/local-2tb"
|
||||
script_dir=$(dirname "$(realpath "$0")") # Get the directory where the script is located
|
||||
first_word_of_script_folder=$(basename "$script_dir" | cut -d'-' -f1)
|
||||
|
||||
# Define the directory where images are stored (using today's date)
|
||||
image_dir="$base_dir/$first_word_of_script_folder/$current_date"
|
||||
|
||||
# Set output directory (new structure with 'sunrise-only' subfolder)
|
||||
output_dir="/home/motion/drives/local-2tb/movies/sunrise/$output_date/sunrise-only"
|
||||
|
||||
# Make sure the output directory exists
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
# Get the sunrise time for today using the sunrise.py script
|
||||
sunrise_time=$(python3 /home/motion/drives/local-2tb/sunrise-scripts/sunrise.py)
|
||||
|
||||
# Check if the sunrise time was fetched successfully
|
||||
if [[ -z "$sunrise_time" ]]; then
|
||||
echo "Error: Failed to retrieve sunrise time."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Output the sunrise time in UTC
|
||||
echo "Sunrise time (UTC): $sunrise_time"
|
||||
|
||||
# Set the time zone to Eastern US time (America/New_York)
|
||||
export TZ="America/New_York"
|
||||
|
||||
# Convert sunrise time from UTC to Eastern Time (ET)
|
||||
sunrise_time_et=$(TZ="America/New_York" date -d "$sunrise_time" +"%H-%M-%S")
|
||||
|
||||
# Output the converted sunrise time in Eastern Time
|
||||
echo "Sunrise time (Eastern Time): $sunrise_time_et"
|
||||
|
||||
# Function to convert time to seconds since midnight
|
||||
time_to_seconds() {
|
||||
IFS='-' read -r h m s <<< "$1"
|
||||
echo $((10#$h * 3600 + 10#$m * 60 + 10#$s))
|
||||
}
|
||||
|
||||
# Convert sunrise time (in Eastern Time) to seconds since midnight
|
||||
sunrise_seconds=$(time_to_seconds "$sunrise_time_et")
|
||||
|
||||
# Calculate the start and end times (60 minutes before sunrise and 15 minutes after sunrise)
|
||||
start_seconds=$((sunrise_seconds - 70 * 60)) # 60 minutes before sunrise
|
||||
end_seconds=$((sunrise_seconds + 10 * 60)) # 20 minutes after sunrise
|
||||
|
||||
# Output the start and end times in seconds for debugging
|
||||
echo "Start seconds: $start_seconds"
|
||||
echo "End seconds: $end_seconds"
|
||||
echo "Sunrise seconds: $sunrise_seconds"
|
||||
|
||||
# Check if the image directory exists
|
||||
if [ ! -d "$image_dir" ]; then
|
||||
echo "Error: The directory for images does not exist: $image_dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temporary file to store the list of image files
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# Find, sort, and process images in the specified directory
|
||||
# Sort files by filename, which will order them correctly by MM-DD-SS
|
||||
find "$image_dir" -type f -name "*.jpg" | sort -n | while read -r image; do
|
||||
# Extract the time portion of the filename (e.g., 09-16-00 from 09-16-00.jpg)
|
||||
image_time=$(basename "$image" .jpg) # MM-DD-SS
|
||||
|
||||
# Convert image time to seconds since midnight
|
||||
image_seconds=$(time_to_seconds "$image_time")
|
||||
|
||||
# Debug: Output the image time and its seconds since midnight
|
||||
echo "Image: $image, Time: $image_time, Seconds: $image_seconds"
|
||||
|
||||
# Check if the image time falls within the specified range
|
||||
if [[ $image_seconds -ge $start_seconds && $image_seconds -le $end_seconds ]]; then
|
||||
echo "Image $image_time ($image_seconds) is within the range [$start_seconds, $end_seconds]"
|
||||
|
||||
# Add the image to the temporary file
|
||||
echo "file '$image'" >> "$temp_file"
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if any images were found in the time range
|
||||
if [ ! -s "$temp_file" ]; then
|
||||
echo "No images found within the specified time range."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Calculate the number of images
|
||||
num_images=$(wc -l < "$temp_file")
|
||||
echo "Total images to be included in the video: $num_images"
|
||||
|
||||
# Output video filename for the first movie (no speed adjustments)
|
||||
first_movie="$output_dir/$current_date-sunrise-day.mp4"
|
||||
|
||||
# Create the first movie at the default frame rate (no speed adjustments)
|
||||
echo "Creating video at default frame rate..."
|
||||
ffmpeg -f concat -safe 0 -i "$temp_file" -c:v libx264 -pix_fmt yuv420p -crf 28 -vsync 2 -y "$first_movie"
|
||||
|
||||
# Check the duration of the created video
|
||||
video_duration=$(ffmpeg -i "$first_movie" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//)
|
||||
echo "Initial video duration: $video_duration"
|
||||
|
||||
# Get the video duration in seconds (from HH:MM:SS format)
|
||||
IFS=':' read -r hours minutes seconds <<< $(echo $video_duration | cut -d '.' -f1) # Extract time
|
||||
total_seconds=$(($hours * 3600 + $minutes * 60 + $seconds)) # Convert to total seconds
|
||||
|
||||
# Target video duration: 10 seconds
|
||||
target_duration=8
|
||||
|
||||
# Calculate the speed-up factor to make the video fit into the target duration of 10 seconds
|
||||
speed_up_factor=$(echo "scale=3; $total_seconds / $target_duration" | bc)
|
||||
echo "Calculated speed-up factor: $speed_up_factor"
|
||||
|
||||
# Output filename for the second movie (speed-adjusted)
|
||||
final_video="$output_dir/$current_date-sunrise-10s.mp4"
|
||||
|
||||
# Apply the speed adjustment using the setpts filter
|
||||
echo "Adjusting video speed to target duration of 10 seconds..."
|
||||
ffmpeg -i "$first_movie" -filter:v "setpts=PTS/$speed_up_factor" -y "$final_video"
|
||||
|
||||
# Check the duration of the adjusted video
|
||||
adjusted_duration=$(ffmpeg -i "$final_video" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,//)
|
||||
echo "Adjusted video duration: $adjusted_duration"
|
||||
|
||||
# Check for ffmpeg success
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error: ffmpeg failed to create the final video."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Inform user the video has been created
|
||||
echo "Video created at $final_video"
|
||||
|
||||
# Clean up temporary files
|
||||
rm "$temp_file"
|
||||
|
||||
# Run the sunrise_overlay.py script to add the sunrise overlay
|
||||
python3 /home/motion/drives/local-2tb/sunrise-scripts/sunrise_overlay.py "$final_video"
|
||||
|
||||
# Run the sunrise2mm.py script to upload the video
|
||||
python3 /home/motion/drives/local-2tb/sunrise-scripts/sunrise2mm.py
|
||||
|
||||
# Check if the Python script was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully uploaded the video to Mattermost."
|
||||
else
|
||||
echo "There was an issue uploading the video to Mattermost."
|
||||
fi
|
||||
Reference in New Issue
Block a user