"""Read one episode of the H1 street-crossing walks (LeRobot v2.1 format) without the LeRobot library.
Tested 2026-11-26 with Python 3.12.14, pyarrow 18.1.0 and opencv-python 5.1.0 on the published files.

meta/info.json describes the features and fps; each episode is one Parquet file plus one MP4 per camera.
Usage: python 05_lerobot_episode.py ./h1-street-crossing-lerobot 0
"""
import json, sys
import pyarrow.parquet as pq
import cv2

root = sys.argv[1] if len(sys.argv) > 1 else "./h1-street-crossing-lerobot"; ep = int(sys.argv[2]) if len(sys.argv) > 2 else 0
info = json.load(open(f"{root}/meta/info.json"))
print("format", info.get("codebase_version"), "| fps", info.get("fps"), "| episodes", info.get("total_episodes"), "| frames", info.get("total_frames"))
print("features:", ", ".join(f"{k} {v.get('shape')}" for k, v in info["features"].items()))
t = pq.read_table(f"{root}/data/chunk-000/episode_{ep:06d}.parquet")
print(f"episode {ep}: {t.num_rows} steps, columns: {t.column_names}")
a = t.column("action").to_pylist()
print("action (velocity command) at start, middle, end:", a[0], a[len(a) // 2], a[-1])
cap = cv2.VideoCapture(f"{root}/videos/chunk-000/observation.images.ego_view/episode_{ep:06d}.mp4")
print("head-camera video:", int(cap.get(cv2.CAP_PROP_FRAME_COUNT)), "frames at", round(cap.get(cv2.CAP_PROP_FPS), 2), "fps,",
      int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), "x", int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
