#!/usr/bin/env bash
set -euo pipefail

# Launcher for batch exporting PDCL MCAP clips to frames + calibration.
#
# Usage:
#   bash tools/pdcl_inference/export_mcap_frames_by_clip_id.sh
#
# Optional env overrides:
#   CLIP_LIST_FILE, OUTPUT_ROOT, OUTPUT_PREFIX,
#   CAMERA_TOPIC, MAX_FRAMES_PER_CLIP, CALIB_FILE, EXTRA_ARGS

CLIP_LIST_FILE="${CLIP_LIST_FILE:-tools/pdcl_inference/clips_6284.txt}"
OUTPUT_ROOT="${OUTPUT_ROOT:-/data1/dongying/Mono3d/G1M3/cases_pdcl_clips}"
OUTPUT_PREFIX="${OUTPUT_PREFIX:-}"
CAMERA_TOPIC="${CAMERA_TOPIC:-camera4}"
MAX_FRAMES_PER_CLIP="${MAX_FRAMES_PER_CLIP:-0}"
CALIB_FILE="${CALIB_FILE:-}"
EXTRA_ARGS="${EXTRA_ARGS:-}"

python tools/pdcl_inference/export_mcap_frames_by_clip_id.py \
  --clip-list-file "${CLIP_LIST_FILE}" \
  --output-root "${OUTPUT_ROOT}" \
  --output-prefix "${OUTPUT_PREFIX}" \
  --camera-topic "${CAMERA_TOPIC}" \
  --max-frames-per-clip "${MAX_FRAMES_PER_CLIP}" \
  ${CALIB_FILE:+--calib-file "${CALIB_FILE}"} \
  --skip-done \
  ${EXTRA_ARGS}
