#!/bin/bash

input_folder="."
output_folder="./output"

# Ensure the output folder exists
mkdir -p "$output_folder"

# Loop through all video files in the input folder
for video_file in "$input_folder"/*.mp4; do
    # Extract the filename without extension
    filename=$(basename -- "$video_file")
    filename_no_extension="${filename%.*}"

    # Define the output GIF file
    output_gif="$output_folder/${filename_no_extension}.gif"

    # FFmpeg command to generate GIF
    ffmpeg -i "$video_file" -filter_complex "[0:v]fps=15,scale=320:-1,split [a][b];[a]palettegen[p];[b][p]paletteuse" "$output_gif"

    echo "Generated GIF: $output_gif"
done
