#!/bin/bash
set -euo pipefail

BASE_DIR="Dataset_RARP_video"
FPS=30   # change to your desired sampling rate (e.g., 0.5, 2, etc.)

for folder in "$BASE_DIR"/*; do
  [ -d "$folder" ] || continue
  for video in "$folder"/*.mp4; do
    [ -f "$video" ] || continue
    echo "Extracting lossless WebP from: $video"
    echo "$folder/frames/frame_%04d.webp"
    mkdir "$folder/frames"

    ffmpeg -hide_banner -i "$video" -vf "fps=${FPS},scale=640:360,format=rgb24" -vcodec libwebp -lossless 1 -compression_level 6  "$folder/frames/frame_%04d.webp"

    echo "Saved to: $folder"
  done
done

echo "✅ Done."