This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 32a6d3220a [docs] Complete video frame storage guide (#11087)
32a6d3220a is described below

commit 32a6d3220a4b040c117c8132fff3b557e03a9537
Author: Jingsong Lee <[email protected]>
AuthorDate: Wed Nov 11 13:43:29 2026 +0800

    [docs] Complete video frame storage guide (#11087)
---
 docs/docs/multimodal-table/video.mdx      | 252 ++++++++++++++++++++++++++++--
 docs/static/img/multimodal-video-read.svg |  91 +++++++++++
 2 files changed, 332 insertions(+), 11 deletions(-)

diff --git a/docs/docs/multimodal-table/video.mdx 
b/docs/docs/multimodal-table/video.mdx
index 35a5bbf693..26c7582626 100644
--- a/docs/docs/multimodal-table/video.mdx
+++ b/docs/docs/multimodal-table/video.mdx
@@ -34,11 +34,16 @@ independent image, audio clip, or binary object.
 
 ## Create a Video Table
 
-Use `video-frame-field` when the logical table has one row per frame while the 
physical storage
-and decoding unit is a complete encoded video. The comma-separated option also 
marks each named
-SQL `BYTES` or `BINARY` column as a BLOB column. It selects the dedicated 
`.video` format; the
+Use `video-frame-field` on a [Data Evolution append table](./data-evolution) 
when the logical
+table has one row per frame while the physical payload is a complete encoded 
video.
+The comma-separated option also marks each named SQL `BYTES` or `BINARY` 
column as a BLOB
+column. It selects the dedicated `.video` format; the
 ordinary `.blob` version and layout are not changed.
 
+The examples use two cameras with aligned frame rows. `frame_index` is an 
application column
+for ordering rows within an episode; the video descriptor independently 
records which frame
+to decode. Keep timestamps in another ordinary column if the application needs 
them.
+
 <Tabs groupId="video-create">
 
 <TabItem value="flink" label="Flink SQL">
@@ -46,6 +51,7 @@ ordinary `.blob` version and layout are not changed.
 ```sql
 CREATE TABLE video_frames (
     episode_id BIGINT,
+    frame_index BIGINT,
     camera_front BYTES,
     camera_wrist BYTES
 ) WITH (
@@ -62,6 +68,7 @@ CREATE TABLE video_frames (
 ```sql
 CREATE TABLE video_frames (
     episode_id BIGINT,
+    frame_index BIGINT,
     camera_front BINARY,
     camera_wrist BINARY
 ) TBLPROPERTIES (
@@ -73,11 +80,150 @@ CREATE TABLE video_frames (
 
 </TabItem>
 
+<TabItem value="python" label="PyPaimon">
+
+Use Python 3.10 or newer and a PyPaimon build matching this documentation 
version,
+including its `.video` format and decoding APIs. To run the complete 
walkthrough from
+a matching source checkout, install from the repository root before starting 
Python:
+
+```shell
+python -m pip install -e './paimon-python[torch,video]'
+```
+
+This installs the PyTorch and video extras used by the decoding example below.
+
+```python
+import pyarrow as pa
+import pypaimon.multimodal as pm
+
+conn = pm.connect(options={"warehouse": "file:///tmp/video_lake"})
+frames = conn.create_table(
+    "video_frames",
+    schema=pa.schema([
+        pa.field("episode_id", pa.int64()),
+        pa.field("frame_index", pa.int64()),
+        pa.field("camera_front", pa.large_binary()),
+        pa.field("camera_wrist", pa.large_binary()),
+    ]),
+    options={"video-frame-field": "camera_front,camera_wrist"},
+)
+```
+
+The multimodal API enables row tracking and Data Evolution by default. When 
opening a table
+created with SQL, use `frames = conn.get_table("video_frames")` and connect to 
its catalog
+and database.
+
+</TabItem>
+
 </Tabs>
 
-Creating the table does not ingest or decode video files. Use the
-[PyPaimon video ingestion API](../pypaimon/video#video-frame-storage)
-to write complete videos and their logical frame rows.
+Creating the table does not ingest or decode video files.
+
+## Write Videos with PyPaimon
+
+Continue with `frames` from the PyPaimon example above. Suppose episode 42 has 
two aligned
+videos, each containing 120 frames in presentation order:
+
+```python
+frame_rows = [{"episode_id": 42, "frame_index": i} for i in range(120)]
+frames.add_video(
+    pm.Blob.from_local("/data/episode-42-front.mp4"),
+    frame_rows,
+    video_column="camera_front",
+    first_frame=0,
+)
+```
+
+`add_video()` appends 120 rows and assigns consecutive video frame ordinals 
starting at
+`first_frame`. It copies the complete encoded video into `.video` storage 
without decoding
+or re-encoding it. Consecutive frame rows share that payload inside the pack; 
they do not
+store 120 copies of the MP4. With explicit `frame_rows`, the caller must 
supply a valid
+frame count and frame ordinals for the source video. `camera_wrist` is 
initially `NULL`.
+
+Fill the second camera on those same rows with `replace_video()`:
+
+```python
+frames.replace_video(
+    where="episode_id = 42",
+    video=pm.Blob.from_local("/data/episode-42-wrist.mp4"),
+    video_column="camera_wrist",
+    first_frame=0,
+)
+```
+
+Matching rows are ordered by `_ROW_ID` and receive consecutive frame ordinals. 
This writes
+only the wrist-camera column, retaining the front video and ordinary columns. 
Each call
+commits separately. A second `add_video()` would append another set of rows; 
use
+`replace_video()` to populate or replace a camera on existing rows. The 
`video_column`
+argument is required when the table configures multiple video fields.
+
+For multiple episodes, `add_videos()` keeps one writer and commit open across 
its inputs,
+allowing several complete videos to share a pack. For automatic frame counting 
and timestamp
+generation, use a schema with `frame_index` and `timestamp` columns as shown 
in the
+[automatic video import API](../pypaimon/video#import-a-video). That path 
inspects the video
+with PyAV; the explicit-frame example above does not require a decoder.
+
+## Add a Video Column
+
+Use the `__VIDEO_FRAME_FIELD` comment directive to add a nullable video column 
to an
+existing [Data Evolution append table](./data-evolution). The table must 
already have
+`row-tracking.enabled=true` and `data-evolution.enabled=true`, no primary key, 
and
+`bucket=-1`.
+
+The directive converts the declared `BYTES` or `BINARY` type to scalar `BLOB` 
and
+automatically appends the new column to `video-frame-field`, preserving 
existing video
+fields. Text after `;` is stored as the column comment. Existing rows read 
`NULL` in
+the new column; adding it does not ingest videos or backfill frame values.
+
+The examples below add `camera_side` to the `video_frames` table created above.
+Point the PyPaimon connection at the same warehouse and database as that table.
+
+<Tabs groupId="video-add-column">
+
+<TabItem value="flink" label="Flink SQL">
+
+```sql
+ALTER TABLE video_frames
+    ADD camera_side BYTES COMMENT '__VIDEO_FRAME_FIELD; side camera frame';
+```
+
+</TabItem>
+
+<TabItem value="spark" label="Spark SQL">
+
+```sql
+ALTER TABLE video_frames
+    ADD COLUMN camera_side BINARY COMMENT '__VIDEO_FRAME_FIELD; side camera 
frame';
+```
+
+</TabItem>
+
+<TabItem value="python" label="PyPaimon">
+
+```python
+import pypaimon.multimodal as pm
+from pypaimon.schema.data_types import AtomicType
+from pypaimon.schema.schema_change import SchemaChange
+
+conn = pm.connect(options={"warehouse": "file:///tmp/video_lake"})
+conn.catalog.alter_table("default.video_frames", [
+    SchemaChange.add_column(
+        "camera_side", AtomicType("BYTES"),
+        "__VIDEO_FRAME_FIELD; side camera frame",
+    ),
+])
+# Reload the table to use the new schema.
+frames = conn.get_table("video_frames")
+```
+
+</TabItem>
+
+</Tabs>
+
+Changing an existing column's comment or directly setting `video-frame-field` 
cannot
+convert an ordinary BLOB column to video storage. Add a new column with the 
directive
+instead. To populate existing frame rows, use
+[`replace_video()`](../pypaimon/video#update-frame-rows-and-replace-a-video).
 
 ## Descriptors and Physical Layout
 
@@ -124,14 +270,41 @@ leave the video packs unchanged. See [Data Evolution 
Maintenance](./data-evoluti
 - Append-only tables only; primary-key tables continue to use managed BLOB 
storage.
 - Every configured field must be a scalar `BLOB`; `ARRAY<BLOB>` and `MAP<K, 
BLOB>` continue to use
   `.blob`.
-- Non-null writes must be exact descriptor-backed `BlobRef` values containing a
-  `VideoFrameDescriptor`. Inline bytes and ordinary `BlobDescriptor` values 
are rejected.
+- At the storage-writer boundary, non-null values must be exact 
descriptor-backed `BlobRef`
+  values containing a `VideoFrameDescriptor`. Inline bytes and ordinary 
`BlobDescriptor`
+  values are rejected there. The PyPaimon video APIs above construct the frame 
descriptors
+  automatically from complete-video sources.
 - A `BlobConsumer` callback is not supported for the video field.
 
 ## Read Frames
 
 A frame descriptor identifies the encoded video and the frame to decode. It 
does
-not contain decoded image pixels. Read behavior differs by API:
+not contain decoded image pixels.
+
+![A selected row is mapped through the video pack index to a video byte range 
and frame ordinal. A PyPaimon worker opens that range, builds an in-memory MP4 
sample index, and decodes from a preceding keyframe to the requested 
frame.](/img/multimodal-video-read.svg)
+
+1. Paimon plans the selected snapshot and columns, aligning the normal data 
and video
+   column files by row ID. The `.video` footer and span index map each 
selected row position
+   to a physical video and a zero-based frame ordinal.
+2. The reader returns a `VideoFrameDescriptor`: the pack URI, the complete 
video's offset
+   and length, the frame ordinal, and the MP4 `moov` range when available. 
Resolving the
+   descriptor does not decode the video or load its complete payload.
+3. A PyPaimon decoding worker opens a seekable stream restricted to that 
video's range.
+   For supported MP4 files, it reads the `moov` sample tables to derive frame 
timing,
+   sample locations, and keyframe positions in memory. Paimon does not persist 
a separate
+   keyframe index. Unsupported layouts use the decoder's scanning path.
+4. The decoder locates a preceding keyframe and decodes forward to the 
requested
+   presentation-order frame, including any required reference frames. 
Neighboring requests
+   can reuse the decoder and cached data. The result is image pixels or a 
tensor, rather
+   than encoded MP4 bytes. Random access can require decoding more than one 
frame.
+
+Decoder sessions and range caches are local to each worker process. The 
diagram describes
+PyPaimon's built-in decoding path; a custom decoder supplied to 
`VideoFrameCollator` controls
+its own seeking and decoding behavior.
+
+### Read Descriptors
+
+Read behavior differs by API:
 
 | API | How to obtain frame descriptors |
 | --- | --- |
@@ -163,7 +336,64 @@ This table property remains enabled for subsequent SQL 
reads.
 
 </TabItem>
 
+<TabItem value="python" label="PyPaimon">
+
+```python
+rows = (
+    frames.scan()
+    .where("episode_id = 42")
+    .select(["episode_id", "frame_index", "camera_front"])
+    .limit(3)
+    .to_list()
+)
+for row in rows:
+    descriptor = pm.VideoFrameDescriptor.deserialize(row["camera_front"])
+    print(descriptor.uri, descriptor.offset, descriptor.length, 
descriptor.frame_index)
+```
+
+These are serialized frame descriptors, not image bytes. Calling 
`read_blobs()` on a
+video column materializes the complete encoded video for each selected row; it 
does
+not extract the selected frame.
+
+</TabItem>
+
 </Tabs>
 
-For Python ingestion and PyTorch `DataLoader` usage, including decoder-session 
reuse in workers,
-see [PyPaimon Multimodal API: Video Frame 
Storage](../pypaimon/video#video-frame-storage).
+### Decode Frames with PyPaimon
+
+Use the matching PyPaimon build and PyTorch/video extras installed in the
+[PyPaimon creation example](#create-a-video-table).
+
+The window dataset decodes configured video columns with PyAV or TorchCodec. 
This example
+requests one front-camera frame per row and stacks the decoded RGB tensors:
+
+```python
+import torch
+from torch.utils.data import DataLoader
+
+dataset = frames.scan().where("episode_id = 42").to_contiguous_window_dataset(
+    columns=["camera_front"],
+    frame_offsets={"camera_front": [0]},
+    group_key="episode_id",
+    order_key="frame_index",
+    video_backend="pyav",
+    column_transforms={"camera_front": torch.stack},
+)
+try:
+    loader = DataLoader(dataset, batch_size=8, num_workers=0, shuffle=False)
+    batch = next(iter(loader))
+    # [batch, time=1, channels=3, height, width]
+    print(batch["camera_front"].shape)
+finally:
+    dataset.close()
+```
+
+Within each episode, `frame_index` must be non-null and increase by one. Use 
offsets such
+as `[-2, -1, 0]` for temporal windows; the dataset keeps descriptors through 
row selection
+and decodes the requested frames before assembling each window. TorchCodec is 
optional
+and must be installed separately when selecting `video_backend="torchcodec"`.
+
+For a row-oriented `scan().to_torch()` dataset, use `VideoFrameCollator` to 
decode frames;
+`to_torch()` alone returns descriptors. See the
+[complete collator example](../pypaimon/video#read-with-pytorch-dataloader) and
+[video training windows](../pypaimon/video#read-video-training-windows).
diff --git a/docs/static/img/multimodal-video-read.svg 
b/docs/static/img/multimodal-video-read.svg
new file mode 100644
index 0000000000..3fa65b9b9a
--- /dev/null
+++ b/docs/static/img/multimodal-video-read.svg
@@ -0,0 +1,91 @@
+<svg xmlns="http://www.w3.org/2000/svg"; width="900" height="786" viewBox="0 0 
900 786" role="img" aria-labelledby="title desc">
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<title id="title">From a logical row to decoded video pixels</title>
+<desc id="desc">Paimon resolves a selected row through the video pack span 
index into a descriptor containing the complete video byte range, frame 
ordinal, and optional MP4 moov range. A PyPaimon worker opens only that video 
range and derives an in-memory frame index from MP4 sample tables. In this 
illustrative sequence, it decodes from keyframe 32 through target frame 37 and 
returns RGB pixels or a tensor. Decoder sessions and range caches are reused 
within each worker. Unsupported layo [...]
+<defs>
+  <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" 
markerHeight="7" orient="auto-start-reverse">
+    <path d="M0 0 L10 5 L0 10 Z" fill="#526277"/>
+  </marker>
+</defs>
+<g font-family="Arial, Helvetica, sans-serif" fill="#172b4d">
+  <rect x="1" y="1" width="898" height="784" rx="12" fill="#ffffff" 
stroke="#d7dfeb" stroke-width="1.5"/>
+  <text x="28" y="44" font-size="27" font-weight="700">From a logical row to 
decoded video pixels</text>
+  <text x="28" y="76" font-size="17" fill="#526277">A frame descriptor is a 
reference. A decoder turns it into pixels.</text>
+
+  <text x="28" y="119" font-size="20" font-weight="700" fill="#2463b4">Paimon: 
select rows and resolve descriptors</text>
+  <rect x="28" y="138" width="250" height="128" rx="8" fill="#eaf2ff" 
stroke="#d7dfeb"/>
+  <text x="44" y="168" font-size="19" font-weight="700" fill="#2463b4">1. 
Select a logical row</text>
+  <text x="44" y="198" font-size="16">episode_id = 42</text>
+  <text x="44" y="223" font-size="16">frame_index = 37</text>
+  <text x="44" y="248" font-size="15" fill="#526277">Align column files by row 
ID.</text>
+
+  <path d="M283 202 H313" fill="none" stroke="#526277" stroke-width="2" 
marker-end="url(#arrow)"/>
+  <rect x="320" y="138" width="250" height="128" rx="8" fill="#eaf2ff" 
stroke="#d7dfeb"/>
+  <text x="336" y="168" font-size="19" font-weight="700" fill="#2463b4">2. 
Resolve a video span</text>
+  <text x="336" y="198" font-size="16">Selected row position</text>
+  <text x="336" y="223" font-size="16">→ video A, frame ordinal 37</text>
+  <text x="336" y="248" font-size="15" fill="#526277">Read the pack footer and 
index.</text>
+
+  <path d="M575 202 H605" fill="none" stroke="#526277" stroke-width="2" 
marker-end="url(#arrow)"/>
+  <rect x="612" y="138" width="260" height="128" rx="8" fill="#eaf2ff" 
stroke="#d7dfeb"/>
+  <text x="628" y="168" font-size="19" font-weight="700" fill="#2463b4">3. 
Return a descriptor</text>
+  <text x="628" y="198" font-size="16">Pack URI + offset + length</text>
+  <text x="628" y="223" font-size="16">Frame ordinal + moov range</text>
+  <text x="628" y="248" font-size="15" fill="#526277">No image pixels decoded 
yet.</text>
+
+  <path d="M742 270 V290 H14 V437 H38" fill="none" stroke="#526277" 
stroke-width="2" marker-end="url(#arrow)"/>
+  <text x="28" y="330" font-size="20" font-weight="700" 
fill="#14766b">PyPaimon worker: open the video, locate frames, decode</text>
+  <rect x="28" y="360" width="844" height="350" rx="10" fill="#f8fbfa" 
stroke="#d7dfeb"/>
+  <rect x="46" y="378" width="358" height="118" rx="8" fill="#e7f5f1" 
stroke="#d7dfeb"/>
+  <text x="62" y="407" font-size="19" font-weight="700" fill="#14766b">4. Open 
a bounded stream</text>
+  <text x="62" y="437" font-size="16">Expose only video A's byte range.</text>
+  <text x="62" y="462" font-size="16">Seek and read through table 
FileIO.</text>
+  <text x="62" y="484" font-size="14" fill="#526277">Other videos in the pack 
stay outside the stream.</text>
+
+  <path d="M412 437 H456" fill="none" stroke="#526277" stroke-width="2" 
marker-end="url(#arrow)"/>
+  <rect x="466" y="378" width="388" height="118" rx="8" fill="#e7f5f1" 
stroke="#d7dfeb"/>
+  <text x="482" y="407" font-size="19" font-weight="700" fill="#14766b">5. 
Read MP4 sample tables</text>
+  <text x="482" y="437" font-size="16">moov → timing, samples, keyframes</text>
+  <text x="482" y="462" font-size="16">Build the frame index in worker 
memory.</text>
+  <text x="482" y="484" font-size="14" fill="#526277">No separate persisted 
keyframe index.</text>
+
+  <path d="M660 502 V522" fill="none" stroke="#526277" stroke-width="2" 
marker-end="url(#arrow)"/>
+  <text x="62" y="550" font-size="19" font-weight="700" fill="#14766b">6. 
Decode from a preceding keyframe to the target</text>
+  <rect x="62" y="570" width="120" height="62" rx="6" fill="#fff1d6" 
stroke="#d4a34a"/>
+  <text x="122" y="595" text-anchor="middle" font-size="16" 
font-weight="700">Keyframe 32</text>
+  <text x="122" y="619" text-anchor="middle" font-size="14" 
fill="#526277">decode starts</text>
+  <rect x="194" y="570" width="120" height="62" rx="6" fill="#edf1f5" 
stroke="#d7dfeb"/>
+  <text x="254" y="608" text-anchor="middle" font-size="18">33</text>
+  <rect x="326" y="570" width="120" height="62" rx="6" fill="#edf1f5" 
stroke="#d7dfeb"/>
+  <text x="386" y="608" text-anchor="middle" font-size="18">34</text>
+  <rect x="458" y="570" width="120" height="62" rx="6" fill="#edf1f5" 
stroke="#d7dfeb"/>
+  <text x="518" y="608" text-anchor="middle" font-size="18">35</text>
+  <rect x="590" y="570" width="120" height="62" rx="6" fill="#edf1f5" 
stroke="#d7dfeb"/>
+  <text x="650" y="608" text-anchor="middle" font-size="18">36</text>
+  <rect x="722" y="570" width="116" height="62" rx="6" fill="#d4eee5" 
stroke="#14766b" stroke-width="2"/>
+  <text x="780" y="595" text-anchor="middle" font-size="16" font-weight="700" 
fill="#14766b">Target 37</text>
+  <text x="780" y="619" text-anchor="middle" font-size="14" fill="#14766b">RGB 
/ tensor</text>
+  <path d="M122 646 H780" fill="none" stroke="#526277" stroke-width="2" 
marker-end="url(#arrow)"/>
+  <text x="62" y="686" font-size="16" fill="#526277">Reuse decoder sessions 
and range caches for nearby requests in the same worker.</text>
+
+  <text x="28" y="742" font-size="16" fill="#526277">Illustrative frame order; 
the codec handles reference frames and reordering.</text>
+  <text x="28" y="767" font-size="16" fill="#526277">Unsupported container 
layouts fall back to decoder scanning.</text>
+</g>
+</svg>

Reply via email to