Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

phase-5 work: R1.2 deterministic corpus generator (5 scenarios x 1080p60/4K60) + SHA256 manifest; gate corpus checks green, impl gaps red

Veyra Goal Agentc7d641415ca0
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6d83e49..c320a611 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -318,6 +318,7 @@ if(VEYRA_CLIP_TOOLS_ROOT AND EXISTS "${VEYRA_CLIP_TOOLS_ROOT}/include/libavcodec
target_include_directories(veyra_clip_gen PRIVATE "${VEYRA_CLIP_TOOLS_ROOT}/include")
target_link_directories(veyra_clip_gen PRIVATE "${VEYRA_CLIP_TOOLS_ROOT}/lib")
target_link_libraries(veyra_clip_gen PRIVATE
+ veyra_base
"${VEYRA_CLIP_TOOLS_ROOT}/lib/avcodec.lib"
"${VEYRA_CLIP_TOOLS_ROOT}/lib/avformat.lib"
"${VEYRA_CLIP_TOOLS_ROOT}/lib/avutil.lib")
diff --git a/loop/JOURNAL.md b/loop/JOURNAL.md
index 47041a16..e30f045b 100644
--- a/loop/JOURNAL.md
+++ b/loop/JOURNAL.md
@@ -944,6 +944,33 @@ C staged teardown 定位崩溃=swapChain_.Release,矩阵证明 NVOF+debug layer+
- 新 blocker:L2 GBV runtime id=938 未初始化描述符(待修,非本任务)。
- 未执行:query-heap GPU timestamp(用户明令禁止);Reviewer/checkpoint(未授权)。
+## Cycle 032 — R1.2 确定性 corpus 生成器(2026-09-06 Goal)
+
+### Before
+
+- Phase: 5(重开,in_progress)
+- 唯一任务: 扩展 `tools/clip_generator/main.cpp` 为五场景确定性生成器(translation +8px/frame、occlusion 遮挡显露、cut-flash-duplicate 硬切/单帧闪光/重复帧、particles 半透明粒子、ui-text 固定文字+运动背景),新增 `--make-corpus` 模式生成 1080p60+4K60 共 10 片并写 SHA256 manifest(loop/local/fixed_clips/corpus-manifest.json + corpus/ 目录);gate 不再依赖已删除的 tracked MP4。
+- 可证伪假设: 若场景内容退化(纯色/全零/无运动),quality gate 的 nonZeroMotion/confidence/sceneCut 检查将在 R4 揭露;本轮可证伪点是——生成的 10 片全部存在、非空、SHA256 与 manifest 一致,且重跑 phase5 gate 时 `corpus:*` 四项由红转绿而其余缺口保持红。
+- 预计修改文件: tools/clip_generator/main.cpp(重写)、CMakeLists.txt(clip_gen 链 veyra_base 取 SHA256)、scripts/gates/phase5.ps1(corpus 路径解析改为相对 manifest 目录)。
+- 快速检查命令: `build x64-release` → 0;`veyra_clip_gen --make-corpus loop/local/fixed_clips` → 0 且 manifest 10 条;`phase5.ps1 -Root .` → 仍 exit 1 但 corpus:* 四项 PASS。
+- 预期新增证据: corpus-manifest.json + 10 个 mp4(ignored 目录)+ gate 复跑输出。
+
+### After
+
+- 实际修改: tools/clip_generator/main.cpp 重写(五场景确定性渲染器 + --make-corpus + manifest 写出);CMakeLists.txt(veyra_clip_gen 链 veyra_base 取文件 SHA256);scripts/gates/phase5.ps1(corpus 路径改为相对 manifest 目录解析)。
+- 实际命令与 exit code:
+ - `build x64-release` → exit 0(两轮:首轮 2 个自有 warning 清理后 0 剩余自有 warning)。
+ - 首次 `veyra_clip_gen --make-corpus` → **exit 2(libopenh264 encoder not found)**: out/build/x64-release 旁的最小版 avcodec-63.dll(player_probe 运行时)遮蔽了 tools-installed 的含 openh264 版本(同 ABI 名)。修复:建立隔离运行目录 `out/build/x64-release/clipgen/`(exe 拷贝 + tools-installed 的 avcodec/avformat/avutil/openh264-7.dll),不动其他 probe 的运行时变量。
+ - 隔离目录重跑 `--make-corpus loop/local/fixed_clips` → **exit 0**:10 片全部生成(5 场景 × 1080p60/4K60,各 600 帧 10s,1080p 8Mbps / 4K 24Mbps)+ corpus-manifest.json(每片含 scenario/width/height/fps/path/sizeBytes/sha256/command,pathBase=manifest-dir)。
+- 复核: manifest 10 条目与 10 个文件一一对应;gate 重跑 → **corpus:manifest-present / manifest-complete / clip-files / clip-sha256 四项 PASS**(gate 独立重算 SHA256 与 manifest 一致,证明路径解析正确),其余 30 项保持红(product 库/runner/矩阵/depth/耐久缺口不变),整体仍 exit 1 — 与假设一致。
+- 场景设计要点: translation 棋盘 +8px/frame 高对比异色(luma+chroma 运动);occlusion 对角纹理背景 + 三角波扫过实心前景(遮挡/显露);cut-flash-duplicate 四段异构内容硬切 + 中段后单帧白闪 + 60% 处 3 帧重复;particles 48 个确定性半透明亮斑(alpha 混合);ui-text 运动渐变背景 + 固定文字条块。全部为 (scenario,x,y,frame,extent) 的纯函数,可复现。
+- 失败 fingerprint: clip-gen|make-corpus|2|DLL shadowing(最小版 avcodec 遮蔽 tools 版)→ 隔离运行目录修复,第 1 次尝试关闭。
+- 是否有进展,依据: 是——gate 的 corpus 输入依赖从"已删除的 tracked MP4"变为确定性生成 + SHA256 锁定的 manifest,且四项检查由红转绿。
+- STATE/BACKLOG 更新: cycle.completed=32;BACKLOG R1.2 → DONE;nextAction → R2.1。
+- 下一唯一动作: R2.1 — 建立 include/veyra/pipeline 契约(Rational PTS、ColorDescription、FrameFlags、GpuTextureHandle、固定 prev/current/next + lookaheadFrames、GuidanceFrame provenance/age、ResetCoordinator 帧边界消费)与 PipelineContractTests。
+
+---
+
## Cycle 031 — R1.1 phase5 gate 重建并先红(2026-09-06 Goal)
### Before
diff --git a/loop/STATE.json b/loop/STATE.json
index facdb03b..a4887545 100644
--- a/loop/STATE.json
+++ b/loop/STATE.json
@@ -76,14 +76,14 @@
}
],
"cycle": {
- "completed": 31,
+ "completed": 32,
"maximum": 120,
"sameFailureAttempts": 0,
"maximumSameFailureAttempts": 3,
"noProgressCycles": 0,
"maximumNoProgressCycles": 5
},
- "currentTask": "R1.1 complete (Cycle 031): scripts/gates/phase5.ps1 rewritten as a 42-check fail-closed product gate (manifest-only depth path deleted, second-1080p-as-4K deleted, 30-minute endurance restored, product-library execution proof, extent/hash/timing/VRAM/reset JSON contract). Proven red on current implementation: exit 1, 34/42 failed with named gaps (product library x5, corpus x4, matrix/depth/endurance/discipline fail-closed).",
+ "currentTask": "R1.2 complete (Cycle 032): veyra_clip_gen extended to five deterministic scenarios (translation/occlusion/cut-flash-duplicate/particles/ui-text), corpus of 10 clips (1080p60 + 4K60, 600 frames each) generated with SHA256 corpus-manifest.json. DLL-shadowing fixed via isolated clipgen runtime dir. Phase5 gate corpus:* x4 now PASS while implementation gaps stay red (30/42 fail, exit 1).",
"lastGate": {
"name": "phase5",
"status": "invalidated_requires_rebuild",
@@ -106,6 +106,6 @@
"A real DirectShow/UVC 4K60 SDR capture device, HDMI audio, and 4K60 source signal are required before P7 capture gate can pass.",
"Public distribution rights for the experimental DLSSNR runtime and all bundled NVIDIA/model/FFmpeg assets are unresolved; a local release candidate is allowed, public launch is blocked."
],
- "nextAction": "Playbook R1.2: extend veyra_clip_gen with five deterministic scenarios (translation, occlusion, cut-flash-duplicate, particles, ui-text) at 1080p60 and 4K60, generate the corpus into loop/local/fixed_clips with recorded commands and SHA256 corpus-manifest.json so the rebuilt phase5 gate corpus checks can pass; then R2.1 FramePacket contract migration.",
- "updatedAt": "2026-09-06T16:55:00+08:00"
+ "nextAction": "Playbook R2.1: migrate data contracts to include/veyra/pipeline (Rational PTS/duration, ColorDescription with assumed flags, FrameFlags 10 events, GpuTextureHandle with owner slot/expected state/ready fence, FrameWindow fixed prev/current/next + lookaheadFrames 0/1/2 without unbounded vector, GuidanceFrame provenance/age/sourceSequence, ResetCoordinator frame-boundary consumption) plus PipelineContractTests covering 8 reset events, negative/unknown PTS, cross-epoch rejection, window cap and fence ownership.",
+ "updatedAt": "2026-09-06T16:35:00+08:00"
}
diff --git a/scripts/gates/phase5.ps1 b/scripts/gates/phase5.ps1
index 23220660..c7b440a7 100644
--- a/scripts/gates/phase5.ps1
+++ b/scripts/gates/phase5.ps1
@@ -112,6 +112,7 @@ Add-GateCheck "product:enhance-graph-submits-gpu" $enhanceOk "src/pipeline/Enhan
# 3. Deterministic corpus (veyra_clip_gen; no dependency on deleted tracked MP4)
# ---------------------------------------------------------------------------
$corpusManifestPath = Join-Path $Root "loop\local\fixed_clips\corpus-manifest.json"
+$corpusManifestDir = Split-Path -Parent $corpusManifestPath
$corpus = $null
Add-GateCheck "corpus:manifest-present" (Test-Path -LiteralPath $corpusManifestPath -PathType Leaf) $corpusManifestPath
if (Test-Path -LiteralPath $corpusManifestPath -PathType Leaf) {
@@ -140,7 +141,7 @@ if ($corpusEntries.Count -ge 10) {
$clipPath = [string](Get-Field $entry "path")
$sha = [string](Get-Field $entry "sha256")
if ([string]::IsNullOrWhiteSpace($clipPath) -or ($sha -notmatch "^[0-9A-Fa-f]{64}$")) { $corpusComplete = $false; continue }
- $absClip = if ([System.IO.Path]::IsPathRooted($clipPath)) { $clipPath } else { Join-Path $Root $clipPath }
+ $absClip = if ([System.IO.Path]::IsPathRooted($clipPath)) { $clipPath } else { Join-Path $corpusManifestDir $clipPath }
if (-not (Test-Path -LiteralPath $absClip -PathType Leaf)) { $corpusFilesOk = $false; continue }
$item = Get-Item -LiteralPath $absClip
if ($item.Length -le 0) { $corpusFilesOk = $false; continue }
@@ -276,7 +277,7 @@ if ($corpusComplete) {
$enduranceJsons = @{}
if ($runnerPresent -and ($null -ne $translationHd)) {
$hdPath = [string](Get-Field $translationHd "path")
- if (-not [System.IO.Path]::IsPathRooted($hdPath)) { $hdPath = Join-Path $Root $hdPath }
+ if (-not [System.IO.Path]::IsPathRooted($hdPath)) { $hdPath = Join-Path $corpusManifestDir $hdPath }
$ej = Join-Path $logDir "endurance-1080p60.json"
Write-Host "[INFO] endurance:1080p60 running (30 minutes, shared graph)..."
& $runnerExe --input $hdPath --duration-seconds 1800 --run-id ($runId + "-end-1080p60") --log-file (Join-Path $logDir "endurance-1080p60.log") --json-file $ej
@@ -289,7 +290,7 @@ else {
if ($runnerPresent -and ($null -ne $translationUhd)) {
$uhdPath = [string](Get-Field $translationUhd "path")
- if (-not [System.IO.Path]::IsPathRooted($uhdPath)) { $uhdPath = Join-Path $Root $uhdPath }
+ if (-not [System.IO.Path]::IsPathRooted($uhdPath)) { $uhdPath = Join-Path $corpusManifestDir $uhdPath }
$ej4 = Join-Path $logDir "endurance-4k60.json"
Write-Host "[INFO] endurance:4k60-native running (30 minutes, shared graph)..."
& $runnerExe --input $uhdPath --duration-seconds 1800 --run-id ($runId + "-end-4k60") --log-file (Join-Path $logDir "endurance-4k60.log") --json-file $ej4
diff --git a/tools/clip_generator/main.cpp b/tools/clip_generator/main.cpp
index d0a19810..96931977 100644
--- a/tools/clip_generator/main.cpp
+++ b/tools/clip_generator/main.cpp
@@ -1,85 +1,313 @@
-// veyra_clip_gen - deterministic H.264 test clip generator (tool-only build).
-// Links the openh264-enabled FFmpeg from C:\veyra-deps\tools-installed; the
-// player itself never links these libraries. Output: MP4/H.264 1080p with a
-// deterministic moving pattern (bars + frame counter + gradient) so seek and
-// parity checks have non-uniform, reproducible content.
+// veyra_clip_gen - deterministic H.264 corpus clip generator (tool-only build).
+// Links the openh264-enabled FFmpeg from the local toolchain and veyra_base
+// (SHA-256). The player never links these libraries.
+//
+// Scenarios (Playbook section 20; every renderer is a pure function of
+// (scenario, x, y, frameIndex, extent) so runs are reproducible):
+// translation high-contrast checkerboard moving +8 px/frame, wrap
+// occlusion slow diagonal texture behind a sweeping solid rect
+// cut-flash-duplicate 4 hard-cut segments + 1-frame white flash + duplicate
+// frame run + PTS-stable cadence break signal
+// particles dark field with translucent bright blobs (alpha)
+// ui-text fixed text-like bar block over a scrolling gradient
+//
+// --make-corpus writes <dir>/corpus-manifest.json plus <dir>/corpus/*.mp4 for
+// 5 scenarios x {1920x1080, 3840x2160} @ 60 fps. Manifest clip paths are
+// relative to the manifest file's own directory ("pathBase": "manifest-dir").
#include <windows.h>
+#include <cmath>
#include <cstdio>
#include <cstring>
#include <format>
#include <string>
+#include <vector>
+
+#include <veyra/FileIdentity.h>
extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
-#include <libavutil/opt.h>
}
namespace {
-// Deterministic RGB value at a pixel (same pattern the harness family uses).
-void patternRgb(int x, int y, int width, int height, int64_t frameIndex, uint8_t out[3])
+enum class Scenario {
+ Translation,
+ Occlusion,
+ CutFlashDuplicate,
+ Particles,
+ UiText,
+};
+
+bool parseScenario(const std::string& name, Scenario& out)
+{
+ if (name == "translation") { out = Scenario::Translation; return true; }
+ if (name == "occlusion") { out = Scenario::Occlusion; return true; }
+ if (name == "cut-flash-duplicate") { out = Scenario::CutFlashDuplicate; return true; }
+ if (name == "particles") { out = Scenario::Particles; return true; }
+ if (name == "ui-text") { out = Scenario::UiText; return true; }
+ return false;
+}
+
+const char* scenarioName(Scenario s)
+{
+ switch (s) {
+ case Scenario::Translation: return "translation";
+ case Scenario::Occlusion: return "occlusion";
+ case Scenario::CutFlashDuplicate: return "cut-flash-duplicate";
+ case Scenario::Particles: return "particles";
+ case Scenario::UiText: return "ui-text";
+ }
+ return "unknown";
+}
+
+// Deterministic 0..1 hash for particle placement (integer-only chains).
+double detHash01(uint32_t a, uint32_t b)
+{
+ uint32_t h = a * 374761393u + b * 668265263u;
+ h = (h ^ (h >> 13)) * 1274126177u;
+ h = h ^ (h >> 16);
+ return static_cast<double>(h & 0xFFFFFFu) / 16777215.0;
+}
+
+// ---------------------------------------------------------------------------
+// Per-pixel scenario renderers (RGB full-range working values).
+// ---------------------------------------------------------------------------
+
+void renderTranslation(int x, int y, int w, int h, int64_t frame, uint8_t out[3])
+{
+ const int cell = h >= 2160 ? 128 : 64;
+ const int64_t offset = frame * 8;
+ const int cx = static_cast<int>((x + offset) / cell);
+ const int cy = y / cell;
+ const bool parity = ((cx + cy) & 1) != 0;
+ // Two high-contrast, chroma-distinct colors so luma AND chroma motion exist.
+ if (parity) { out[0] = 205; out[1] = 70; out[2] = 60; }
+ else { out[0] = 55; out[1] = 55; out[2] = 200; }
+ // Soft vertical gradient keeps every region non-flat.
+ const double g = static_cast<double>(y) / h;
+ const int lift = static_cast<int>(g * 24.0);
+ out[0] = static_cast<uint8_t>(out[0] + lift > 255 ? 255 : out[0] + lift);
+ out[1] = static_cast<uint8_t>(out[1] + lift > 255 ? 255 : out[1] + lift);
+ out[2] = static_cast<uint8_t>(out[2] + lift > 255 ? 255 : out[2] + lift);
+}
+
+void renderOcclusionBackground(int x, int y, int64_t frame, uint8_t out[3])
+{
+ const int period = 48;
+ const int64_t offset = frame * -2;
+ const int phase = static_cast<int>((x + offset) + y) % period;
+ const int band = phase < period / 2 ? 0 : 1;
+ const int base = band == 0 ? 96 : 168;
+ const int fine = ((x / 4 + y / 4) & 1) != 0 ? 10 : -10;
+ out[0] = static_cast<uint8_t>(base + fine);
+ out[1] = static_cast<uint8_t>(base + fine + 8);
+ out[2] = static_cast<uint8_t>(base + fine + 16);
+}
+
+void renderOcclusion(int x, int y, int w, int h, int64_t totalFrames, int64_t frame, uint8_t out[3])
+{
+ // Foreground rect sweeps left->right->left across the clip (triangle wave).
+ const int rectW = w * 35 / 100;
+ const int rectH = h * 50 / 100;
+ const int rectY0 = (h - rectH) / 2;
+ const double t = static_cast<double>(frame) / static_cast<double>(totalFrames - 1);
+ double tri = t * 2.0;
+ if (tri > 1.0) { tri = 2.0 - tri; }
+ const int rectX0 = static_cast<int>(tri * static_cast<double>(w - rectW));
+ if (y >= rectY0 && y < rectY0 + rectH && x >= rectX0 && x < rectX0 + rectW) {
+ const int border = (h >= 2160) ? 8 : 4;
+ const bool edge = x < rectX0 + border || x >= rectX0 + rectW - border
+ || y < rectY0 + border || y >= rectY0 + rectH - border;
+ if (edge) { out[0] = 225; out[1] = 225; out[2] = 235; }
+ else { out[0] = 70; out[1] = 125; out[2] = 180; }
+ return;
+ }
+ renderOcclusionBackground(x, y, frame, out);
+}
+
+void renderCutSegment(int seg, int x, int y, int w, int h, int64_t frame, uint8_t out[3])
+{
+ switch (seg) {
+ case 0: {
+ // Fine checker, distinct colors from the translation scenario.
+ const int cell = h >= 2160 ? 48 : 24;
+ const bool parity = (((x / cell) + (y / cell)) & 1) != 0;
+ out[0] = parity ? 190 : 70; out[1] = parity ? 150 : 95; out[2] = parity ? 60 : 175;
+ return;
+ }
+ case 1: {
+ // Large slow vertical color blocks.
+ const int cell = h >= 2160 ? 384 : 192;
+ const int block = static_cast<int>((y / cell + frame / 30) % 4);
+ const uint8_t v = static_cast<uint8_t>(60 + block * 45);
+ out[0] = v; out[1] = static_cast<uint8_t>(220 - block * 30); out[2] = static_cast<uint8_t>(90 + block * 25);
+ return;
+ }
+ case 2: {
+ // Fast horizontal stripes (+16 px/frame equivalent by phase).
+ const int period = h >= 2160 ? 160 : 80;
+ const int phase = static_cast<int>((x + frame * 16) % period);
+ const bool on = phase < period / 2;
+ const uint8_t v = on ? 210 : 55;
+ out[0] = v; out[1] = static_cast<uint8_t>(v * 3 / 4); out[2] = static_cast<uint8_t>(v * 2 / 3);
+ return;
+ }
+ default: {
+ // Expanding rings from center.
+ const double dx = x - w * 0.5, dy = y - h * 0.5;
+ const double r = std::sqrt(dx * dx + dy * dy);
+ const double period = h >= 2160 ? 240.0 : 120.0;
+ const double phase = std::fmod(r - static_cast<double>(frame) * 6.0, period);
+ const bool on = phase >= 0 && phase < period * 0.5;
+ const uint8_t v = on ? 200 : 80;
+ out[0] = v; out[1] = v; out[2] = static_cast<uint8_t>(on ? 120 : 190);
+ return;
+ }
+ }
+}
+
+void renderCutFlashDuplicate(int x, int y, int w, int h, int64_t totalFrames, int64_t frame, uint8_t out[3])
+{
+ const int64_t segFrames = totalFrames / 4;
+ // Duplicate run: frames [60%, 60%+3) reuse the content of frame 60%-1.
+ const int64_t dupStart = totalFrames * 6 / 10;
+ int64_t eff = frame;
+ if (frame >= dupStart && frame < dupStart + 3) { eff = dupStart - 1; }
+ // Single-frame white flash right after the middle hard cut.
+ const int64_t flashFrame = segFrames * 2 + 1;
+ if (frame == flashFrame) { out[0] = 242; out[1] = 242; out[2] = 242; return; }
+ const int seg = static_cast<int>(eff / segFrames);
+ renderCutSegment(seg, x, y, w, h, eff, out);
+}
+
+void renderUiTextBackground(int x, int y, int w, int h, int64_t frame, uint8_t out[3])
{
- const int bars = 8;
- const int barWidth = width / bars;
- const double u = static_cast<double>(x) / width;
- const double v = static_cast<double>(y) / height;
- if (y < height / 2) {
- const int bar = x / barWidth;
- const uint8_t lit = ((bar + frameIndex) % bars == 0) ? 235 : 40;
- out[0] = bar == 0 || bar == 3 || bar == 6 ? lit : 40;
- out[1] = bar == 1 || bar == 3 || bar == 5 ? lit : 40;
- out[2] = bar == 2 || bar == 5 || bar == 6 ? lit : 40;
+ const double u = static_cast<double>(x) / w;
+ const double v = static_cast<double>(y) / h;
+ const double scroll = std::fmod(u + static_cast<double>(frame) * 6.0 / w, 1.0);
+ out[0] = static_cast<uint8_t>(40 + scroll * 150);
+ out[1] = static_cast<uint8_t>(60 + v * 90);
+ out[2] = static_cast<uint8_t>(180 - scroll * 120);
+}
+
+void renderUiText(int x, int y, int w, int h, int64_t frame, uint8_t out[3])
+{
+ // Fixed text-like block: rows of white bars with deterministic widths.
+ const int x0 = w * 10 / 100, x1 = w * 55 / 100;
+ const int y0 = h * 15 / 100, y1 = h * 85 / 100;
+ if (x >= x0 && x < x1 && y >= y0 && y < y1) {
+ const int lineH = h / 26;
+ const int gap = h / 78;
+ const int localY = y - y0;
+ const int inLine = localY % (lineH + gap);
+ if (inLine < lineH) {
+ const int line = localY / (lineH + gap);
+ const double frac = 0.35 + 0.6 * detHash01(static_cast<uint32_t>(line), 7u);
+ const int barW = static_cast<int>(frac * (x1 - x0));
+ if (x - x0 < barW || (line < 3 && x - x0 < (x1 - x0))) {
+ out[0] = 245; out[1] = 245; out[2] = 245;
+ return;
+ }
+ }
}
- else {
- out[0] = static_cast<uint8_t>(u * 255);
- out[1] = static_cast<uint8_t>(v * 255);
- out[2] = static_cast<uint8_t>(((u + v) * 0.5) * 255);
+ renderUiTextBackground(x, y, w, h, frame, out);
+}
+
+void renderScenarioPixel(Scenario s, int x, int y, int w, int h, int64_t totalFrames, int64_t frame, uint8_t out[3])
+{
+ switch (s) {
+ case Scenario::Translation: renderTranslation(x, y, w, h, frame, out); return;
+ case Scenario::Occlusion: renderOcclusion(x, y, w, h, totalFrames, frame, out); return;
+ case Scenario::CutFlashDuplicate: renderCutFlashDuplicate(x, y, w, h, totalFrames, frame, out); return;
+ case Scenario::UiText: renderUiText(x, y, w, h, frame, out); return;
+ case Scenario::Particles: renderUiTextBackground(x, y, w, h, frame, out); return; // bg only; blobs drawn after
}
- if (y < 12) {
- const uint8_t bit = (frameIndex >> (x * 8 / width)) & 1 ? 235 : 16;
- out[0] = out[1] = out[2] = bit;
+}
+
+// ---------------------------------------------------------------------------
+// Full-frame RGB rendering (particles drawn as overlay pass).
+// ---------------------------------------------------------------------------
+
+void renderFrameRgb(Scenario s, int64_t frame, int64_t totalFrames, int w, int h, std::vector<uint8_t>& rgb)
+{
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ uint8_t px[3];
+ renderScenarioPixel(s, x, y, w, h, totalFrames, frame, px);
+ uint8_t* d = &rgb[(static_cast<size_t>(y) * w + x) * 3];
+ d[0] = px[0]; d[1] = px[1]; d[2] = px[2];
+ }
+ }
+ if (s != Scenario::Particles) { return; }
+
+ // Translucent bright blobs over the dark background (alpha blend 0.55).
+ const double scale = static_cast<double>(h) / 1080.0;
+ const int count = 48;
+ for (int i = 0; i < count; ++i) {
+ const double bx = detHash01(static_cast<uint32_t>(i), 1u) * w;
+ const double by = detHash01(static_cast<uint32_t>(i), 2u) * h;
+ const double dir = detHash01(static_cast<uint32_t>(i), 3u) > 0.5 ? 1.0 : -1.0;
+ const double speed = (2.0 + 5.0 * detHash01(static_cast<uint32_t>(i), 4u)) * scale;
+ const double cxp = std::fmod(bx + dir * speed * static_cast<double>(frame) + w, w);
+ const double cyp = std::fmod(by + std::sin(static_cast<double>(i) + frame * 0.01) * 40.0 * scale + h, h);
+ const double radius = (24.0 + detHash01(static_cast<uint32_t>(i), 5u) * 72.0) * scale;
+ const uint8_t cr = static_cast<uint8_t>(120 + detHash01(static_cast<uint32_t>(i), 6u) * 130);
+ const uint8_t cg = static_cast<uint8_t>(120 + detHash01(static_cast<uint32_t>(i), 7u) * 130);
+ const uint8_t cb = static_cast<uint8_t>(120 + detHash01(static_cast<uint32_t>(i), 8u) * 130);
+ const int x0 = std::max(0, static_cast<int>(cxp - radius));
+ const int x1 = std::min(w - 1, static_cast<int>(cxp + radius));
+ const int y0 = std::max(0, static_cast<int>(cyp - radius));
+ const int y1 = std::min(h - 1, static_cast<int>(cyp + radius));
+ const double r2 = radius * radius;
+ for (int yy = y0; yy <= y1; ++yy) {
+ for (int xx = x0; xx <= x1; ++xx) {
+ const double dx = xx - cxp, dy = yy - cyp;
+ const double d2 = dx * dx + dy * dy;
+ if (d2 >= r2) { continue; }
+ const double fall = 1.0 - std::sqrt(d2) / radius; // 1 center -> 0 edge
+ const double a = 0.55 * fall;
+ uint8_t* p = &rgb[(static_cast<size_t>(yy) * w + xx) * 3];
+ p[0] = static_cast<uint8_t>(p[0] * (1.0 - a) + cr * a);
+ p[1] = static_cast<uint8_t>(p[1] * (1.0 - a) + cg * a);
+ p[2] = static_cast<uint8_t>(p[2] * (1.0 - a) + cb * a);
+ }
+ }
}
}
-// Fill a YUV420P frame directly (BT.601 limited range) without swscale.
-void fillYuv420p(AVFrame* frame, int width, int height, int64_t frameIndex)
+// ---------------------------------------------------------------------------
+// RGB -> YUV420P (BT.601 limited), 2x2 chroma averaged. No swscale dependency.
+// ---------------------------------------------------------------------------
+
+void fillYuv420pFromRgb(AVFrame* frame, const std::vector<uint8_t>& rgb, int w, int h)
{
- for (int y = 0; y < height; ++y) {
+ for (int y = 0; y < h; ++y) {
uint8_t* yRow = frame->data[0] + y * frame->linesize[0];
- for (int x = 0; x < width; ++x) {
- uint8_t rgb[3];
- patternRgb(x, y, width, height, frameIndex, rgb);
- const double r = rgb[0] / 255.0;
- const double g = rgb[1] / 255.0;
- const double b = rgb[2] / 255.0;
+ const uint8_t* src = &rgb[static_cast<size_t>(y) * w * 3];
+ for (int x = 0; x < w; ++x) {
+ const double r = src[x * 3 + 0] / 255.0;
+ const double g = src[x * 3 + 1] / 255.0;
+ const double b = src[x * 3 + 2] / 255.0;
const double y_ = 0.299 * r + 0.587 * g + 0.114 * b;
yRow[x] = static_cast<uint8_t>(16 + y_ * 219);
}
}
- const int chromaWidth = width / 2;
- const int chromaHeight = height / 2;
- for (int cy = 0; cy < chromaHeight; ++cy) {
+ const int cw = w / 2, ch = h / 2;
+ for (int cy = 0; cy < ch; ++cy) {
uint8_t* uRow = frame->data[1] + cy * frame->linesize[1];
uint8_t* vRow = frame->data[2] + cy * frame->linesize[2];
- for (int cx = 0; cx < chromaWidth; ++cx) {
- // Average the 2x2 RGB block, then convert chroma.
+ for (int cx = 0; cx < cw; ++cx) {
double rr = 0, gg = 0, bb = 0;
for (int dy = 0; dy < 2; ++dy) {
for (int dx = 0; dx < 2; ++dx) {
- uint8_t rgb[3];
- patternRgb(cx * 2 + dx, cy * 2 + dy, width, height, frameIndex, rgb);
- rr += rgb[0] / 255.0;
- gg += rgb[1] / 255.0;
- bb += rgb[2] / 255.0;
+ const uint8_t* p = &rgb[(static_cast<size_t>(cy * 2 + dy) * w + cx * 2 + dx) * 3];
+ rr += p[0] / 255.0; gg += p[1] / 255.0; bb += p[2] / 255.0;
}
}
- rr /= 4.0;
- gg /= 4.0;
- bb /= 4.0;
- const double y_ = 0.299 * rr + 0.587 * gg + 0.114 * bb;
+ rr /= 4.0; gg /= 4.0; bb /= 4.0;
const double u_ = -0.169 * rr - 0.331 * gg + 0.500 * bb;
const double v_ = 0.500 * rr - 0.419 * gg - 0.081 * bb;
uRow[cx] = static_cast<uint8_t>(128 + u_ * 224);
@@ -88,45 +316,26 @@ void fillYuv420p(AVFrame* frame, int width, int height, int64_t frameIndex)
}
}
-} // namespace
+// ---------------------------------------------------------------------------
+// Encoding
+// ---------------------------------------------------------------------------
-int main(int argc, char** argv)
+int encodeClip(const std::string& output, Scenario scenario, int width, int height, int fps, int seconds, int64_t& outFrames)
{
- std::string output = "test_h264_1080p.mp4";
- int seconds = 30;
- int fps = 30;
- int width = 1920;
- int height = 1080;
- for (int i = 1; i < argc; ++i) {
- const std::string arg = argv[i];
- if (arg == "--output" && i + 1 < argc) output = argv[++i];
- else if (arg == "--seconds" && i + 1 < argc) seconds = atoi(argv[++i]);
- else if (arg == "--fps" && i + 1 < argc) fps = atoi(argv[++i]);
- else if (arg == "--width" && i + 1 < argc) width = atoi(argv[++i]);
- else if (arg == "--height" && i + 1 < argc) height = atoi(argv[++i]);
- }
-
AVFormatContext* formatContext = nullptr;
avformat_alloc_output_context2(&formatContext, nullptr, nullptr, output.c_str());
if (formatContext == nullptr) {
- std::fprintf(stderr, "clip-gen: avformat_alloc_output_context2 failed\n");
+ std::fprintf(stderr, "clip-gen: avformat_alloc_output_context2 failed for %s\n", output.c_str());
return 1;
}
-
const AVCodec* codec = avcodec_find_encoder_by_name("libopenh264");
if (codec == nullptr) {
std::fprintf(stderr, "clip-gen: libopenh264 encoder not found\n");
return 2;
}
-
AVStream* stream = avformat_new_stream(formatContext, nullptr);
- if (stream == nullptr) {
- return 3;
- }
AVCodecContext* codecContext = avcodec_alloc_context3(codec);
- if (codecContext == nullptr) {
- return 3;
- }
+ if (stream == nullptr || codecContext == nullptr) { return 3; }
codecContext->width = width;
codecContext->height = height;
codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
@@ -134,7 +343,7 @@ int main(int argc, char** argv)
codecContext->framerate = { fps, 1 };
codecContext->gop_size = fps;
codecContext->max_b_frames = 0;
- codecContext->bit_rate = 6'000'000;
+ codecContext->bit_rate = height >= 2160 ? 24'000'000 : 8'000'000;
if (formatContext->oformat->flags & AVFMT_GLOBALHEADER) {
codecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
}
@@ -144,70 +353,161 @@ int main(int argc, char** argv)
}
avcodec_parameters_from_context(stream->codecpar, codecContext);
stream->time_base = codecContext->time_base;
-
if (!(formatContext->oformat->flags & AVFMT_NOFILE)) {
if (avio_open(&formatContext->pb, output.c_str(), AVIO_FLAG_WRITE) < 0) {
- std::fprintf(stderr, "clip-gen: avio_open failed\n");
+ std::fprintf(stderr, "clip-gen: avio_open failed for %s\n", output.c_str());
return 5;
}
}
- if (avformat_write_header(formatContext, nullptr) < 0) {
- return 5;
- }
+ if (avformat_write_header(formatContext, nullptr) < 0) { return 5; }
AVFrame* yuvFrame = av_frame_alloc();
yuvFrame->format = AV_PIX_FMT_YUV420P;
yuvFrame->width = width;
yuvFrame->height = height;
av_frame_get_buffer(yuvFrame, 32);
-
+ std::vector<uint8_t> rgb(static_cast<size_t>(width) * height * 3);
AVPacket* packet = av_packet_alloc();
const int64_t totalFrames = static_cast<int64_t>(seconds) * fps;
for (int64_t frameIndex = 0; frameIndex < totalFrames; ++frameIndex) {
- fillYuv420p(yuvFrame, width, height, frameIndex);
+ renderFrameRgb(scenario, frameIndex, totalFrames, width, height, rgb);
+ fillYuv420pFromRgb(yuvFrame, rgb, width, height);
yuvFrame->pts = frameIndex;
- if (avcodec_send_frame(codecContext, yuvFrame) < 0) {
- return 6;
- }
+ if (avcodec_send_frame(codecContext, yuvFrame) < 0) { return 6; }
for (;;) {
const int result = avcodec_receive_packet(codecContext, packet);
- if (result == AVERROR(EAGAIN) || result == AVERROR_EOF) {
- break;
- }
- if (result < 0) {
- return 6;
- }
+ if (result == AVERROR(EAGAIN) || result == AVERROR_EOF) { break; }
+ if (result < 0) { return 6; }
av_packet_rescale_ts(packet, codecContext->time_base, stream->time_base);
packet->stream_index = stream->index;
- if (av_interleaved_write_frame(formatContext, packet) < 0) {
- return 7;
- }
+ if (av_interleaved_write_frame(formatContext, packet) < 0) { return 7; }
}
}
(void)avcodec_send_frame(codecContext, nullptr);
for (;;) {
const int result = avcodec_receive_packet(codecContext, packet);
- if (result == AVERROR(EAGAIN) || result == AVERROR_EOF) {
- break;
- }
- if (result < 0) {
- return 6;
- }
+ if (result == AVERROR(EAGAIN) || result == AVERROR_EOF) { break; }
+ if (result < 0) { return 6; }
av_packet_rescale_ts(packet, codecContext->time_base, stream->time_base);
packet->stream_index = stream->index;
av_interleaved_write_frame(formatContext, packet);
}
av_write_trailer(formatContext);
-
- std::fprintf(stderr, "clip-gen: wrote %s (%lld frames, %ds@%d)\n",
- output.c_str(), static_cast<long long>(totalFrames), seconds, fps);
+ outFrames = totalFrames;
+ std::fprintf(stderr, "clip-gen: wrote %s (%lld frames, %ds@%d, %dx%d, %s)\n",
+ output.c_str(), static_cast<long long>(totalFrames), seconds, fps, width, height, scenarioName(scenario));
av_packet_free(&packet);
av_frame_free(&yuvFrame);
avcodec_free_context(&codecContext);
- if (!(formatContext->oformat->flags & AVFMT_NOFILE)) {
- avio_closep(&formatContext->pb);
- }
+ if (!(formatContext->oformat->flags & AVFMT_NOFILE)) { avio_closep(&formatContext->pb); }
avformat_free_context(formatContext);
return 0;
}
+
+std::string toForwardSlashes(std::string s)
+{
+ for (char& c : s) { if (c == '\\') { c = '/'; } }
+ return s;
+}
+
+int makeCorpus(const std::string& dir)
+{
+ CreateDirectoryA(dir.c_str(), nullptr);
+ const std::string corpusDir = dir + "/corpus";
+ CreateDirectoryA(corpusDir.c_str(), nullptr);
+
+ const struct { Scenario s; const char* name; } scenarios[] = {
+ { Scenario::Translation, "translation" },
+ { Scenario::Occlusion, "occlusion" },
+ { Scenario::CutFlashDuplicate, "cut-flash-duplicate" },
+ { Scenario::Particles, "particles" },
+ { Scenario::UiText, "ui-text" },
+ };
+ const struct { int w, h; const char* suffix; } extents[] = {
+ { 1920, 1080, "1080p60" },
+ { 3840, 2160, "4k60" },
+ };
+ const int fps = 60;
+ const int seconds = 10;
+
+ std::string manifest;
+ manifest += "{\n \"generator\": \"veyra_clip_gen\",\n \"generatorVersion\": 2,\n";
+ manifest += " \"pathBase\": \"manifest-dir\",\n \"clips\": [\n";
+ bool first = true;
+ for (const auto& sc : scenarios) {
+ for (const auto& ext : extents) {
+ const std::string file = std::string(sc.name) + "_" + ext.suffix + ".mp4";
+ const std::string path = corpusDir + "/" + file;
+ int64_t frames = 0;
+ const int rc = encodeClip(path, sc.s, ext.w, ext.h, fps, seconds, frames);
+ if (rc != 0) {
+ std::fprintf(stderr, "clip-gen: corpus generation failed rc=%d for %s\n", rc, path.c_str());
+ return rc;
+ }
+ veyra::FileIdentity ident;
+ veyra::IdentityError err = veyra::IdentityError::None;
+ std::wstring wide(path.begin(), path.end());
+ if (!veyra::computeFileIdentity(wide, ident, err) || ident.sha256Upper.empty()) {
+ std::fprintf(stderr, "clip-gen: identity/hash failed for %s err=%d\n", path.c_str(), static_cast<int>(err));
+ return 10;
+ }
+ if (!first) { manifest += ",\n"; }
+ first = false;
+ manifest += std::format(" {{\"scenario\": \"{}\", \"width\": {}, \"height\": {}, \"fps\": {}, "
+ "\"durationSeconds\": {}, \"frames\": {}, \"path\": \"corpus/{}\", \"sizeBytes\": {}, "
+ "\"sha256\": \"{}\", \"command\": \"veyra_clip_gen --scenario {} --width {} --height {} "
+ "--fps {} --seconds {} --output {}\"}}",
+ sc.name, ext.w, ext.h, fps, seconds, static_cast<long long>(frames), file,
+ static_cast<unsigned long long>(ident.sizeBytes), ident.sha256Upper,
+ sc.name, ext.w, ext.h, fps, seconds, toForwardSlashes(path));
+ }
+ }
+ manifest += "\n ]\n}\n";
+
+ const std::string manifestPath = dir + "/corpus-manifest.json";
+ FILE* f = nullptr;
+ if (fopen_s(&f, manifestPath.c_str(), "wb") != 0 || f == nullptr) {
+ std::fprintf(stderr, "clip-gen: cannot write %s\n", manifestPath.c_str());
+ return 11;
+ }
+ std::fwrite(manifest.data(), 1, manifest.size(), f);
+ std::fclose(f);
+ std::fprintf(stderr, "clip-gen: corpus manifest written: %s\n", manifestPath.c_str());
+ return 0;
+}
+
+} // namespace
+
+int main(int argc, char** argv)
+{
+ std::string output;
+ std::string scenarioArg;
+ std::string corpusDir;
+ int seconds = 10;
+ int fps = 60;
+ int width = 1920;
+ int height = 1080;
+ for (int i = 1; i < argc; ++i) {
+ const std::string arg = argv[i];
+ if (arg == "--output" && i + 1 < argc) output = argv[++i];
+ else if (arg == "--scenario" && i + 1 < argc) scenarioArg = argv[++i];
+ else if (arg == "--make-corpus" && i + 1 < argc) corpusDir = argv[++i];
+ else if (arg == "--seconds" && i + 1 < argc) seconds = std::atoi(argv[++i]);
+ else if (arg == "--fps" && i + 1 < argc) fps = std::atoi(argv[++i]);
+ else if (arg == "--width" && i + 1 < argc) width = std::atoi(argv[++i]);
+ else if (arg == "--height" && i + 1 < argc) height = std::atoi(argv[++i]);
+ }
+ if (!corpusDir.empty()) { return makeCorpus(corpusDir); }
+ Scenario scenario = Scenario::Translation;
+ if (scenarioArg.empty() || !parseScenario(scenarioArg, scenario)) {
+ std::fprintf(stderr, "clip-gen: --scenario required (translation|occlusion|cut-flash-duplicate|particles|ui-text) or --make-corpus <dir>\n");
+ return 1;
+ }
+ if (output.empty()) {
+ std::fprintf(stderr, "clip-gen: --output required\n");
+ return 1;
+ }
+ int64_t frames = 0;
+ return encodeClip(output, scenario, width, height, fps, seconds, frames);
+}