"""Minimal loader pairing decoded RGB frames with per-frame action rows. Usage: pip install opencv-python python load_sample.py --dir . --segment 0 --limit 300 """ from __future__ import annotations import argparse import json from pathlib import Path from typing import Iterator try: import cv2 except ImportError as exc: raise SystemExit("opencv-python is required: pip install opencv-python") from exc SESSION_ID = "cafe4f6a-ad46-4fb8-9f81-5779f6761be1" def iter_segment(session_dir: Path, segment_index: int) -> Iterator[tuple[int, object, dict]]: stem = f"seg-{segment_index:03d}" video_path = session_dir / f"{stem}.mp4" actions_path = session_dir / f"{stem}.jsonl" cap = cv2.VideoCapture(str(video_path)) if not cap.isOpened(): raise RuntimeError(f"Could not open {video_path}") try: with actions_path.open("r", encoding="utf-8") as f: for line in f: ok, frame_bgr = cap.read() if not ok: break action = json.loads(line) frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB) yield action["frame"], frame_rgb, action finally: cap.release() def main() -> None: parser = argparse.ArgumentParser(description="Inspect Fallout 4 open sample frames and actions.") parser.add_argument("--dir", type=Path, default=Path("."), help="Path to fallout4-30min-open root") parser.add_argument("--segment", type=int, default=0, choices=[0, 1, 2], help="Segment index (0..2)") parser.add_argument("--limit", type=int, default=300, help="Max frames to iterate (0 for all)") args = parser.parse_args() session_dir = args.dir / "sessions" / SESSION_ID count = 0 active = 0 for frame_idx, rgb, action in iter_segment(session_dir, args.segment): mouse = action.get("mouse", {}) keys = action.get("keys", []) dx = mouse.get("dx", 0) dy = mouse.get("dy", 0) if keys or dx or dy or mouse.get("buttons"): active += 1 if count < 5 or (count % 60 == 0): print(f"frame={frame_idx} shape={rgb.shape} t={action['t_s']:.3f}s keys={keys} dx={dx} dy={dy}") count += 1 if args.limit and count >= args.limit: break print(f"Read {count} frames from seg-{args.segment:03d} ({active} with active input).") if __name__ == "__main__": main()