#!/bin/bash
# 每 20 秒抽一帧，拼成总览图传回 OCS（用来找笔出现的位置和样子）
set -u
cd /home/agent/.claude/workspace/project
mkdir -p qc/frames
FF=$(python3 -c "import imageio_ffmpeg; print(imageio_ffmpeg.get_ffmpeg_exe())")
for n in 1 2 3 4; do
  dur=$(python3 -c "import av; c=av.open('data/uploads/shipin${n}.mp4'); print(round(float(c.duration/av.time_base),1))")
  echo "=== shipin${n}: ${dur}s ==="
  rm -f qc/frames/shipin${n}_*.jpg
  "$FF" -hide_banner -loglevel error -y -i "data/uploads/shipin${n}.mp4" -vf "fps=1/20,scale=640:-1" "qc/frames/shipin${n}_%03d.jpg"
  cnt=$(ls qc/frames/shipin${n}_*.jpg | wc -l)
  echo "frames: $cnt"
  "$FF" -hide_banner -loglevel error -y -i "qc/frames/shipin${n}_%03d.jpg" -filter_complex "tile=4x4" -frames:v 1 -q:v 3 "qc/shipin${n}_grid.jpg"
  ls -la "qc/shipin${n}_grid.jpg"
  curl -s --upload-file "qc/shipin${n}_grid.jpg" "https://ocs.dimond.top/shipin${n}_grid.jpg"
  echo
done
echo "GRID DONE"
