log "Checking width and height…"
do shell script "
# Ensure ffmpeg and ffprobe are in the PATH;
export PATH=/usr/local/bin:$PATH;
# Navigate to the working directory;
cd 'Path/to/folder/';
# Define the video file path;
video_file='/Path/to/video';
# Use ffprobe to extract video width and height;
dimensions=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0:s=x $video_file);
# Parse the dimensions to get width and height;
width=$(echo $dimensions | cut -d'x' -f1);
height=$(echo $dimensions | cut -d'x' -f2);
# Debugging: Display width and height;
echo 'Width: $width';
echo 'Height: $height';
# Check if width and height are valid numbers;
if ! [[ $width =~ ^[0-9]+$ ]] || ! [[ $height =~ ^[0-9]+$ ]]; then
echo 'Error: Could not retrieve video dimensions.';
exit 1;
fi;
# Compare width and height;
if [ $width -gt $height ]; then
# Do wider than tall rotation here;
echo 'Processing wider than tall video...';
ffmpeg -y -display_rotation:v:0 -90.0 -I $video_file -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -shortest './Temp/new_video_temp_name.mov';
elif [ '$width' -lt '$height' ]; then
#Process taller than wide video with no rotation
echo 'Processing taller than wide video...';
ffmpeg -y -display_rotation:v:0 0.0 -i $video_file -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -shortest './Temp/new_video_temp_name.mov'
else
# Handle square video;
echo 'Processing square video...';
ffmpeg -y -display_rotation:v:0 0.0 -i $video_file -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -shortest './Temp/new_video_temp_name.mov'
fi;
"