#!/bin/bash # Script to create a 4-panel video from front, side, and top view images # Layout: # - Top Left: Front view # - Top Right: Side view # - Bottom Left: Top view # - Bottom Right: Empty (black) for future content set -e BASE_PATH="/home/warlock/Projects/ScfHeatmapGen/js/2025-10-06_18-00-42" FRONT_DIR="$BASE_PATH/front" SIDE_DIR="$BASE_PATH/side" TOP_DIR="$BASE_PATH/top" OUTPUT_DIR="$BASE_PATH/temp_frames" OUTPUT_VIDEO="$BASE_PATH/combined_4panel_video.mp4" echo "Creating 4-panel video from heatmap images..." # Create temporary directory for combined frames mkdir -p "$OUTPUT_DIR" # Get the number of images (assuming all directories have the same count) NUM_IMAGES=$(ls "$FRONT_DIR"/*.png | wc -l) echo "Found $NUM_IMAGES images in each directory" # Get dimensions of first image FIRST_IMG=$(ls "$FRONT_DIR"/*.png | head -1) IMG_INFO=$(identify "$FIRST_IMG") IMG_WIDTH=$(echo "$IMG_INFO" | cut -d' ' -f3 | cut -d'x' -f1) IMG_HEIGHT=$(echo "$IMG_INFO" | cut -d' ' -f3 | cut -d'x' -f2) echo "Image dimensions: ${IMG_WIDTH}x${IMG_HEIGHT}" # Calculate output dimensions (2x2 grid) OUTPUT_WIDTH=$((IMG_WIDTH * 2)) OUTPUT_HEIGHT=$((IMG_HEIGHT * 2)) echo "Output video dimensions: ${OUTPUT_WIDTH}x${OUTPUT_HEIGHT}" # Process each frame for i in $(seq -w 1 $NUM_IMAGES); do FRONT_IMG="$FRONT_DIR/${i}.png" SIDE_IMG="$SIDE_DIR/${i}.png" TOP_IMG="$TOP_DIR/${i}.png" OUTPUT_FRAME="$OUTPUT_DIR/frame_${i}.png" echo "Processing frame $i/$NUM_IMAGES" # Create a black panel for the bottom right convert -size ${IMG_WIDTH}x${IMG_HEIGHT} xc:black "$OUTPUT_DIR/empty_${i}.png" # Create 2x2 grid using ImageMagick montage montage \ "$FRONT_IMG" "$SIDE_IMG" \ "$TOP_IMG" "$OUTPUT_DIR/empty_${i}.png" \ -tile 2x2 \ -geometry ${IMG_WIDTH}x${IMG_HEIGHT}+0+0 \ -background black \ "$OUTPUT_FRAME" # Add labels to each panel convert "$OUTPUT_FRAME" \ -font DejaVu-Sans-Bold \ -pointsize 24 \ -fill white \ -annotate +20+30 "Front View" \ -annotate +$((IMG_WIDTH + 20))+30 "Side View" \ -annotate +20+$((IMG_HEIGHT + 30)) "Top View" \ -annotate +$((IMG_WIDTH + 20))+$((IMG_HEIGHT + 30)) "Reserved" \ "$OUTPUT_FRAME" # Clean up temporary empty panel rm "$OUTPUT_DIR/empty_${i}.png" done echo "All frames processed. Creating video..." # Create video from frames using FFmpeg ffmpeg -y \ -framerate 2 \ -i "$OUTPUT_DIR/frame_%03d.png" \ -c:v libopenh264 \ -pix_fmt yuv420p \ -crf 18 \ "$OUTPUT_VIDEO" echo "Video created: $OUTPUT_VIDEO" # # Clean up temporary frames # echo "Cleaning up temporary files..." # rm -rf "$OUTPUT_DIR" echo "Done! Video saved to: $OUTPUT_VIDEO" echo "Duration: $(echo "scale=2; $NUM_IMAGES/30" | bc) seconds"