diff --git a/core/gen/video.h b/core/gen/video.h index 8c26c584..01f03eb7 100644 --- a/core/gen/video.h +++ b/core/gen/video.h @@ -85,7 +85,15 @@ struct VideoRefMedia { * each into the pack's keyframe table and encodes it into an image slot (a keyframe request * carries no references, so those slots are free). The server resizes each to the target canvas * (first a plain stretch, last a centre crop) and sets enc_pixels to one frame at that size, so - * its latent grid is the target's exactly and its pinned rows are frame_rows wide. */ + * its latent grid is the target's exactly and its pinned rows are frame_rows wide. + * A keyframe is fed to the DiT on TWO channels, matching the reference (clip.tokenize + + * vae.encode): the VAE-latent pin above, AND -- when the container carries a vision tower -- a + * anchor block through the tower (its `data` bytes are prepared as media and its + * soft tokens interleaved into the text conditioning). That anchor is the semantic counterpart + * to the low-level VAE pin; without it the DiT reconstructs the frame from pixels alone and + * over-saturates. `index` is the keyframe's ordinal (first = 1, last = 2), not a + * per-kind count, so the block is labelled the way the source workflow names it. On a towerless + * container the anchor channel is absent and the pin-only path runs unchanged. */ enum Kind : int32_t { IMAGE = 0, VIDEO = 1, VIDEO_AUDIO = 2, AUDIO = 3, FIRST_FRAME = 4, LAST_FRAME = 5 }; Kind kind = IMAGE; int32_t index = 0; diff --git a/core/gen/video_driver.cpp b/core/gen/video_driver.cpp index 62cc8673..b96b244a 100644 --- a/core/gen/video_driver.cpp +++ b/core/gen/video_driver.cpp @@ -345,7 +345,15 @@ int VideoDriver::submit(std::unique_ptr r, std::string* why) { * pack lays those slots between the text and the target streams (RadVideoGenBatch::ref_tab). * Every kind the declaration allows is consumed; the guard below is only about a container * lacking its vision tower, which could encode nothing. */ - if (!r->refs.empty() && max_enc_ == 0) + /* Reference media need the vision tower (their identity soft tokens). Endpoint keyframes do not: + * they condition through the VAE-latent pin, so a container converted without its tower can still + * render them -- the server simply lays no `media` for them and the pin-only path runs. (Keyframes + * still need the VAE encoders, checked just below.) */ + bool has_ref_media = false; + for (const VideoRefMedia& m : r->refs) + if (m.kind != VideoRefMedia::FIRST_FRAME && m.kind != VideoRefMedia::LAST_FRAME) + has_ref_media = true; + if (has_ref_media && max_enc_ == 0) return no("this container was converted without its vision tower, so no request can " "carry reference media"); /* A reference video, soundtrack or standalone audio reaches the model only through the VAE @@ -358,12 +366,16 @@ int VideoDriver::submit(std::unique_ptr r, std::string* why) { if (m.kind != VideoRefMedia::IMAGE) return no("'" + m.name + "' is a reference " + (m.kind == VideoRefMedia::VIDEO ? "video" - : m.kind == VideoRefMedia::VIDEO_AUDIO ? "soundtrack" : "audio") + + : m.kind == VideoRefMedia::VIDEO_AUDIO ? "soundtrack" + : m.kind == VideoRefMedia::FIRST_FRAME || + m.kind == VideoRefMedia::LAST_FRAME ? "keyframe" : "audio") + ", but this container was converted without its VAE encoders, so nothing " "can condition on it"); - /* Only reference images add language-model soft-token rows, so only they need processed media. - * A reference video or audio reaches the model purely through the VAE encode rows the pack lays - * from the reference table, so a request of those alone carries no `media` and needs none. */ + /* Only pictures (reference images and endpoint keyframes) add language-model soft-token rows, so + * only they need processed media. A reference video or audio reaches the model purely through the + * VAE encode rows the pack lays from the reference table, so a request of those alone carries no + * `media` and needs none. A keyframe with no tower also carries no `media` — that is the deliberate + * pin-only fallback, not a silent weakening (its VAE pin still conditions the DiT). */ bool has_image = false; for (const VideoRefMedia& m : r->refs) if (m.kind == VideoRefMedia::IMAGE) has_image = true; diff --git a/core/server/videos.cpp b/core/server/videos.cpp index 24f9ab8c..1c76a26b 100644 --- a/core/server/videos.cpp +++ b/core/server/videos.cpp @@ -310,7 +310,11 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { gen::VideoRefMedia m; m.kind = p.name == "first_frame" ? gen::VideoRefMedia::FIRST_FRAME : gen::VideoRefMedia::LAST_FRAME; - m.index = 1; + /* The keyframe's ordinal, so its vision-anchor block is labelled the way + * the source workflow names it (first = , last = ). A keyframe + * request carries no reference media (checked below), so these numbers cannot collide + * with a reference's own . */ + m.index = m.kind == gen::VideoRefMedia::FIRST_FRAME ? 1 : 2; m.name = p.name; m.filename = p.filename; m.content_type = p.content_type; @@ -603,9 +607,15 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { r->refs = std::move(refs); /* Keyframes ride the reference vector for the driver's sake (its encode queue indexes it), but * always AFTER every reference: the driver lays the reference rows down first, then folds each - * FIRST_FRAME/LAST_FRAME into the pack's keyframe table. first before last, so they keyframe-order - * 0 and 1 and take image slots 1 and 2. */ + * FIRST_FRAME/LAST_FRAME into the pack's keyframe table. Sort first before last (a client may send + * the file parts in either order) so they keyframe-order 0 and 1, take image slots 1 and 2, and + * present as then . */ + std::stable_sort(keys.begin(), keys.end(), [](const gen::VideoRefMedia& a, + const gen::VideoRefMedia& b) { + return a.kind < b.kind; /* FIRST_FRAME (4) before LAST_FRAME (5) */ + }); r->refs.insert(r->refs.end(), keys.begin(), keys.end()); + const bool has_keys = !keys.empty(); /* ---- the prompt: the template's text with special tokens, the reference media in its * presentation order, the prompt last (docs/PORT-REF2VA.md §3: images, then videos each @@ -630,7 +640,7 @@ HttpResponse Server::handle_video_create(const HttpRequest& req) { * soundtrack's `