#!/usr/bin/env bash
# scripts/manual/video-frame-fetch.sh
#
# Manual: fetch recent H.264 eye samples and render first frames for inspection.
# Not part of CI; requires SSH access to a live server.
set -euo pipefail

PI_HOST="nikto@192.168.42.253"  # user@IP-of lesavka
REMOTE_DIR="/tmp"               # where eye*-idr.h264 are written
FIRST_FEW=10

WORKDIR="$(mktemp -d)"
echo "⏬ pulling h264 samples from $PI_HOST ..."
scp "${PI_HOST}:${REMOTE_DIR}/eye*.h264" "$WORKDIR/"

echo "🎞️  converting to PNG ..."
for h264 in "$WORKDIR"/eye*.h264; do
    (( FIRST_FEW == 0 )) && break
    png="${h264%.h264}.png"
    ffmpeg -loglevel error -y -f h264 -i "$h264" -frames:v 1 "$png"
    echo "🖼️  $(basename "$png") ready"
    xdg-open "$png" >/dev/null 2>&1 &
    (( FIRST_FEW-- ))
done
echo "✅ done - images are opening (directory: $WORKDIR)"
