File size: 2,519 Bytes
5fee01c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""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()