Knonik Ingest

This guide explains how to use Knonik ingest from the wheel-based Knonik package.

You can use ingest in two ways:

  • ▸Terminal: knonik ingest ... and knonik pack ...
  • ▸Python: knonik.ingest.run(...) and knonik.ingest.pack(...)

1. What Ingest Does

Knonik ingest converts raw robot datasets into Knonik compressed episode directories. Those episode directories can then be packed into KHLP shards for the Knonik multidataloader.

Supported source families include:

  • ▸HDF5
  • ▸NPY / NPZ
  • ▸Zarr (per-episode or consolidated)
  • ▸LeRobot v2
  • ▸LeRobot v3
  • ▸ROS bags - ROS1 .bag and ROS2 MCAP / SQLite3 (.mcap, .db3, or a ROS2 bag directory)
  • ▸RLDS / TFRecord, when the required optional dependencies are available
  • ▸D3IL
  • ▸Directories of video files - phone, factory or headset recordings (section 6.5)

Unsupported format? You do not have to wait for a built-in reader. You can ingest any format into Knonik using one of two generic adapters - an offline one (dir_type: "npy_separate") and a streaming one (live ingest). See section 7.

Need to go the other way? The Export guide turns Knonik data back into HDF5, Zarr, LeRobot, ROS bag / MCAP, and more.

2. Install

Ingest ships in the Knonik wheel. See Overview → Install. Ingest, pack and export read and write local paths.

3. Log In

Log in once for ingest with your email and a CLI key from your dashboard (see Overview → Log In):

bash
knonik login --product ingest

The same login covers knonik ingest, knonik pack, knonik config and knonik export.

4. Offline Ingest From Terminal

Run offline ingest with:

bash
knonik ingest \
  --config /path/to/ingest_config.json \
  --input  /path/to/raw_dataset \
  --output /path/to/output_dir

The --config file describes your dataset - its on-disk layout, which keys hold each camera/state/action stream, and how to compress them. See section 6 for how to write one.

config files usually have data_dir in them, the --input flag overrides this. This helps in using the same config across multiple machines without any local dir and path issues.

Example:

bash
knonik ingest \
  --config /home/me/configs/config_lerobot_v3.json \
  --input  /home/me/data/thread_velcro \
  --output /home/me/data/out/knonik_thread_velcro

The dataset config ingest leaves behind

Every run finishes by writing a dataset config to <output>/config.json - a different file from the ingest config you passed in, describing the episodes that came out rather than the raw data that went in. It is what quality check and the visualizer in knonik viz read. Ingest fills in everything it can prove (stream names, widths, codecs, frame rate, timestamp semantics, and per-channel joint names where the source declares them) and marks the semantic parts - which stream is the action, where the arms are - with <FILL:...> placeholders for you to complete. See Quality & Annotation §6.

An existing config.json in the output directory is never overwritten. Add --force-config to regenerate it:

bash
knonik ingest --config ingest.json --input /raw --output /out --force-config

5. Pack Into KHLP From Terminal

After ingest writes episode directories (and, optionally, you have checked and annotated them in knonik viz), pack them for the dataloader:

bash
knonik pack \
  --input-dir    /path/to/output_dir/knonik_dataset \
  --output-dir   /path/to/packed_dir \
  --dataset-name my_dataset \
  --fps          30

Example:

bash
knonik pack \
  --input-dir    /home/me/data/out/knonik_thread_velcro \
  --output-dir   /home/me/data/out/thread_velcro_hlp \
  --dataset-name thread_velcro \
  --fps          50

This writes KHLP files and hlp_manifest.json into the output directory. The manifest path is the main input to the dataloader.

Shard size is chosen for you. A shard has to start on a video keyframe, so by default the packer derives the shard size from the keyframe interval the video was encoded with. Pass --shard-size N only to force a value; it must be a multiple of that interval, and the packer refuses one that is not.

Accepted annotations and quality results stored with the episodes are carried into the pack.

Generate normalisation stats while you pack. Add --stats and the packer also writes norm_stats.json next to hlp_manifest.json: the per-column count, mean, std, min, max and exact 1st/99th percentiles of every numeric stream (state, action, ...), read from every episode. This is the file you normalise state and action with when you train, so you get it in the same step instead of scanning the dataset again later.

bash
knonik pack \
  --input-dir    /home/me/data/out/knonik_thread_velcro \
  --output-dir   /home/me/data/out/thread_velcro_hlp \
  --dataset-name thread_velcro \
  --fps          50 \
  --stats

Already packed without it? knonik stats compute <packed_dir> writes the same file afterwards. See Norms and Stats for the file format, sampling for very large datasets, and normalising batches with it.

Storage Profiles

The packer can store RGB differently depending on the training workload. This is a pack-time choice: you do not need to re-ingest the raw data to try a different storage profile.

--storage-profileBest forTradeoff
compact_video (default)Small storage and sequential accessSparse random access may decode extra frames around the requested one.
training_compressedFast sparse random accessRe-encodes at pack time and is larger than compact_video; see the dataloader guide for the matching loader settings.
bash
knonik pack \
  --input-dir       /datasets/my_dataset_ingested \
  --output-dir      /datasets/my_dataset_compressed \
  --dataset-name    my_dataset \
  --fps             50 \
  --storage-profile training_compressed

training_compressed re-encodes every frame, one CPU core per pack. Raise --workers to build several packs at once; the output is the same for any value.

Packer Options

OptionDefaultMeaning
--input-dirrequiredThe ingested dataset root (the directory holding episode_*).
--output-dirrequiredWhere the KHLP files and hlp_manifest.json are written.
--dataset-name""Name stored in the manifest and in batch metadata.
--fps30FPS stored in the manifest. Set it to your real rate: the dataloader uses it to turn delta_timestamps seconds into frames.
--shard-sizeautoFrames per shard. Auto derives it from the encoded keyframe interval.
--pack-modeshard_batchshard_batch (recommended for training) spreads each episode across packs. standard keeps episodes whole, --hlp-size per pack.
--hlp-size8Whole episodes per pack, standard mode only.
--window-size64Episode shuffle window used while packing.
--seed0RNG seed for deterministic packing.
--storage-profilecompact_videocompact_video or training_compressed.
--workers1Packs built in parallel (shard_batch only).
--include-timestampsoffStore each numeric stream's own per-sample timestamps. Required for datasets ingested with streams at their own rates (section 5a); costs 8 bytes per frame per stream.
--shard-durationfrom ingestSeconds per shard for time-aligned sharding (section 5a). Normally omitted.
--statsoffAlso write norm_stats.json: per-column mean, std, min, max and 1st/99th percentiles of every numeric stream. See Norms and Stats.

Quick Manifest Check

You can inspect the packed manifest without loading the dataset:

bash
python - <<'PY'
import json
from pathlib import Path

data = json.loads(Path("/datasets/my_dataset_compressed/hlp_manifest.json").read_text())
for key in ("dataset", "shard_size", "fps", "pack_mode", "storage_profile", "num_hlps"):
    if key in data:
        print(f"{key}: {data[key]}")
PY

5a. Streams on Different Rates

By default ingest resamples every stream onto one clock: the busiest camera for a ROS source, the shortest stream otherwise. A 200 Hz IMU recorded beside a 10 Hz camera comes out at 10 Hz. That is simple and every loader version can read it, but the dropped samples are gone.

sync_policy in the ingest config decides whether that happens:

ValueBehaviour
anchorDefault. Resample every stream onto one clock.
autoKeep each stream at its own rate when the measured rates actually differ.
nativeAlways keep each stream at its own rate.

Ingest records every stream's measured rate either way, and, where it resampled, how many samples each stream arrived with and how many it kept.

Packing a native dataset needs --include-timestamps. Without each stream's own clock the pack could only describe them all as uniform at --fps, so the packer refuses and tells you the two options: pass --include-timestamps, or re-ingest with sync_policy: "anchor".

Time-aligned sharding (shard_duration_s)

With mixed rates, a sample-count shard size cuts each stream at different instants. Set a shard duration at ingest instead and every stream cuts on the same wall-clock boundaries:

json
{
  "dir_type": "mcap",
  "sync_policy": "native",
  "shard_duration_s": 3.0,
  "gop_duration_s": 1.0
}

shard_duration_s must be a whole number of GOPs (gop_duration_s); the config is rejected otherwise. Packing reads the duration back and adopts it, so the pack command needs no extra flag beyond --include-timestamps.

Pick a duration longer than the widest window your training run asks for (chunk_len at the anchor rate, plus any delta_timestamps span). The dataloader checks this when it starts and tells you if it does not fit.

Carrying topics Knonik cannot decode

Some recordings hold data no reader decodes, such as point clouds or vendor messages. They are skipped by default. To keep them for export, opt in:

yaml
sync_policy: native
carry_blobs: true

They are stored as timestamped opaque bytes with their message type, written back out by export, and never placed in a training batch.

6. Ingest Config

The config tells ingest what your raw dataset looks like: its on-disk layout, which keys hold each camera / state / action stream, and how aggressively to compress them. Pass it with --config (terminal) or as the config= argument (Python). Config files may be written as JSON or YAML.

6.1 Writing a Config For Your Own Dataset

A config is made of a few top-level blocks. At a glance:

BlockRequiredWhat it does
dir_typeyesHow episodes are laid out on disk (selects the reader).
data_typefor episodicThe file format inside each episode directory.
data_diryes¹Path to your raw dataset.
fpsnoDefault frame rate for image/video streams.
metadatanoFree-text dataset name, robot type, and description.
layoutyesMaps source keys → output streams (cameras, state, action, …).
presetnoCompression settings (defaults to medium).

¹ data_dir is optional if you always pass --input, which overrides it.

Step 1 - Pick dir_type

dir_type selects the reader for your dataset's on-disk layout:

dir_typeUse for
lerobot_v2 / lerobot_v3LeRobot datasets.
zarrZarr stores (per-episode or consolidated).
rosbag / mcapROS bag recordings - ROS1 .bag, ROS2 .mcap / .db3, or a ROS2 bag directory. mcap is an alias for the same reader.
rlds / tfrecordRLDS / TFRecord (needs optional dependencies).
d3ilD3IL datasets.
episodicA directory of per-episode files - also set data_type below.
videoDirectories of video files, one episode per video or per group of camera videos (section 6.5).
npy_separateGeneric offline adapter for any other format (section 7).

For episodic, add data_type to say what is inside each episode directory:

data_typeMeaning
hdf5 / npy / zarrRead that file format directly.
lerobot_v2 / lerobot_v3 / rosbag / mcap / rldsRoute to that format reader.

episodic file naming. When reading a format directly, ingest globs data_dir for a fixed pattern - anything named differently is invisible:

data_typeExpects, directly inside data_dir
hdf5episode_*.h5 or episode_*.hdf5
npyepisode_*.npz (one npz archive per episode, holding the arrays)
zarrepisode_<n>/ directories, with an integer <n> - sorted numerically

Episodes are ordered by that glob, so episode_0…episode_9 sort before episode_10 only for zarr; zero-pad your names (episode_000007) if the order matters for HDF5/NPZ.

Step 2 - Map your streams with layout

layout is the heart of the config: it tells ingest which keys in your source data become which output streams. The entry name is the output stream name you choose; the value is the source path in your raw data.

layout keyShapeMaps
images"<name>": {"key": "<source path>", "fps": N}One entry per RGB camera.
numeric"<name>": "<source path>"State / action / qpos / … streams.
depth"<name>": {"key": "<source path>", "fps": N}Depth streams (optional).
timestamps"<source path>"Timestamp stream (optional; omit to use frame index).

Source paths use dot notation to address nested keys:

Source pathConfig key
HDF5 observations/images/top"observations.images.top"
Zarr camera_0/rgb"camera_0.rgb"
Top-level action"action"
ROS topic /camera/rgb/image_raw"/camera/rgb/image_raw"

LeRobot naming. For lerobot_v2 / lerobot_v3, image keys are the bare camera name (e.g. "cam_high", not "observation.images.cam_high"). These readers expose exactly two numeric streams - the primary proprioception column as "state" and the primary command column as "action" - so the values in layout.numeric must be "state" or "action" (the names on the left are yours to choose). Omit layout entirely to take every camera plus state / action as-is.

How much layout each reader uses

layout means slightly different things depending on which reader dir_type selects. This is the single most common source of confusion, so check your row before writing the block:

dir_typeSource keys are…layout behaviour
episodic + hdf5 / npy / zarrdot-paths into the file (observations.images.top)Required. Nothing is ingested unless you map it. Depth key is layout.depth.
zarr (whole-store)dot-paths into the store (camera_0.rgb)Optional but recommended - with a layout the reader addresses named arrays directly and supports any number of numeric streams.
lerobot_v2 / lerobot_v3bare camera names; state / actionOptional. Filters and renames. Omit → all cameras + state + action.
rosbag / mcapauto-derived names from ROS topicsCameras only (layout.images, depth under layout.depths). layout.numeric is ignored - see section 6.2.
rlds / tfrecord / d3ilcamera names from the dataset specOptional. Filters and renames cameras; numeric is state / action.
npy_separatestaged file pathsNot used - use a streams block instead (section 7).

Unknown names are skipped, not errors. For the format readers (everything except episodic and npy_separate), a layout.images entry whose key is not present in the data is silently dropped - you get an episode without that camera rather than a failure. If a stream is missing from the output, check the spelling against episode_000000/metadata.json (see below) before anything else.

Check what you actually got

Every ingested episode records the stream names it wrote. After a short trial run (add "episode_limit": 1 if your dir_type is a format reader, or just point --input at a copy holding one episode), read them back:

bash
python -c "import json;m=json.load(open('OUT/episode_000000/metadata.json'));print(m['rgb_streams'],m['depth_streams'],m['numeric_streams'])"

Those exact names are what you feed to the dataset config and what the dataloader requests, so it is worth doing before you ingest a thousand episodes.

Step 3 - Set compression with preset

Either name a built-in preset ("high", "medium", …) or give an explicit {rgb, depth, numeric} dict. It defaults to medium. See section 8 for every knob.

Putting it together

A minimal episodic-HDF5 config using all of the above:

json
{
  "dir_type": "episodic",
  "data_type": "hdf5",
  "data_dir": "/home/me/data/raw_bimanual",
  "fps": 50,
  "metadata": {
    "dataset": "bimanual_transfer",
    "robot_type": "bimanual",
    "layout": "two camera streams plus state/action"
  },
  "preset": {
    "rgb": {"codec": "vp9", "quality": 18, "gop": 3},
    "depth": {"quantization_mm": 1},
    "numeric": {"level": 1}
  },
  "layout": {
    "images": {
      "cam_high": {"key": "observations.images.cam_high", "fps": 50},
      "cam_left": {"key": "observations.images.cam_left", "fps": 50}
    },
    "numeric": {
      "state": "observations.qpos",
      "action": "action"
    },
    "timestamps": "timestamps"
  }
}

Full field reference

FieldRequiredMeaning
dir_typeyesDataset layout: episodic, lerobot_v2, lerobot_v3, zarr, rosbag, mcap, rlds, tfrecord, d3il, video, or npy_separate.
data_typefor episodicSource format inside an episodic directory: hdf5, npy, or zarr (read directly), or lerobot_v2 / lerobot_v3 / rosbag / mcap / rlds (routed to that format reader).
data_diryes unless --input is usedSource dataset path on the local machine.
presetno (default medium)Compression preset as a dict or a named preset.
preset_overridesnoPer-section overrides deep-merged over a named preset, e.g. {"rgb": {"gop": 15}}.
fpsnoDefault FPS for image/video streams.
episode_limitnoStop after N episodes - for smoke tests. Honoured by the format readers (lerobot_*, zarr, rosbag/mcap, rlds, tfrecord, d3il); ignored by episodic direct reads and npy_separate.
allow_pickleno (default false)episodic + npy only. Set true to load object arrays (ragged arrays, saved Python objects) from the .npz files. Loading one unpickles it, which runs any code inside the file, so set it only for files you trust. Without it, numeric arrays load as normal and an object array stops the ingest with Object arrays cannot be loaded when allow_pickle=False.
metadata.datasetnoDataset name written into metadata.
metadata.robot_typenoFree-text robot identifier.
metadata.layoutnoFree-text description of the streams.
layout.imagesnoRGB image streams.
layout.depthnoDepth streams.
layout.numericnoNumeric streams such as state/action.
layout.timestampsnoTimestamp stream path if available.
layout.langnoWhere each episode's language instruction comes from. LeRobot v2/v3: auto (default), tasks, or task_index. TFRecord/RLDS: the name of the language feature.
languagenoLanguage-instruction control (null=auto, false=skip, or a dict).
sync_policynoanchor (default), auto or native. See section 5a.
shard_duration_s / gop_duration_snoTime-aligned sharding. See section 5a.
videofor videoHow a directory of video files maps to episodes. See section 6.5.

6.2 ROS Bags and MCAP

Use dir_type: "rosbag" (or its alias "mcap") for ROS1 .bag, ROS2 .mcap / .db3 files, or a ROS2 bag directory. ROS does not need to be installed.

data_dir can be a single bag (one episode), or a directory of bags (one episode each), either one bag per subdirectory or bag files side by side.

Streams are created for you from the bag's topics, so you normally write no layout:

  • ▸Image topics become RGB or depth streams, named after the camera (/camera/color/image_raw → camera).
  • ▸Numeric topics (joint states, IMU, odometry, poses, twists, wrenches, trajectories) each become their own numeric stream, named after the full topic (/joint_states → joint_states).
  • ▸Other message types are skipped.

Each bag needs at least one camera topic.

A minimal config:

json
{
  "dir_type": "rosbag",
  "data_dir": "/data/bags",
  "preset": "medium",
  "fps": 30,
  "metadata": {
    "dataset": "moma_pick_place",
    "robot_type": "mobile_manipulator"
  }
}

To keep only some cameras, list them under layout.images (and depth under layout.depths), using the generated camera names as key:

json
"layout": {
  "images": {
    "cam_head":  {"key": "head_zed_left", "fps": 30},
    "cam_wrist": {"key": "wrist_cam",     "fps": 30}
  },
  "depths": {
    "cam_head_depth": {"key": "head_zed", "fps": 30}
  }
}

layout.numeric is not used for ROS bags: every numeric topic is ingested.

Check the generated stream names after a first run with "episode_limit": 1:

bash
python -c "import json;m=json.load(open('/out/episode_000000/metadata.json'));print(m['rgb_streams'],m['depth_streams'],m['numeric_streams'])"

To keep each topic at its own rate instead of resampling to the camera, set "sync_policy": "native" (see section 5a).

6.3 Examples

Complete, working configs for the common source families.

Episodic HDF5 - ALOHA bimanual. A directory of per-episode HDF5 files: one top camera, plus qpos, qvel, and action numeric streams nested under observations. Note how each layout.numeric entry renames a source path to a clean output stream name:

json
{
  "dir_type": "episodic",
  "data_type": "hdf5",
  "preset": {
    "rgb":     {"codec": "vp9", "quality": 15, "gop": 3},
    "depth":   {"quantization_mm": 1},
    "numeric": {"level": 1}
  },
  "fps": 50,
  "data_dir": "/data/input",

  "metadata": {
    "dataset": "bimanual_transfer",
    "robot_type": "aloha_bimanual",
    "layout": "qpos(14) + qvel(14) + action(14) + cam_top"
  },

  "layout": {
    "images": {
      "top": {"key": "observations.images.top", "fps": 50}
    },

    "numeric": {
      "qpos":    "observations.qpos",
      "qvel":    "observations.qvel",
      "actions": "action"
    }
  }
}

LeRobot v3 - four cameras. A LeRobot v3 dataset with four cameras and state/action. Because this is a LeRobot reader, the image keys are the bare camera names and the primary proprioception/command columns use the logical state / action names; a timestamp stream is also mapped. A dataset carrying extra columns would name them directly - "qvel": "observation.qvel" - or drop layout.numeric to take every numeric column as-is:

json
{
  "dir_type": "lerobot_v3",
  "preset": {
    "rgb":     {"codec": "vp9", "quality": 15, "gop": 30},
    "depth":   {"quantization_mm": 1},
    "numeric": {"level": 1}
  },
  "fps": 50,
  "data_dir": "/data/input",

  "metadata": {
    "dataset": "thread_velcro",
    "robot_type": "unknown",
    "layout": "state(14) + action(14) + cam_high + cam_low + cam_left_wrist + cam_right_wrist"
  },

  "layout": {
    "images": {
      "cam_high":        {"key": "cam_high",        "fps": 50},
      "cam_low":         {"key": "cam_low",          "fps": 50},
      "cam_left_wrist":  {"key": "cam_left_wrist",   "fps": 50},
      "cam_right_wrist": {"key": "cam_right_wrist",  "fps": 50}
    },

    "numeric": {
      "state":  "state",
      "action": "action"
    },

    "timestamps": "timestamp"
  }
}

Episodic Zarr - per-episode stores. A directory of per-episode Zarr stores. Source paths are dot-separated group paths inside the store, so the nested array camera_0/rgb is written "camera_0.rgb". Four numeric arrays are mapped one-to-one:

json
{
  "dir_type": "episodic",
  "data_type": "zarr",
  "data_dir": "/data/pickNplace",
  "preset": "high",

  "metadata": {
    "dataset": "pickNplace",
    "robot_type": "dexterous_hand",
    "layout": "hand_action + pose + proprioception + fsr + camera_0"
  },

  "layout": {
    "images": {
      "camera_0": {"key": "camera_0.rgb", "fps": 30}
    },
    "numeric": {
      "hand_action":    "hand_action",
      "pose":           "pose",
      "proprioception": "proprioception",
      "fsr":            "fsr"
    }
  }
}

Episodic NPY - CALVIN-style, with depth. Per-episode .npy files, two RGB cameras and two depth cameras. Note that the episodic reader spells depth layout.depth (singular), and that preset: "ultra_low" is a near-lossless choice for iterating on a small slice:

json
{
  "dir_type": "episodic",
  "data_type": "npy",
  "data_dir": "/data/calvin",
  "preset": "ultra_low",

  "metadata": {
    "dataset": "calvin_debug",
    "layout": "actions + rel_actions + robot_obs + scene_obs, 2 rgb + 2 depth"
  },

  "layout": {
    "images": {
      "rgb_static":  {"key": "rgb_static",  "fps": 30},
      "rgb_gripper": {"key": "rgb_gripper", "fps": 30}
    },
    "depth": {
      "depth_static":  {"key": "depth_static",  "fps": 30},
      "depth_gripper": {"key": "depth_gripper", "fps": 30}
    },
    "numeric": {
      "actions":     "actions",
      "rel_actions": "rel_actions",
      "robot_obs":   "robot_obs",
      "scene_obs":   "scene_obs"
    }
  }
}

ROS bag / MCAP. See section 6.2 - these need no layout at all.

6.4 Troubleshooting A Config

SymptomCauseFix
A camera or numeric stream is missing from the outputFor format readers, a layout key that doesn't exist is silently skippedCompare against episode_000000/metadata.json (rgb_streams / numeric_streams) from a 1-episode run
episodic run produces empty episodeslayout is required for episodic - nothing is ingested unless mappedAdd layout.images / layout.numeric with dot-path keys
No episodes at all from a ROS bagThe bag has no decodable camera topic, so there is no frame clockCheck the bag has an Image / CompressedImage topic in a supported encoding
No ROS bags found at …data_dir is one level offPoint it at the bag, or at the parent holding one bag per subdirectory
Depth ingested but emptyDepth filter key is layout.depth for episodic, layout.depths for format readersUse the spelling for your dir_type
Streams present but frame counts differEpisode length is the minimum across streamsAlign your streams, or accept the truncation
An episodic dataset ingests zero episodesFiles don't match the expected episode_* glob for that data_typeRename to episode_*.h5 / episode_*.npz / episode_<n>/
Ingest is slow on a first lookFull-quality preset over every episodeUse "preset": "low", plus "episode_limit": 2 on the format readers
Ingest of long or high-resolution video is slowEvery frame is decoded and re-encodedUse "codec": "copy" where the reader supports it (section 8)

6.5 Directories of Video Files

For datasets that are only recordings, such as egocentric captures, factory cameras or phone footage, each video (or each group of camera videos) is one episode. You describe the folder layout with a path pattern:

json
{
  "dir_type": "video",
  "data_dir": "/data/ego/factory001_worker001_part00",
  "preset": "medium",
  "preset_overrides": {"rgb": {"codec": "copy"}},
  "metadata": {"dataset": "ego_factory"},
  "video": {
    "pattern": "factory{factory}_worker{worker}_{clip}.mp4",
    "camera": "ego",
    "episode_id": "factory{factory}_worker{worker}_{clip}",
    "sidecar": "{stem}.json"
  }
}

pattern is a path relative to data_dir:

TokenMatchesCaptured
{name}characters inside a single folder or file nameyes, into episode metadata as name
*any characters inside one folder or file nameno
**any number of folders, including noneno
?one characterno

A name used twice in one pattern must match the same text both times ({task}/{task}_{n}.mp4).

Two capture names are special:

  • ▸{camera} names the stream a file belongs to. Files whose other captures all match form one multi-camera episode, so both {episode}/{camera}.mp4 and {camera}/{episode}.mp4 work. Without {camera}, every file has one stream named by camera (default "video").
  • ▸{episode} is just the natural name for the identifying part of the path.

All video options:

OptionDefaultMeaning
pattern**/{episode}.*Which files are episodes and what to capture from their paths.
camera"video"Stream name when the pattern has no {camera}.
episode_idall captures except {camera}, joined with /Template for the episode id. Two episodes with the same id are refused.
sidecarnoneTemplate for a per-episode .json/.yaml file whose top-level keys are added to the episode's metadata. Can use {stem} and {dir}. A missing sidecar is skipped.
sidecar_requiredfalseFail if an episode's sidecar does not exist.
languagenoneTemplate giving the episode's instruction, e.g. "{task}".
extensionscommon video suffixesWhich file suffixes count as video.
resizenone[width, height] to downscale decoded frames. Not allowed with "codec": "copy".
anchorfirst camera alphabeticallyThe camera whose clock the episode follows when cameras run at different rates.
require_all_camerastrueSkip (with a warning) episodes missing a camera other episodes have.

Each frame's timestamp comes from the video itself, so variable-frame-rate recordings keep their real timing. Audio is not ingested.

For long or high-resolution recordings use "codec": "copy" (see section 8): a copy takes seconds where a re-encode takes a long time, and decodes to exactly the source frames.

Known limitation: H.264 sources encoded with B-frames (the default for most phone and camera footage) can be copied at ingest but are not yet accepted by the packer. Re-encode those sources (any rgb codec other than copy) for now.

Quality check: the automatic quality check in Knonik Standard covers teleoperated robot data. Quality checking for egocentric video is coming with Knonik Hub. You can still visualize and manually annotate video datasets in knonik viz.

7. Converting Any Format Into Knonik

When no built-in reader recognizes your dataset, you convert it yourself with one of two generic adapters. Both feed the same ingest engine as the built-in readers, so the compressed episodes and KHLP shards they produce are identical in every way - you are only responsible for handing Knonik the raw arrays.

  • ▸Offline adapter (dir_type: "npy_separate") - you first write each stream to disk as .npy files, then run a normal ingest over that staged directory. Best when the data already fits on disk and you want a simple, re-runnable step.
  • ▸Streaming adapter (live ingest) - you push frames into ingest one at a time as plain numpy arrays, with no staging. Best when data arrives serially, when you have many episodes, or when staging the whole dataset first is impractical.

Whichever you use, the frame contract is the same:

StreamdtypeShape (per frame)Notes
RGBuint8(H, W, 3)One image per frame.
Depthfloat32(H, W)Metres. Optional.
Numericfloat32(D,)State / action / qpos / … one vector per frame.
Timestampsfloat64scalar per frameEpoch seconds. Optional - omit to use the frame index.

The number of frames ingested for an episode is the minimum length across all of its streams, so make sure your streams are aligned before you ingest.

Offline adapter - stage streams as .npy

Stage each stream on disk, then point an npy_separate config at the staged files. RGB and depth streams are a directory of per-frame files named with a printf-style pattern (indices from 0); numeric streams are a single (T, D) array; timestamps are a single (T,) array.

The script below reads one episode from your own format, stages it, and ingests it. Replace read_my_episode with your loader - everything else is generic:

python
import numpy as np
from pathlib import Path
from knonik.ingest import run

STAGE = Path("/home/me/staged/episode_0")
OUT   = "/home/me/data/out/my_custom_dataset"
FPS   = 30

# 1. Read one episode from your own format. Return aligned arrays:
#      rgb:    uint8   (T, H, W, 3)
#      state:  float32 (T, state_dim)
#      action: float32 (T, action_dim)
#      ts:     float64 (T,)   epoch seconds   (optional)
def read_my_episode(src):
    ...  # your code here
    return {"rgb": rgb, "state": state, "action": action, "ts": ts}

ep = read_my_episode("/raw/episode_0")

# 2. Stage each stream as .npy.
(STAGE / "cam_top").mkdir(parents=True, exist_ok=True)
for i, frame in enumerate(ep["rgb"]):                     # RGB: one file per frame
    np.save(STAGE / "cam_top" / f"frame_{i:06d}.npy", frame.astype(np.uint8))
np.save(STAGE / "state.npy",      ep["state"].astype(np.float32))    # numeric: (T, D)
np.save(STAGE / "action.npy",     ep["action"].astype(np.float32))
np.save(STAGE / "timestamps.npy", ep["ts"].astype(np.float64))      # optional

# 3. Describe the staged layout with an npy_separate config.
config = {
    "dir_type": "npy_separate",
    "metadata": {"dataset": "my_custom_dataset"},
    "timestamps": str(STAGE / "timestamps.npy"),          # optional
    "streams": {
        "rgb": {
            "cam_top": {"dir": str(STAGE / "cam_top"),
                        "pattern": "frame_%06d.npy", "fps": FPS},
        },
        "numeric": {
            "state":  {"path": str(STAGE / "state.npy")},
            "action": {"path": str(STAGE / "action.npy")},
        },
        # "depth": {"cam_top_depth": {"dir": ..., "pattern": ..., "fps": FPS}},
    },
}

# 4. Ingest the staged episode.
run(config=config, output=OUT)

Notes:

  • ▸Use a streams block here, not layout - npy_separate reads staged files directly rather than mapping source keys.
  • ▸numeric entries take an optional chunk_len (e.g. {"path": ..., "chunk_len": 128}) to control on-disk chunking of the array.
  • ▸Each run(...) ingests one episode. For a multi-episode dataset, prefer the streaming adapter below - it writes many episodes into a single output directory in one pass, with no staging.

Streaming adapter - push frames live (no staging)

When you have many episodes, or data that arrives serially, skip staging and push frames straight in with the in-process live_session API. You register each stream once, then, for every episode, open an episode(...) block and push frames in order. This uses the same engine as offline ingest.

python
import numpy as np
from pathlib import Path
from knonik.ingest import live_session

OUT = "/home/me/data/out/my_custom_dataset"
FPS = 30

# Your own reader: yield one episode at a time from your format.
def my_episodes():
    for path in sorted(Path("/raw").glob("*.myfmt")):
        yield load_my_episode(path)   # -> {"task", "rgb", "state", "action", "ts"}

with live_session(output=OUT, preset="high") as ses:
    # Register every stream once, before the first episode.
    ses.register_rgb("cam_top", fps=FPS)
    ses.register_numeric("state",  dim=14)
    ses.register_numeric("action", dim=14)

    for ep in my_episodes():
        with ses.episode(metadata={"task": ep["task"]}):
            for t in range(len(ep["action"])):
                ts = ep["ts"][t]                                      # epoch seconds
                ses.rgb("cam_top",  ep["rgb"][t],    timestamp=ts)    # uint8   (H, W, 3)
                ses.numeric("state",  ep["state"][t],  timestamp=ts)  # float32 (14,)
                ses.numeric("action", ep["action"][t], timestamp=ts)  # float32 (14,)
  • ▸ses.episode(...) finalizes the episode on a clean exit and discards it on an exception, so a crashed episode is never half-written (and is not charged).
  • ▸Depth works the same way: ses.register_depth("cam_top_depth", fps=FPS) then ses.depth("cam_top_depth", depth_m, timestamp=ts) (metres, float32).
  • ▸Arrays are coerced to the expected dtype and contiguity for you.
  • ▸preset takes the same forms as offline ingest (a named preset, an inline {rgb, depth, numeric} dict, or omitted → medium); see section 8.

If your producer is not Python (for example a C++/ROS controller), drive the same streaming path over the cross-process stdin protocol instead - see section 10.

8. Compression Presets

Recommended explicit preset:

json
{
  "rgb": {"codec": "vp9", "quality": 18, "gop": 3},
  "depth": {"quantization_mm": 1},
  "numeric": {"level": 1}
}

Common knobs:

BlockFieldMeaning
rgbcodecvp9, av1, ffv1, or copy (below).
rgbqualityLower means higher quality and larger files.
rgbgopSmaller GOP improves random access but increases size.
depthquantization_mmDepth quantization in millimetres. 0 means lossless.
numericlevelNumeric compression level.

Pack-time profiles are separate from ingest presets. The ingest preset controls the intermediate episode files. storage_profile controls how those ingested episodes are rewritten into KHLP shards for training.

Named presets

Instead of a dict you can name a built-in preset (preset defaults to medium if omitted):

json
"preset": "high"
NameRGB codecRGB CRFGOPDepthNumericUse when
ultraav140605 mm5Final archive, smallest size.
highvp936452 mm4Standard production (recommended).
mediumvp932301 mm3Balanced; default, and the default for live.
lowvp928151 mm1Fast iteration during development.
ultra_lowvp91531 mm1Near-lossless, very large.
losslessffv1-300 mm1Strictly lossless, very large.
decode_friendlyvp93211 mm3Every frame is a keyframe: ~3-5× faster RGB decode at training time for ~2-3× more storage. Good for read-heavy training on cheap local NVMe.

Add preset_overrides to tweak a named preset, e.g.:

json
"preset": "high",
"preset_overrides": { "rgb": { "gop": 15 } }

Named presets, inline preset dicts, and preset_overrides all work for both offline and live ingest (see section 10).

Copying the source video instead of re-encoding it

If the source video is already what you want to train on, ingest can copy its encoded video into each episode instead of decoding and re-encoding every frame:

json
"preset": "medium",
"preset_overrides": {"rgb": {"codec": "copy"}}

Re-encoding is nearly all of ingest's time, so copying is typically orders of magnitude faster. It also adds no generation loss: the episode decodes to the same pixels as the source.

quality and gop do not apply: the keyframes are wherever the source put them, and the packer derives the shard size from them. If you prefer a fixed keyframe interval, pack with --storage-profile training_compressed, which re-encodes at pack time.

Copy mode refuses, by name, anything it cannot do exactly:

  • ▸Readers: lerobot_v3 and video only.
  • ▸Keyframes: each episode must start on a keyframe in its source file.
  • ▸Contiguous frames: each camera's frames must be one consecutive run in one file.
  • ▸Sync policy: sync_policy: "anchor" only.
  • ▸Time-aligned sharding: shard_duration_s is not supported with a copy.

9. Python API

Use the public wrapper API from knonik.ingest.

Offline ingest

python
from knonik.ingest import run

run(
    config="/home/me/configs/config_lerobot_v3.json",
    input="/home/me/data/thread_velcro",
    output="/home/me/data/out/knonik_thread_velcro",
    force_config=False,   # True to overwrite an existing dataset config.json
)

The run writes <output>/config.json - the dataset config described in Quality & Annotation §6 - when it finishes. force_config is the API equivalent of --force-config; leave it at False and an existing config is kept.

You can also pass a config dictionary:

python
from knonik.ingest import run

config = {
    "dir_type": "lerobot_v3",
    "data_dir": "/home/me/data/thread_velcro",
    "preset": {
        "rgb": {"codec": "vp9", "quality": 18, "gop": 3},
        "depth": {"quantization_mm": 1},
        "numeric": {"level": 1}
    },
    "layout": {
        "images": {
            # LeRobot camera keys are the bare name; the reader strips the
            # "observation.images." prefix automatically.
            "cam_high": {"key": "cam_high", "fps": 30}
        },
        "numeric": {
            # The main proprioception/command columns are exposed as
            # "state" / "action"; any other numeric column keeps its own
            # name, e.g. "qvel": "observation.qvel".
            "state": "state",
            "action": "action"
        }
    }
}

run(config=config, output="/home/me/data/out/knonik_thread_velcro")

Pack

python
from knonik.ingest import pack

paths = pack(
    input_dir="/home/me/data/out/knonik_thread_velcro",
    output_dir="/home/me/data/out/thread_velcro_hlp",
    dataset_name="thread_velcro",
    window_size=64,
    fps=50,
    seed=0,
    pack_mode="shard_batch",
)

print(paths)

pack(...) takes the same options as knonik pack, as keyword arguments: shard_size (default 0 = derived from the keyframe interval), hlp_size, storage_profile, include_timestamps, shard_duration_s, workers and stats (see Norms and Stats).

Pass stats=True to get normalisation stats with the pack. pack(..., stats=True) writes norm_stats.json beside the manifest once the packs are built, exactly as knonik pack --stats does. Read it back with knonik.stats.load(output_dir). See Norms and Stats.

Pack with a storage profile

pack(...) takes an optional storage_profile ("compact_video" default, or "training_compressed"). The codec/quality/format internals for each profile are chosen automatically - there is nothing else to configure:

python
from knonik.ingest import pack

paths = pack(
    input_dir="/datasets/my_dataset_ingested",
    output_dir="/datasets/my_dataset_compressed",
    dataset_name="my_dataset",
    window_size=64,
    fps=50,
    seed=0,
    pack_mode="shard_batch",
    storage_profile="training_compressed",
)

Live ingest

For a Python producer, drive ingest directly with live_session. This uses the same engine as offline ingest, fed frame-by-frame as numpy arrays - no stdin protocol and no .npy staging:

python
from knonik.ingest import live_session

with live_session(output="/home/me/data/live_out", preset="high") as ses:
    ses.register_rgb("cam_top", fps=30)        # register each stream once,
    ses.register_numeric("action", dim=7)      # before the first episode
    for _ in range(num_episodes):
        with ses.episode(metadata={"task": "pick_and_place"}):
            for t in range(episode_length):
                ses.rgb("cam_top", capture_rgb(), timestamp=t / 30)     # uint8 (H, W, 3)
                ses.numeric("action", get_action(), timestamp=t / 30)   # float32 (7,)
  • ▸

    preset accepts the same forms as offline ingest: a named preset, an inline {rgb, depth, numeric} dict, or omitted (→ medium); pass preset_overrides=... to tweak a named preset.

  • ▸

    register_numeric also takes role= ("action" or "state") and channel_names=[...]. You are the source of truth for a live capture, so anything you declare here is written straight into the dataset config at the end of the run instead of coming back to you as a question. Pass them only when they are true of the data you push:

    python
    ses.register_numeric("action", dim=7, role="action",
                         channel_names=["j1","j2","j3","j4","j5","j6","gripper"])
    
  • ▸

    live_session(..., force_config=True) overwrites an existing dataset config.json in the output directory; the default leaves it alone.

  • ▸

    ses.episode(...) calls start on enter, end on success, and abort on error (a discarded episode is not written and charges nothing).

  • ▸

    Depth works the same way: ses.register_depth("cam_top_depth", fps=30) then ses.depth("cam_top_depth", depth_m, timestamp=...) (metres, float32).

  • ▸

    Arrays are coerced to the expected dtype/contiguity for you.

Live ingest (stdin protocol)

run_live runs the cross-process JSON protocol, reading commands from the current process's stdin. Use it when a non-Python program drives ingest; otherwise prefer live_session above.

python
from knonik.ingest import run_live

run_live(
    config="/home/me/configs/live_config.json",
    output="/home/me/data/live_out",
)

10. Live Ingest From Terminal (stdin protocol)

Live mode reads the Knonik live protocol from stdin:

bash
knonik ingest live \
  --config /path/to/live_config.json \
  --output /path/to/live_output

This is the cross-process path: a separate producer (often non-Python, e.g. a C++/ROS controller) writes newline-delimited JSON commands to stdin, and frame payloads are staged as .npy files and referenced by path. If your producer is Python, prefer the in-process live_session API instead - it avoids the JSON protocol and the .npy staging entirely.

A minimal live config:

json
{
  "output_dir": "/path/to/live_output",
  "preset": "medium"
}

Important points:

  • ▸Keep stdin open while streaming. Closing stdin ends the session (any open episode is finalized first).
  • ▸Register streams after start, at the beginning of each episode (streams are bound to the episode being written), then push frames, then end. Repeat the start → register → push → end cycle for each episode.
  • ▸Write each frame's .npy file to disk before sending the command that references it.
  • ▸Use local filesystem paths, not Docker mount paths.
  • ▸preset accepts the same forms as offline ingest: a named string ("high", "medium", …), an inline {rgb, depth, numeric} dict, or omitted (defaults to medium), plus optional preset_overrides.
  • ▸output_dir is required in the config; --output overrides it.

Live ingest is also the streaming generic adapter for unrecognized formats: read your data one frame at a time in your own script and push each frame in. From Python, the in-process live_session API does this with plain numpy arrays; non-Python producers use the protocol below. See section 7.

Live Protocol Reference

The agent reads one JSON object per line from stdin and writes one JSON response per line to stdout. Every response is either {"ok": true} or {"ok": false, "error": "<message>"}.

Commands

CommandRequired fieldsDescription
register_rgbcmd, nameRegister an RGB stream.
register_depthcmd, nameRegister a depth stream.
register_numericcmd, name, dimRegister a numeric stream. dim is an int, or a list for multi-dim vectors.
startcmdBegin a new episode.
rgbcmd, name, pathSubmit one RGB frame (path → a .npy file).
depthcmd, name, pathSubmit one depth frame.
numericcmd, name, pathSubmit one numeric vector.
endcmdFinalize and persist the current episode.
exitcmdFinalize any open episode and shut down cleanly.

If timestamp is omitted, the frame index is used as the timestamp.

Lifecycle

text
start  →  register_* (each stream)  →  rgb / depth / numeric × N  →  end
  ↓
start  →  register_*  →  …  →  end          (repeat for more episodes)
  ↓
exit

Driving live ingest from Python

python
import json, os, subprocess
import numpy as np

os.makedirs("/tmp/knonik_frames", exist_ok=True)

proc = subprocess.Popen(
    ["knonik", "ingest", "live",
     "--config", "/path/to/live_config.json",
     "--output", "/path/to/live_output"],
    stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True,
)

def send(cmd):
    proc.stdin.write(json.dumps(cmd) + "\n")
    proc.stdin.flush()
    return json.loads(proc.stdout.readline())

for ep in range(num_episodes):
    assert send({"cmd": "start", "metadata": {"task": "pick_and_place"}})["ok"]
    # Register streams after start, at the beginning of each episode.
    assert send({"cmd": "register_rgb",     "name": "cam_top", "fps": 30})["ok"]
    assert send({"cmd": "register_numeric", "name": "action",  "dim": 7})["ok"]
    for t in range(episode_length):
        ts = t / 30.0

        p = f"/tmp/knonik_frames/rgb_{t:04d}.npy"
        np.save(p, capture_rgb())            # uint8 (H, W, 3)
        send({"cmd": "rgb", "name": "cam_top", "path": p, "timestamp": ts})

        p = f"/tmp/knonik_frames/action_{t:04d}.npy"
        np.save(p, get_action())             # float32 (7,)
        send({"cmd": "numeric", "name": "action", "path": p, "timestamp": ts})
    assert send({"cmd": "end"})["ok"]

send({"cmd": "exit"})
proc.stdin.close()
proc.wait()

The in-process variant knonik.ingest.run_live(config, output) runs the same protocol but reads from the current process's stdin - handy when another program pipes commands into your Python process.

11. Output Layout

Offline ingest writes one directory per episode:

text
knonik_thread_velcro/
  config.json                   (dataset config - see Quality & Annotation §6)
  episode_000000/
    metadata.json
    rgb_<stream>.webm           (one per RGB stream)
    depth_<stream>.hdf5         (one per depth stream, if any)
    <numeric_stream>/           (Zarr v2 array, shape [T, D], float32)
    <numeric_stream>_time/      (Zarr v2 array, shape [T], float64 epoch seconds)
    annotations/                (language annotations, if enabled - see below)
  episode_000001/
    ...

metadata.json records the dataset name, robot type, source format, episode id, the RGB/depth/numeric stream names, start/end time, and episode_length. It also carries what the dataset config generator needs: stream_params (the encoder and compressor settings each stream was written with), stream_roles when the source format declared which stream is the action, channel_names when the source declared per-channel labels, and urdf_joints when a ROS bag recorded /robot_description. Read a numeric stream with Zarr:

python
import zarr
action = zarr.open("knonik_thread_velcro/episode_000000/action", mode="r")
print(action.shape, action[:5])

Language annotations. Format-reader ingests also write per-episode files under episode_<n>/annotations/language/ (episode.yaml, rephrased.yaml, timestamps.yaml). The instruction comes from the dataset, the language config block, or metadata.language_instruction. Set language: false to skip, or pass a dict like {"instruction": "pick up the cube", "rephrases": [...]} to supply one when the dataset has none.

Packing writes KHLP shards and a manifest:

text
knonik_thread_velcro_hlp/
  hlp_000000.khlp
  hlp_000001.khlp
  hlp_manifest.json

Use hlp_manifest.json with the Knonik multidataloader.