[PR #1609] [Engine] Video input: video_url parts through strata-vision, in the Qwen3-VL layout #3559

Open
opened 2026-11-07 14:42:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1609
Author: @Destrayon
Created: 10/8/2026
Status: 🔄 Open

Base: main ← Head: pr/video-understanding


📝 Commits (6)

  • a9f382c strata-vision: ENCV encodes a video in the Qwen3-VL layout
  • 267d55d serve: video parts (OpenAI video_url, Responses input_video, Anthropic video)
  • 565eedc web: attach a video in the chat page (button, drop), sent as a video_url part
  • a5290d6 docs: videos (the layout, the keys, measured encoding and answers)
  • 2ab2751 strata-vision: a pair's time label is its frames' real mean (ffmpeg's fps filter returns frame k at ~(k+0.5)/fps)
  • f9827cf serve: a video's frame pairs default to at most 768 tokens, qwen-vl-utils' VIDEO_MAX_TOKEN_NUM

📊 Changes

9 files changed (+680 additions, -42 deletions)

View changed files

📝 docs/DETAILS.md (+68 -2)
📝 serve/frontend.py (+32 -1)
📝 serve/responses.py (+6 -1)
📝 serve/server.py (+168 -29)
📝 serve/test_server.py (+151 -0)
📝 serve/web/app.css (+1 -0)
📝 serve/web/app.js (+31 -6)
📝 serve/web/sprite.svg (+1 -0)
📝 tools/vision/strata_vision.cpp (+222 -3)

📄 Description

Problem and result

Qwen3.8-Flash-Next was trained on video (its template has <|video_pad|>, its mmproj is qwen3vl_merger with
temporal merge 2), but Strata reads pictures only: a video_url part is refused. With this change a video sent as an
OpenAI video_url part, a Responses input_video part or an Anthropic video block (as data:, an http(s) URL or
a local path, like images) is read by the model, and the web chat can attach one. The engine is unchanged: each frame
pair reaches it as an ordinary picture record through the existing GENI path.

A video is laid out as transformers' Qwen3-VL processor (processing_qwen3_vl.py) does it: frames sampled by ffmpeg,
frames 0+1, 2+3, ... merged into one temporal patch (an odd last frame doubled), each pair preceded by its time as
text, <1.2 seconds> (the mean of the two frames' real times), then <|vision_start|> image <|vision_end|>.

none. DETAILS.md lists "no video" under the current limits. Follow-up work on top of this branch was in #2023.

Approach

  • strata-vision gets ENCV <fps> <max_frames> <max_side> <pair_tokens> <total_tokens> <min_pair_tokens> <video> <out>, answering OK <tokens> <pairs> <frames> <ms> and LAYOUT <T ids|I cells; ...>. It plans from the video's
    probed length within the whole-video budget: 2 fps at up to 768 tokens per pair (qwen-vl-utils' default) while it
    fits, then smaller frames down to 128 per pair, then a lower frame rate, so any length is one request. It encodes 64
    frames at a time (peak 859 MB for a 10-minute video at 158K tokens). --ffmpeg-dir names ffmpeg/ffprobe when they
    are not on PATH. ENC is unchanged.
  • llama.cpp's own video helper (mtmd_helper_video) is not used for the layout: it writes a Video: label and a
    [0m5.00s] timestamp every 5 s after the frame it marks, which leaves frame 0 unpaired and shifts every label; with
    it, answers placed events about 1 s late. Its ffmpeg reader is used for the frames.
  • serve replaces the template's <|vision_start|><|video_pad|><|vision_end|> with the layout (text ids and one
    <|image_pad|> per cell); the pairs' records join the request's embeddings file in prompt order with the images.
    The image rules apply: URL downloads outside the request queue, local files only from the server's own page or
    trusted origins, the request's own files never evicted (#1072), offline mode refuses a video URL as it does an image
    URL, and a client that hangs up stops the encoding between videos. Budget: video_total_tokens 0 = 60% of the
    context, at most 224K (the model card's hour-scale setting), shared by the request's videos; video_fps,
    video_tokens, video_min_tokens, video_max_frames, video_max_side in the "vision" section, and a part's own
    fps, max_frames, max_side, tokens, total_tokens override them. /health has "videos".
  • On main the engine's conversation cache takes one key per picture (img_keys, #2228). A video's file holds one
    record per frame pair, so a request with a video sends no keys and the engine keys each record by its embeddings'
    hash, as it does when keys are absent. Requests with pictures only are unchanged.
  • web: the attach button and dropping a file take a video (up to 200 MB) when /health says videos are read.
  • docs: a Videos section in DETAILS.md (the layout, the keys, measurements).
  • Compatibility: nothing changes without a video part. Videos need ffmpeg and ffprobe (as llama.cpp's own video
    support does); without them a video is refused with ERR cannot read the video ... (is ffmpeg/ffprobe installed?)
    and pictures are unaffected. Setup does not install them. A release's ready-made strata-vision needs rebuilding
    for ENCV.

Validation

Rebased on main f57c0adc; tested revision f9827cfa (this branch). Windows 11, i9-13900K, RTX 5070 Ti, MSVC 14.51
(Visual Studio 18).

Passed:

  • python -m pytest serve/test_server.py -q on f9827cfa: 347 passed, 3 skipped, 449 subtests passed. The 9
    video tests (-k video: layout splicing, images and videos in prompt order, a literal marker kept as text, the
    three APIs' request shapes, the budget, the ENCV line, the temp file removed on a broken pipe) all pass.
  • python -m pytest serve -q --ignore=serve/test_server.py on f9827cfa: 526 passed, 14 skipped, 10,083 subtests passed.
  • node --check serve/web/app.js: no errors.
  • strata-vision from f9827cfa built with MSVC against llama.cpp 3cf0325 (main's pinned commit), CPU backend:
    builds clean. ENC test-1.jpeg gives OK 300 20 15 (unchanged). ENCV 2 0 0 448 0 128 on a 10 s 720x358 clip gives
    OK 2530 10 20 (20 frames, 10 pairs, 2,530 tokens, 15 s on 16 CPU threads), labels 0.5, 1.5, ... s. Against the
    pre-rebase build on the same clip: same token count, pairs, frames and record headers; only the time labels
    differ, which is this branch's label fix.
  • strata-vision from f9827cfa built with CUDA 12.8 for sm_120 (MSVC 14.44), run with --gpu on the 5070 Ti:
    ENC test-1.jpeg 300 tokens in 257 ms; ENCV on the same clip 2,530 tokens in 2.2 s, the LAYOUT line identical
    to the CPU build's, embeddings rows at cosine similarity 0.9994 mean (0.959 lowest) to the CPU build's.
  • The engine from f9827cfa (main's engine source unchanged by this PR) builds with CUDA 12.8 for sm_120 (setup's
    CUDA 12 options: -DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON).
  • A model answer from the f9827cfa GPU encoder: the clip sent as a video_url part, encoded on this PC (2.6 s) and
    answered by IQ3_S on an RTX 2080 Ti in another Strata server (2,640 prompt tokens, 13.4 s, thinking off). That
    server runs other code than this PR's serve/ (the encoder's records reached it as embeddings), so this checks the encoder and the layout, not this PR's server path. The first five seconds were
    described right (a creature grabbing a scared man, a close-up of the chair's lever, the man on the floor), the
    rest partly invented. Asked when the lever close-up appears: "3.0 seconds" (the shot runs 1.65-3.40 s, ffmpeg's
    scene detection); the clippers close-up: "7.0" (the shot runs 6.07-7.07 s).
  • Before the rebase (main 82f46a8, engine 0.1.39), end to end through the server with IQ2_XS on the 5070 Ti and the
    CPU encoder: on a 10 s clip the revolver placed at 6 s, right; on a 36 s HUD video the first HP change (87 to 41 at
    6 s) right, the later four not named. Measurements from that revision:
Video Budget Frames Tokens Encode
10 s, 720x358 (tools/mtmd/test-3.mp4) - 20 1,078 CPU 6.5 s, GPU 0.74 s
36 s, 1080p 39K (64K context) 72 (2 fps) 16,128 GPU 8.6 s
10 min, 540p 39K (64K context) 614 (~1 fps) 36,840 GPU 21 s
10 min, 540p 157K (256K context) 1,200 (2 fps) 158,400 GPU 71 s

(GPU: the encoder built with CUDA 12.8 for sm_120 on the 5070 Ti; at most 448 tokens per pair. A 10-minute
synthetic video with a 2-second banner at 7:13, on an RTX 2080 Ti with IQ3_S: the scene at 7:20 and the banner
right at 64K and at 256K context.)

Failed:
none observed.

Not run:

  • CUDA 13 builds (the release toolkit for this card), HIP, SYCL, Metal and Linux builds.

Limits

  • ffmpeg and ffprobe are the user's to install; setup does not do it.
  • A request with a video gets no per-picture cache keys (#2228), so the conversation cache matches its records by
    their embeddings' hash: a video encoded again with other bits does not match its checkpoints.
  • Long videos on the CPU encoder are slow (a 10-minute video's encode has its own 30-minute read timeout,
    STRATA_VISION_VIDEO_S).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1609 **Author:** [@Destrayon](https://github.com/Destrayon) **Created:** 10/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/video-understanding` --- ### 📝 Commits (6) - [`a9f382c`](https://github.com/Niko1221/Strata/commit/a9f382c8266bd06fa30f6244d7f3df1a4ebbf1e1) strata-vision: ENCV encodes a video in the Qwen3-VL layout - [`267d55d`](https://github.com/Niko1221/Strata/commit/267d55d9ff7d224f446579d61aa7014c541db692) serve: video parts (OpenAI video_url, Responses input_video, Anthropic video) - [`565eedc`](https://github.com/Niko1221/Strata/commit/565eedcaadd5ed4e639bae5fca33e2bc6d7114f6) web: attach a video in the chat page (button, drop), sent as a video_url part - [`a5290d6`](https://github.com/Niko1221/Strata/commit/a5290d60f3fe9307ff96df2b0f44ab3a957d4967) docs: videos (the layout, the keys, measured encoding and answers) - [`2ab2751`](https://github.com/Niko1221/Strata/commit/2ab27517fd56398225edb66307c9546f5bce0ac4) strata-vision: a pair's time label is its frames' real mean (ffmpeg's fps filter returns frame k at ~(k+0.5)/fps) - [`f9827cf`](https://github.com/Niko1221/Strata/commit/f9827cfac9b48a8d4524427747aa97fad6bb06a5) serve: a video's frame pairs default to at most 768 tokens, qwen-vl-utils' VIDEO_MAX_TOKEN_NUM ### 📊 Changes **9 files changed** (+680 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+68 -2) 📝 `serve/frontend.py` (+32 -1) 📝 `serve/responses.py` (+6 -1) 📝 `serve/server.py` (+168 -29) 📝 `serve/test_server.py` (+151 -0) 📝 `serve/web/app.css` (+1 -0) 📝 `serve/web/app.js` (+31 -6) 📝 `serve/web/sprite.svg` (+1 -0) 📝 `tools/vision/strata_vision.cpp` (+222 -3) </details> ### 📄 Description ## Problem and result Qwen3.8-Flash-Next was trained on video (its template has `<|video_pad|>`, its mmproj is `qwen3vl_merger` with temporal merge 2), but Strata reads pictures only: a `video_url` part is refused. With this change a video sent as an OpenAI `video_url` part, a Responses `input_video` part or an Anthropic `video` block (as `data:`, an `http(s)` URL or a local path, like images) is read by the model, and the web chat can attach one. The engine is unchanged: each frame pair reaches it as an ordinary picture record through the existing `GENI` path. A video is laid out as transformers' Qwen3-VL processor (`processing_qwen3_vl.py`) does it: frames sampled by ffmpeg, frames 0+1, 2+3, ... merged into one temporal patch (an odd last frame doubled), each pair preceded by its time as text, `<1.2 seconds>` (the mean of the two frames' real times), then `<|vision_start|>` image `<|vision_end|>`. ## Related discussion none. DETAILS.md lists "no video" under the current limits. Follow-up work on top of this branch was in #2023. ## Approach - **strata-vision** gets `ENCV <fps> <max_frames> <max_side> <pair_tokens> <total_tokens> <min_pair_tokens> <video> <out>`, answering `OK <tokens> <pairs> <frames> <ms>` and `LAYOUT <T ids|I cells; ...>`. It plans from the video's probed length within the whole-video budget: 2 fps at up to 768 tokens per pair (qwen-vl-utils' default) while it fits, then smaller frames down to 128 per pair, then a lower frame rate, so any length is one request. It encodes 64 frames at a time (peak 859 MB for a 10-minute video at 158K tokens). `--ffmpeg-dir` names ffmpeg/ffprobe when they are not on PATH. `ENC` is unchanged. - llama.cpp's own video helper (`mtmd_helper_video`) is not used for the layout: it writes a `Video:` label and a `[0m5.00s]` timestamp every 5 s after the frame it marks, which leaves frame 0 unpaired and shifts every label; with it, answers placed events about 1 s late. Its ffmpeg reader is used for the frames. - **serve** replaces the template's `<|vision_start|><|video_pad|><|vision_end|>` with the layout (text ids and one `<|image_pad|>` per cell); the pairs' records join the request's embeddings file in prompt order with the images. The image rules apply: URL downloads outside the request queue, local files only from the server's own page or trusted origins, the request's own files never evicted (#1072), offline mode refuses a video URL as it does an image URL, and a client that hangs up stops the encoding between videos. Budget: `video_total_tokens` 0 = 60% of the context, at most 224K (the model card's hour-scale setting), shared by the request's videos; `video_fps`, `video_tokens`, `video_min_tokens`, `video_max_frames`, `video_max_side` in the `"vision"` section, and a part's own `fps`, `max_frames`, `max_side`, `tokens`, `total_tokens` override them. `/health` has `"videos"`. - On main the engine's conversation cache takes one key per picture (`img_keys`, #2228). A video's file holds one record per frame pair, so a request with a video sends no keys and the engine keys each record by its embeddings' hash, as it does when keys are absent. Requests with pictures only are unchanged. - **web:** the attach button and dropping a file take a video (up to 200 MB) when `/health` says videos are read. - **docs:** a Videos section in DETAILS.md (the layout, the keys, measurements). - Compatibility: nothing changes without a video part. Videos need `ffmpeg` and `ffprobe` (as llama.cpp's own video support does); without them a video is refused with `ERR cannot read the video ... (is ffmpeg/ffprobe installed?)` and pictures are unaffected. Setup does not install them. A release's ready-made `strata-vision` needs rebuilding for `ENCV`. ## Validation Rebased on main `f57c0adc`; tested revision `f9827cfa` (this branch). Windows 11, i9-13900K, RTX 5070 Ti, MSVC 14.51 (Visual Studio 18). **Passed:** - `python -m pytest serve/test_server.py -q` on `f9827cfa`: 347 passed, 3 skipped, 449 subtests passed. The 9 video tests (`-k video`: layout splicing, images and videos in prompt order, a literal marker kept as text, the three APIs' request shapes, the budget, the ENCV line, the temp file removed on a broken pipe) all pass. - `python -m pytest serve -q --ignore=serve/test_server.py` on `f9827cfa`: 526 passed, 14 skipped, 10,083 subtests passed. - `node --check serve/web/app.js`: no errors. - `strata-vision` from `f9827cfa` built with MSVC against llama.cpp `3cf0325` (main's pinned commit), CPU backend: builds clean. `ENC test-1.jpeg` gives `OK 300 20 15` (unchanged). `ENCV 2 0 0 448 0 128` on a 10 s 720x358 clip gives `OK 2530 10 20` (20 frames, 10 pairs, 2,530 tokens, 15 s on 16 CPU threads), labels 0.5, 1.5, ... s. Against the pre-rebase build on the same clip: same token count, pairs, frames and record headers; only the time labels differ, which is this branch's label fix. - `strata-vision` from `f9827cfa` built with CUDA 12.8 for sm_120 (MSVC 14.44), run with `--gpu` on the 5070 Ti: `ENC test-1.jpeg` 300 tokens in 257 ms; `ENCV` on the same clip 2,530 tokens in 2.2 s, the LAYOUT line identical to the CPU build's, embeddings rows at cosine similarity 0.9994 mean (0.959 lowest) to the CPU build's. - The engine from `f9827cfa` (main's engine source unchanged by this PR) builds with CUDA 12.8 for sm_120 (setup's CUDA 12 options: `-DSTRATA_EXPERIMENTAL_SM60=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON`). - A model answer from the `f9827cfa` GPU encoder: the clip sent as a `video_url` part, encoded on this PC (2.6 s) and answered by IQ3_S on an RTX 2080 Ti in another Strata server (2,640 prompt tokens, 13.4 s, thinking off). That server runs other code than this PR's `serve/` (the encoder's records reached it as embeddings), so this checks the encoder and the layout, not this PR's server path. The first five seconds were described right (a creature grabbing a scared man, a close-up of the chair's lever, the man on the floor), the rest partly invented. Asked when the lever close-up appears: "3.0 seconds" (the shot runs 1.65-3.40 s, ffmpeg's scene detection); the clippers close-up: "7.0" (the shot runs 6.07-7.07 s). - Before the rebase (main `82f46a8`, engine 0.1.39), end to end through the server with IQ2_XS on the 5070 Ti and the CPU encoder: on a 10 s clip the revolver placed at 6 s, right; on a 36 s HUD video the first HP change (87 to 41 at 6 s) right, the later four not named. Measurements from that revision: | Video | Budget | Frames | Tokens | Encode | | --- | ---: | ---: | ---: | ---: | | 10 s, 720x358 (`tools/mtmd/test-3.mp4`) | - | 20 | 1,078 | CPU 6.5 s, GPU 0.74 s | | 36 s, 1080p | 39K (64K context) | 72 (2 fps) | 16,128 | GPU 8.6 s | | 10 min, 540p | 39K (64K context) | 614 (~1 fps) | 36,840 | GPU 21 s | | 10 min, 540p | 157K (256K context) | 1,200 (2 fps) | 158,400 | GPU 71 s | (GPU: the encoder built with CUDA 12.8 for sm_120 on the 5070 Ti; at most 448 tokens per pair. A 10-minute synthetic video with a 2-second banner at 7:13, on an RTX 2080 Ti with IQ3_S: the scene at 7:20 and the banner right at 64K and at 256K context.) **Failed:** none observed. **Not run:** - CUDA 13 builds (the release toolkit for this card), HIP, SYCL, Metal and Linux builds. ## Limits - ffmpeg and ffprobe are the user's to install; setup does not do it. - A request with a video gets no per-picture cache keys (#2228), so the conversation cache matches its records by their embeddings' hash: a video encoded again with other bits does not match its checkpoints. - Long videos on the CPU encoder are slow (a 10-minute video's encode has its own 30-minute read timeout, `STRATA_VISION_VIDEO_S`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3559
No description provided.