this post was submitted on 08 Oct 2024
11 points (100.0% liked)

Linux

5230 readers
199 users here now

A community for everything relating to the linux operating system

Also check out [email protected]

Original icon base courtesy of [email protected] and The GIMP

founded 1 year ago
MODERATORS
 

I want to create a collage of 20 screenshots from a video, arranged in a 5x4 grid, regardless of the video’s length. How can I do this efficiently on a Linux system?

Specifically, I’d like a way to automatically generate this collage of 20 thumbnails from the video, without having to manually select and arrange the screenshots. The number of thumbnails should always be 20, even if the video is longer or shorter.

Can you suggest a command-line tool or script that can handle this task efficiently on Linux? I’m looking for a solution that is automated and doesn’t require a lot of manual work.

Here's what I've tried but I only get 20 black boxes:

#!/bin/bash

# Check if input video exists
if [ ! -f "$1" ]; then
    echo "Error: Input video file not found."
    exit 1
fi

# Get video duration
duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1")

# Calculate interval between frames
interval=$((duration / 20))

# Extract 20 frames from the video
for i in {1..20}; do
    ffmpeg -ss $((interval * ($i - 1))) -i "$1" -vf scale=200:-1 -q:v 2 "${1%.*}_frame$i.jpg"
done

# Create collage
montage -mode concatenate -tile 5x4 -geometry +2+2 "${1%.*}_frame*.jpg" output_collage.jpg

# Clean up temporary files
rm "${1%.*}_frame*.jpg"

echo "Collage created: output_collage.jpg"
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 1 month ago

Apparently the client I was using didn't render codeblock markdown. Thanks for the pointer. Found a better client.