Last active
February 2, 2024 17:56
-
-
Save TotalLag/a975c055b6ec5bc3dcfb1a0fdb5b978e to your computer and use it in GitHub Desktop.
This script is designed to create a selective and impactful collage, utilizing a 3x5 tile layout to present a selection of moments from the video. By extracting 15 frames at optimized intervals and sizes, and outputting as a high-quality JPEG, the script aims to produce a visually engaging summary of the video content.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check for the correct number of arguments | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 <video_filename>" | |
exit 1 | |
fi | |
VIDEO_FILE="$1" | |
DURATION=$(ffmpeg -i "$VIDEO_FILE" 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F: '{print $1*3600+$2*60+$3}') | |
# Calculate the interval for extracting 15 frames | |
INTERVAL=$(echo "scale=2; $DURATION / 15" | bc -l) | |
TEMP_DIR=$(mktemp -d) | |
# Extract and scale down frames to fit within 800 pixels in width, maintaining aspect ratio | |
ffmpeg -i "$VIDEO_FILE" -vf "fps=1/$INTERVAL,scale='min(800,iw):-2'" -vsync vfr "$TEMP_DIR/frame_%04d.png" | |
OUTPUT_FILE="${VIDEO_FILE%.*}-collage.jpg" | |
# Update the montage command for a 3x5 tile layout and output as JPEG | |
montage "$TEMP_DIR/frame_*.png" -geometry +0+0 -tile 3x5 -quality 85 "$OUTPUT_FILE" | |
# Clean up the temporary directory | |
rm -r "$TEMP_DIR" | |
echo "Collage created: $OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment