finger / process_videos.sh
huzey's picture
init
1a01fdb
#!/bin/bash
# Directory containing the videos
VIDEO_DIR="predefined"
# Target dimensions
TARGET_WIDTH=720
TARGET_HEIGHT=640
# Process each video in the directory
for video in "$VIDEO_DIR"/*.mov; do
if [ -f "$video" ]; then
echo "Processing: $video"
# Get video dimensions
width=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=noprint_wrappers=1:nokey=1 "$video")
height=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=noprint_wrappers=1:nokey=1 "$video")
# Calculate crop dimensions for 720:640 aspect ratio
if [ "$width" -gt "$height" ]; then
# If video is wider than tall
crop_width=$(( height * TARGET_WIDTH / TARGET_HEIGHT ))
crop_height=$height
x_offset=$(( (width - crop_width) / 2 ))
y_offset=0
else
# If video is taller than wide
crop_width=$width
crop_height=$(( width * TARGET_HEIGHT / TARGET_WIDTH ))
x_offset=0
y_offset=$(( (height - crop_height) / 2 ))
fi
# Process video with ffmpeg
ffmpeg -i "$video" \
-af "aresample=48000" \
-vf "crop=$crop_width:$crop_height:$x_offset:$y_offset,scale=$TARGET_WIDTH:$TARGET_HEIGHT" \
-c:v libx264 \
-c:a aac \
-y \
"${video%.*}_processed.mov"
echo "Completed: $video"
fi
done
echo "All videos processed!"