# Arcturus Vision Camera recording metadata

Current Camera recordings store per-frame timing, camera calibration, and available pose data in an embedded `gpmd` data track. [sample_per_frame_metadata.json](sample_per_frame_metadata.json) shows the JSON for one frame.

Use the original MP4 transferred with Arcturus Vision Sync. Run these commands in a shell on macOS, Linux, or Windows Subsystem for Linux (WSL) with FFmpeg (`ffmpeg` and `ffprobe`) and Python 3.8 or later installed.

## 1. Find and extract the metadata track

```sh
ffprobe -v error -select_streams d \
  -show_entries stream=index,codec_tag_string:stream_tags=handler_name \
  -of compact "recording.mp4"
```

Find the `gpmd` stream with the `VideoPlayerXR Timed Metadata` handler. Replace `2` below with its `index`. If the track is missing, check that you have the original recording. A converted export may omit the data track.

```sh
ffmpeg -v error -n -i "recording.mp4" -map 0:2 -c copy -f data metadata.gpmf
```

## 2. Dump the metadata as JSON Lines

The command reads the `AVmf` / `AVmd` records for the `json/v1` format and writes one JSON object per frame to `metadata.jsonl`. Choose a new output filename for each recording.

```sh
python3 - metadata.gpmf > metadata.jsonl <<'PY'
import json
import struct
import sys

header = struct.Struct(">4scBH")

def records(source):
    while raw := source.read(header.size):
        if len(raw) != header.size:
            raise SystemExit("Incomplete GPMF header")
        key, type_code, size, count = header.unpack(raw)
        length = size * count
        padded_length = (length + 3) & ~3
        data = source.read(padded_length)
        if not size or len(data) != padded_length:
            raise SystemExit("Invalid or incomplete GPMF record")
        yield key, type_code, size, data[:length]

frames = 0
with open(sys.argv[1], "rb") as source:
    stream = records(source)
    for record in stream:
        if record != (b"AVmf", b"c", 1, b"json/v1"):
            continue
        payload = next(stream, None)
        if payload is None or payload[:3] != (b"AVmd", b"c", 1):
            raise SystemExit("Expected an AVmd payload after the json/v1 marker")
        frame = json.loads(payload[3].decode("utf-8"))
        if not isinstance(frame, dict):
            raise SystemExit("Expected a JSON object for each frame")
        print(json.dumps(frame, separators=(",", ":")))
        frames += 1

if not frames:
    raise SystemExit("No json/v1 frame metadata found")
PY
```

To pretty-print the first frame and count all exported frames, run:

```sh
head -n 1 metadata.jsonl | python3 -m json.tool
wc -l < metadata.jsonl
```
