#!/bin/bash

# Check if the required argument is provided
if [ "$#" -ne 2 ]; then
    echo "Usage: $0 input.mp4 output.gif"
    exit 1
fi

input_file=$1
output_file=$2

# Check if FFmpeg is installed
if ! command -v ffmpeg &> /dev/null; then
    echo "Error: FFmpeg is not installed. Please install it first."
    exit 1
fi

# Convert MP4 to GIF using FFmpeg with improved quality settings
ffmpeg -i "$input_file" -vf "fps=15,scale=640:-1:flags=lanczos" -c:v gif -b:v 2M -movflags +faststart "$output_file"

echo "Conversion complete. Output file: $output_file"
