# Video SDK

  Load, slice, and batch video data in Python with NumPy-style indexing. Every
  operation is lazy — nothing is decoded until you actually access pixels, so
  slicing an hour of footage costs nothing.

> **Note:** **Before you begin** — `pip install dreamlake` for this Python SDK. The
>   `dreamlake` CLI is a separate native binary
>   ([install it here](/index.md#install)); use it to authenticate with
>   `dreamlake login`, which the SDK then reuses. Video ids come from
>   `dreamlake list` or the dashboard.

## Load

```python
import dreamlake as dl

video = dl.load_video("v-BV1bW411n7fY9x01")
print(video.fps, video.duration, video.width, video.height)
```

## Slice

`float` = time (seconds), `int` = frame number. Returns a lazy `Video`.

```python
clip = video[10.0:20.0]       # 10s clip
frame = video[42]              # frame 42
sub = clip[2.0:5.0]           # sub-slice → Video(st=12.0, et=15.0)
```

## Access Frames

```python
video[0].image                 # PIL Image
video[0].numpy()               # (H, W, 3)
clip.numpy()                   # (N, H, W, 3)
clip.tensor()                  # (N, C, H, W) torch tensor
video.thumbnail                # middle frame
```

## Chunk & Batch

```python
chunks = video[0.0:2.0].chunk(0.200)   # VideoArray of 10 × 200ms
chunks[:, 0].numpy()                     # first frame of each → (10, H, W, 3)
chunks[:, 0].tensor()                    # feed to model
```

## TextTrack

Buffer time-aligned text entries, flush to server:

```python
track = dl.text_track(prefix="/run-042/captions", project="robotics@alice")
track.add("Robot picks up cup", source=clip)
track.flush()
```

## VectorIndex

Store and search embeddings:

```python
index = dl.vec_index("my-experiment")
index.add(vector=enc(clip[0]), caption="robot arm", source=clip)
results = index.search("robot picking up cup", limit=10)
```

## Prefix Context

```python
with dl.Prefix(project="robotics@alice", prefix="/2026/04/run-042"):
    dl.upload("./video.mp4", path="camera/front")
    track = dl.text_track(path="captions/llava")
```

## Next steps

    Vectorize the clips you just sliced and query them with natural language.

    Upload and organize the episodes the SDK loads from.
