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++

feat: improve AV1 and MOV media compatibility

Veyra Goal Agent9b6c414d6d93
diff --git a/docs/BUILD.md b/docs/BUILD.md
index b85c6020..df0b6648 100644
--- a/docs/BUILD.md
+++ b/docs/BUILD.md
@@ -19,7 +19,7 @@ cd Veyra-NRVideo
powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/build.ps1 -Root . -Preset x64-release
```
-`build.ps1` resolves Visual Studio and CMake, stages the five FFmpeg DLLs, and builds `out/build/x64-release/veyra.exe`. Its default FFmpeg location is `C:/veyra-deps/installed/x64-windows`. Use the CMake cache variables below for other dependency layouts. `-BuildDirectory` selects a separate output directory while an existing build is running.
+`build.ps1` resolves Visual Studio and CMake, stages the five FFmpeg DLLs, and builds `out/build/x64-release/veyra.exe`. Its default FFmpeg location is `C:/veyra-deps/installed/x64-windows`. Use `-FfmpegRoot C:/path/to/prefix` when testing another FFmpeg prefix; the prefix must contain matching `include`, `lib`, `bin`, and `share/ffmpeg` trees. An AV1-enabled local prefix must also provide `bin/dav1d.dll` and its `share/dav1d` notices; the build script stages that DLL app-locally and never searches the system PATH. `-BuildDirectory` selects a separate output directory while an existing build is running.
| CMake variable | Local dependency |
| --- | --- |
@@ -38,6 +38,8 @@ The NGX configuration lives in `runtime_local/config/ngx-local.json` for develop
Release 1.2.0 includes `Veyra-1.2.0-FFmpeg-source.zip` separately: the patched FFmpeg source, SPDX-verified vcpkg port and patches, notices, and configuration queried from the shipped DLL. It is not needed to run Veyra.
+The AV1 software-decoding experiment is kept in a separate local FFmpeg prefix until its corresponding-source package and release audit are complete. It uses FFmpeg's LGPL build with the optional LGPL-compatible dav1d backend. MOV is a container rather than a codec: ProRes/H.264/HEVC MOV playback is tested independently, while an AV1 file must still use a container/muxer that actually carries AV1 (typically MP4 or WebM). A file extension alone is never treated as a compatibility guarantee.
+
- FFmpeg: https://github.com/FFmpeg/FFmpeg/tree/n9.0.1 ; vcpkg port source recorded in the distributed `licenses/FFMPEG-SPDX.json`.
- vcpkg FFmpeg port: https://github.com/microsoft/vcpkg/tree/55cd8b8a4f19d8e6ba2ad114c8acacc4af5915a0/ports/ffmpeg . Its patches and the LGPL notices are part of the corresponding-source material.
- FidelityFX SDK: https://github.com/GPUOpen-LibrariesAndSDKs/FidelityFX-SDK/tree/c6efa6bf7f2027b3ec94f28578bb5965eabb9e55 ; MIT license.
diff --git a/docs/MEDIA_FILE_COMPATIBILITY_PLAN_2026-09-14.md b/docs/MEDIA_FILE_COMPATIBILITY_PLAN_2026-09-14.md
index f25fa2c4..0716c3cf 100644
--- a/docs/MEDIA_FILE_COMPATIBILITY_PLAN_2026-09-14.md
+++ b/docs/MEDIA_FILE_COMPATIBILITY_PLAN_2026-09-14.md
@@ -6,9 +6,9 @@
本机随 1.2.0 发布的 patched FFmpeg n9.0.1 配置已经包含 `avformat` 和原生软件解码器。对实际随包 `avcodec-63.dll` 调用 `avcodec_descriptor_get_by_name` / `avcodec_find_decoder` 的结果为:H.264、HEVC、AV1、VP9、ProRes、DNxHD、MPEG-2、MPEG-4、VC-1 均能找到解码器;配置也保留 MOV/MP4、Matroska/WebM、AVI、MPEG-TS 解封装器。文件选择框已经列出 MP4/MKV/MOV/AVI/TS,且保留“所有文件”。
-这不等于产品已经可靠支持这些素材。普通文件播放目前强制 `preferHardwareDecode=false`,全部走软件解码;图在创建前只从 `AVCodecParameters` 推断色彩与位深,许多 MOV/AV1 文件的真实像素格式、HDR 信令、色度位置要到首帧才确定;失败 UI 只显示“无法打开视频”。因此用户看到“不支持”时,可能是软件 AV1 性能不足、HDR/10-bit/4:2:2/4:4:4 输入契约不完整、音轨初始化失败,或文件本身损坏,而不是 FFmpeg 完全没有 AV1/MOV。
+这不等于产品已经可靠支持这些素材。1.2.0 基线的普通文件播放曾强制 `preferHardwareDecode=false`,全部走软件解码;本分支已改为先尝试共享 D3D12VA,并在首帧导入契约不满足时回到软件。图在创建前只从 `AVCodecParameters` 推断色彩与位深仍然不够,许多 MOV/AV1 文件的真实像素格式、HDR 信令、色度位置要到首帧才确定;失败 UI 只显示“无法打开视频”。因此用户看到“不支持”时,可能是软件 AV1 性能不足、HDR/10-bit/4:2:2/4:4:4 输入契约不完整、音轨初始化失败,或文件本身损坏,而不是 FFmpeg 完全没有 AV1/MOV。
-当前 patched FFmpeg 的构建配置禁用 `libdav1d`,但保留 FFmpeg 自带 AV1 解码器;这能解码,不代表 CPU 性能足够。RTX 30 及更早显卡通常不能把 AV1 解码交给硬件,不能假装它们会获得 RTX 40/50 的 AV1 硬解表现。
+1.2.0 随包的 patched FFmpeg 构建配置禁用了 `libdav1d`。对实际 AV1 MP4 做软件探针时,原生 AV1 解码器枚举成功,但首包返回 `-40 / Function not implemented`,所以“能枚举”不能当成“能播放”。本轮已在项目外依赖目录用同一套 PS5 slice 补丁重建 FFmpeg,启用 `libdav1d 1.5.4`;新构建的 AV1 30 帧、ProRes-MOV 30 帧软件探针均通过,H.264 D3D12VA + NR 探针也通过。该新依赖尚未替换 1.2.0 发布资产,完整便携包和对应源码包审计仍是下一步。RTX 30 及更早显卡通常不能把 AV1 解码交给硬件,不能假装它们会获得 RTX 40/50 的 AV1 硬解表现。
## 范围与不承诺
@@ -20,7 +20,7 @@
### A. 先做媒体预检和真实错误报告
-新增独立 `MediaProbe`,在创建增强图前读取:容器名称、视频 codec/profile、像素格式/位深、尺寸、帧率与 VFR、色彩范围/矩阵/transfer/primaries、色度位置、音频 codec/声道布局,以及 FFmpeg 能否找到软件解码器和 D3D12VA 硬件配置。
+现有 `veyra_media_probe` 和文件源日志在创建增强图前读取:容器名称、视频 codec/profile、像素格式/位深、尺寸、帧率与 VFR、色彩范围/矩阵/transfer/primaries、色度位置、音频 codec/声道布局,以及 FFmpeg 能否找到软件解码器和 D3D12VA 硬件配置。
预检结果产生明确的支持结论,而不是靠扩展名:
@@ -63,7 +63,7 @@ UI 在打开失败时显示上述原因;日志完整记录 FFmpeg codec id/nam
基准以 1080p60、1440p60、4K30/60 AV1 各跑硬解和软件解,记录 decode P50/P95、掉帧、CPU、GPU、首帧、seek、音画同步。当前软件线程上限为 4;只有基准证明 AV1 受 CPU 解码限制时,才做 codec/分辨率感知的有上限线程策略。
-若原生 FFmpeg AV1 软件解仍不足,再单独评估将 BSD 许可的 `libdav1d` 接入 FFmpeg。那是依赖重建节点,不是“加 DLL”小修:必须重建并重新验证 PS5 H.264 slice patch、更新对应 FFmpeg 源码包、构建记录、许可证、运行库 SHA-256 和完整便携包审计。没有这一整套证据,不替换 1.2.0 的 FFmpeg。
+本轮已经完成了依赖评估:原生 AV1 路径对真实样本失败,因此 `libdav1d 1.5.4` 接入 FFmpeg。重建保留了 PS5 H.264 32→256 slice patch,配置仍是 LGPL;独立 prefix 的 `veyra-local-build.json` 记录五个 FFmpeg DLL 和 `dav1d.dll` 的 SHA-256、版本、许可证与来源。仍未把它直接替换进 1.2.0 发布包:发布前必须把 dav1d 对应源码/port、版权与 SPDX、运行库清单、完整便携包和 AV1/MOV 回归一起审计。
### F. 音频和导出不要借机回归
@@ -77,4 +77,4 @@ UI 在打开失败时显示上述原因;日志完整记录 FFmpeg codec id/nam
4. 再打开 NR、SR、DLSS/XeSS FG 做至少一条 SDR 和一条 HDR 回归;导出、截图、PS5、采集卡必须跑现有 delivery,确保本节点没有改变它们的输入路径。
5. 每次解码路径切换、seek、首帧色彩改变都原子 reset 图历史。硬解首次帧不符合 NV12/P010 时回退软件,不允许半会话继续。
-若 A 的诊断表明用户 AV1/MOV 已可被当前 DLL 解码,则优先修 Auto 硬解、色彩契约和 UI 诊断;不为了“支持列表好看”引入 dav1d 或重新打包 FFmpeg。若用户样本是 Dolby Vision、ProRes RAW 或受 DRM 保护,则明确拒绝并说明原因,不做不可靠的兼容层。
+当前代码已完成首帧颜色/位深探测、普通文件 Auto 硬解到软件回退、硬件纹理导入契约和具体解码日志;实际新 FFmpeg 的 AV1/ProRes 探针证据见 `docs/WORKLOG.md`。若用户样本是 Dolby Vision、ProRes RAW 或受 DRM 保护,则仍明确拒绝并说明原因,不做不可靠的兼容层。新 FFmpeg 尚未成为正式发布资产,不能把本地验证写成 1.2.0 已支持。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 4bd50e09..e5288ee4 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -2003,3 +2003,21 @@ GitHub Release https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.0 于
用户反馈 AV1、MOV 等文件“不能支持”,授权先研究并给出方案。本轮只读取源代码、1.2.0 随包 patched FFmpeg 构建记录和本机 DLL ABI,不修改产品功能、不构建、不更换 FFmpeg、不发布。实际 `avcodec-63.dll` 查询确认 H.264/HEVC/AV1/VP9/ProRes/DNxHD/MPEG-2/MPEG-4/VC-1 均有软件解码器;FFmpeg 配置与源码确认 MOV/MP4、Matroska/WebM、AVI、MPEG-TS 解封装器存在。当前问题不是一个 AV1 allowlist:文件对话框已有 MOV/AVI/TS 与所有文件,而普通文件又硬编码关闭硬解、图创建前不能可靠得到首帧的位深/HDR信息、失败提示过于笼统。FFmpeg 配置禁用了 libdav1d,保留原生 AV1,不能凭“能解码”承诺性能。
完整的可回退分阶段实施/验收计划见 docs/MEDIA_FILE_COMPATIBILITY_PLAN_2026-09-14.md。重点先做预检诊断和安全的 Auto 硬解→软件回退,再贯通首帧色彩契约与样本矩阵;dav1d/重建 patched FFmpeg 仅在真实性能基准证明必要后独立审计。未拿到用户问题文件或其日志,不能断言当前失败的具体 codec/profile/metadata 原因。
+
+## 2026-09-14 — 媒体文件兼容性施工:AV1/MOV 与首帧/硬解回退
+
+在 `codex/media-codec-compatibility` 隔离分支施工。`SourceInfo` 现在记录容器、视频 codec 和首帧像素格式;普通文件先探测首个有效视频帧再创建 EnhanceGraph,图描述会收到文件位深;文件路径默认尝试 D3D12VA,D3D12 纹理不是单层 NV12/P010、硬解报错或首帧导入契约不满足时,在首帧前原子重开软件解码并记录原因。日志补充首帧实际 format、HDR/matrix/transfer/range/chromaLocation;FFmpeg D3D12VA 导入增加纹理维度、mip、sample、尺寸与 DXGI 格式校验。没有改 PS5/采集卡入口的协议。
+
+真实证据:旧 1.2.0 patched FFmpeg 的 AV1 MP4 软件探针虽找到 `av1`,首帧失败 `code=-40 Function not implemented`;因此“枚举到解码器”确实不是“可以播放”。使用项目外 vcpkg `dav1d 1.5.4`(Apache-2.0/BSD-2-Clause/ISC/MIT)并保留 PS5 H.264 32→256 slice patch 重建独立 FFmpeg prefix;配置含 `--enable-libdav1d`、许可证仍为 LGPL 2.1+,`avcodec-63.dll` 对 `dav1d.dll` 的动态依赖已由 dumpbin 核实。新运行目录中:AV1 MP4 软件解码30帧 PASS(实际 codec=libdav1d)、ProRes MOV软件解码30帧 PASS;新五个FFmpeg DLL + dav1d 下 H.264 D3D12VA/共享设备/NR 12帧 PASS;旧 H.264 软件源测试23/23 PASS。新 prefix 的五个FFmpeg DLL和dav1d哈希、外部依赖许可记录在本机 `C:/veyra-deps/ffmpeg-ps5-dav1d-installed/share/ffmpeg/veyra-local-build.json`,未进入Git。
+
+构建命令 `cmd /c out/release-1.1.0-build.cmd` 最终成功;中间一次 `veyra.exe` 链接遇到旧进程/临时锁,重跑后通过。`git diff --check` 待本轮收口时执行。当前新FFmpeg尚未替换1.2.0 GitHub Release资产,也未制作/上传包含dav1d源码、port、版权和SPDX的对应源码包;不能把1.2.0写成已支持AV1。未执行用户原始AV1/MOV文件、长时播放、所有10/12-bit/4:2:2/4:4:4组合及实机画质验收;下一步补运行脚本/便携审计与真实样本矩阵,再决定是否制作新版本。
+
+## 2026-09-14 — 媒体兼容性施工收口(本地分支,未发布)
+
+在 `codex/media-codec-compatibility` 完成首个可运行闭环:`FFmpegVideoDecoder` 对 AV1 优先选择可选的 `libdav1d`,无该后端时保留 FFmpeg 原生回退;文件源默认尝试共享 D3D12VA,首帧前发现解码错误或 D3D12 纹理不满足 2D/NV12/P010/尺寸契约时自动重开软件解码;图创建前消费首帧缓存,避免 AV1/MOV 的真实位深和 HDR 信令被错误地按 SDR 建图。构建脚本支持 `-FfmpegRoot`,并只从所选前缀把 `dav1d.dll` 放到应用目录;便携脚本同步复制 DAV1D 版权/SPDX,未改变源码仓库的二进制隔离规则。文件源头文件注释已更新为按 FFmpeg 实际容器/codec 能力描述。
+
+本机外部依赖 `C:/veyra-deps/ffmpeg-ps5-dav1d-installed` 已补齐 `dav1d.dll`(SHA256 `38E09F960822A081FC46FC296FB3EF5F841D1A6C15A39F20684C2F9D88A9FC52`)及对应许可证;FFmpeg 配置实际含 `--enable-libdav1d`,保留 PS5 H.264 32→256 slice patch。构建命令为:`powershell -NoProfile -ExecutionPolicy Bypass -File scripts/build.ps1 ... -BuildDirectory out/media-codec-dav1d -FfmpegRoot C:/veyra-deps/ffmpeg-ps5-dav1d-installed`,478/478 编译链接通过,输出包含五个 FFmpeg DLL 和 `dav1d.dll`。PowerShell 三个脚本语法解析均为0错误,`git diff --check`收口通过。
+
+验证结果:新 `veyra_media_probe.exe` 的 AV1 MP4 软件解码30帧 PASS(日志明确 `codec=libdav1d`);ProRes MOV 软件解码30帧 PASS;同一新运行目录的 H.264 D3D12VA/共享设备/NR 12帧 PASS(NGX Create/Evaluate/Release 为 `0x1`、SEH0);H.264 `veyra_source_tests` 23/23,软件媒体探针30帧 PASS;`veyra_quality_probe` 对 AV1 30帧、无增强图完整处理,`failures=0`;独立便携包只关闭增强的完整播放器 smoke 运行3秒,`smoke frames=60 generated=0 failed=false`,自动从 AV1 D3D12VA 回退到 `libdav1d` 并保存/显示正常。实际合法的 AV1-MOV 样本无法由当前 FFmpeg MOV muxer生成(其明确拒绝 AV1 写入 MOV),因此没有把“AV1 MOV”写成已验证格式;MOV 按容器内实际 codec 分开判断。
+
+本地 `package-portable.ps1` 已成功生成带 `dav1d.dll`、DAV1D 版权/SPDX 和 FFMPEG provenance 的1.2.0测试包。`portable-smoke.ps1` 的基础、社区NR、DLSS NR/FG场景产生了有效输出;最后的既有 VideoSR 断言因当前驱动未加载脚本要求的 `_nvngx.dll` 失败,日志保留在 `out/media-codec-dav1d-portable-smoke/video-sr-nr-fg.stdout.log`,不归因于AV1/MOV。新 FFmpeg 仍未替换1.2.0 GitHub Release,未制作/上传包含 dav1d 对应源码/port 的正式对应源码包;用户原始文件、长时播放、10/12-bit、4:2:2/4:4:4 和其他显卡尚未验收,不能宣称所有格式和设备均已支持。
diff --git a/include/veyra/media/FFmpegDemuxer.h b/include/veyra/media/FFmpegDemuxer.h
index a7888e5a..8b7de717 100644
--- a/include/veyra/media/FFmpegDemuxer.h
+++ b/include/veyra/media/FFmpegDemuxer.h
@@ -39,6 +39,7 @@ public:
const AVCodecParameters* videoCodecParameters() const;
int videoTimeBaseNum() const; // stream time_base for frame PTS conversion
int videoTimeBaseDen() const;
+ std::string formatName() const;
// Returns false at end of file. The packet stays owned by this demuxer
// and remains valid until the next call.
diff --git a/include/veyra/media/FFmpegVideoDecoder.h b/include/veyra/media/FFmpegVideoDecoder.h
index 3931b544..8b2ad211 100644
--- a/include/veyra/media/FFmpegVideoDecoder.h
+++ b/include/veyra/media/FFmpegVideoDecoder.h
@@ -76,6 +76,11 @@ public:
int frameTimeBaseDen() const { return frameTimeBaseDen_; }
bool usingD3D12Frames() const { return hwAccelActive_ && context_ != nullptr && lastFrameFormat_ != -1; }
+ bool hardwareActive() const { return hwAccelActive_ && context_ != nullptr; }
+ // The product ingress currently imports only 2D NV12/P010 D3D12VA
+ // surfaces. Validate that contract before handing the first frame to the
+ // graph so an unsupported hardware surface can fall back cleanly.
+ bool hardwareFrameImportable() const;
int lastFrameFormat() const { return lastFrameFormat_; }
uint64_t gpuQueueWaitCount() const { return gpuQueueWaitCount_; }
diff --git a/include/veyra/source/IFrameSource.h b/include/veyra/source/IFrameSource.h
index b9b40e9d..dd1b0a17 100644
--- a/include/veyra/source/IFrameSource.h
+++ b/include/veyra/source/IFrameSource.h
@@ -33,6 +33,11 @@ struct SourceInfo {
int nominalRateNum = 0, nominalRateDen = 0; // candidate, not proof of CFR
double timestampQuantum = 0.0;
bool hardwareDecodeActive = false;
+ // File diagnostics. These are descriptive capability results, not a
+ // promise that every profile of the codec is supported.
+ std::string containerName;
+ std::string videoCodecName;
+ std::string videoPixelFormatName;
pipeline::ColorDescription color;
};
diff --git a/include/veyra/source/MediaFileSource.h b/include/veyra/source/MediaFileSource.h
index b5445b94..e1e6ec85 100644
--- a/include/veyra/source/MediaFileSource.h
+++ b/include/veyra/source/MediaFileSource.h
@@ -1,11 +1,14 @@
#pragma once
-// MediaFileSource - local video file input (H.264/HEVC in MP4/MKV/MOV)
+// MediaFileSource - local video file input (FFmpeg containers/codecs,
+// including H.264/HEVC/AV1 and professional MOV codecs when the selected
+// FFmpeg prefix provides their decoders)
// composing the product veyra_media libraries. No second decode
// implementation exists here: FFmpegDemuxer + FFmpegVideoDecoder do the
// work; this class owns contract translation (PTS/duration/color/flags/
// epoch) and the seek protocol.
#include <cstdint>
+#include <string_view>
#include "veyra/media/FFmpegDemuxer.h"
#include "veyra/media/FFmpegVideoDecoder.h"
@@ -34,6 +37,7 @@ public:
private:
pipeline::ColorDescription parseColor(const AVCodecParameters* params) const;
+ bool fallbackToSoftware(std::string_view reason);
media::FFmpegDemuxer demuxer_;
media::FFmpegVideoDecoder decoder_;
@@ -47,6 +51,8 @@ private:
bool eofSignalled_ = false;
std::wstring errorMessage_;
int64_t lastPtsUs_ = INT64_MIN;
+ std::wstring path_;
+ bool preferHardwareDecode_ = false;
};
} // namespace veyra::source
diff --git a/scripts/acceptance/portable-smoke.ps1 b/scripts/acceptance/portable-smoke.ps1
index 262ce047..b55a35f1 100644
--- a/scripts/acceptance/portable-smoke.ps1
+++ b/scripts/acceptance/portable-smoke.ps1
@@ -56,6 +56,9 @@ try {
foreach($module in @('avcodec-63.dll','avformat-63.dll','avutil-61.dll','swresample-7.dll','swscale-10.dll','vcruntime140.dll')+$case.modules){
if(-not $loaded.ContainsKey($module) -or -not $loaded[$module].StartsWith($package+'\',[StringComparison]::OrdinalIgnoreCase)){throw "$name missing app-local module $module ($($loaded[$module]))"}
}
+ if($loaded.ContainsKey('dav1d.dll') -and -not $loaded['dav1d.dll'].StartsWith($package+'\',[StringComparison]::OrdinalIgnoreCase)){
+ throw "$name loaded dav1d.dll outside the portable package ($($loaded['dav1d.dll']))"
+ }
if($case.modules -contains 'nvngx_dlssnr.dll'){
$nrFolder=if($name -eq 'ampere-nr'){'runtime/experimental/nr-ampere'}elseif($name -eq 'community-sr-nr-fg'){'runtime/experimental/nr-community'}else{'runtime/experimental'}
$expectedNr=[IO.Path]::GetFullPath((Join-Path $package "$nrFolder/nvngx_dlssnr.dll"))
diff --git a/scripts/build.ps1 b/scripts/build.ps1
index 67d37e8f..19b55c62 100644
--- a/scripts/build.ps1
+++ b/scripts/build.ps1
@@ -9,6 +9,7 @@ param(
[string]$RemotePlayPrefixPath,
[string]$ProtocPath,
[string]$PkgConfigPath,
+ [string]$FfmpegRoot,
[switch]$Clean
)
@@ -74,7 +75,7 @@ else {
# FFmpeg dependency roots (C:\veyra-deps: the project path contains spaces,
# which FFmpeg's build refuses; see loop/JOURNAL.md).
-$ffmpegRoot = "C:\veyra-deps\installed\x64-windows"
+$ffmpegRoot = if ($FfmpegRoot) { [IO.Path]::GetFullPath($FfmpegRoot) } else { "C:\veyra-deps\installed\x64-windows" }
if (Test-Path -LiteralPath (Join-Path $ffmpegRoot "include\libavformat\avformat.h") -PathType Leaf) {
$configureExtra = $configureExtra + (' -DVEYRA_FFMPEG_ROOT="{0}"' -f $ffmpegRoot)
}
@@ -119,6 +120,16 @@ if ($exitCode -eq 0 -and (Test-Path -LiteralPath (Join-Path $buildDir 'veyra.exe
foreach ($name in @('avcodec-63.dll','avformat-63.dll','avutil-61.dll','swresample-7.dll','swscale-10.dll')) {
Copy-Item -LiteralPath (Join-Path $ffmpegRoot "bin/$name") -Destination $buildDir
}
+ # AV1 software decoding is optional at the FFmpeg build level. When the
+ # selected prefix was built with libdav1d, keep its app-local dependency
+ # beside avcodec; never silently copy a system or unrelated dav1d DLL.
+ $dav1d = Join-Path $ffmpegRoot 'bin/dav1d.dll'
+ $stagedDav1d = Join-Path $buildDir 'dav1d.dll'
+ if (Test-Path -LiteralPath $dav1d -PathType Leaf) {
+ Copy-Item -LiteralPath $dav1d -Destination $stagedDav1d -Force
+ } elseif (Test-Path -LiteralPath $stagedDav1d -PathType Leaf) {
+ Remove-Item -LiteralPath $stagedDav1d -Force
+ }
}
Write-Host ("build.ps1: preset {0} exitCode={1}" -f $Preset, $exitCode)
exit $exitCode
diff --git a/scripts/package-portable.ps1 b/scripts/package-portable.ps1
index d9343119..ab9838ce 100644
--- a/scripts/package-portable.ps1
+++ b/scripts/package-portable.ps1
@@ -13,7 +13,19 @@ $stage = Join-Path $resolvedOutput "Veyra-$Version-win64-portable"
$archive = "$stage.zip"
# Preserve existing candidates and their verification evidence.
if ((Test-Path -LiteralPath $stage) -or (Test-Path -LiteralPath $archive)) { throw 'Output exists; choose a new staging directory.' }
+$ffmpegRoot = 'C:\veyra-deps\installed\x64-windows'
+$cachePath = Join-Path $bin 'CMakeCache.txt'
+if (Test-Path -LiteralPath $cachePath -PathType Leaf) {
+ $ffmpegMatch = [regex]::Match((Get-Content -LiteralPath $cachePath -Raw), '(?m)^VEYRA_FFMPEG_ROOT:[^=]*=(.+)$')
+ if ($ffmpegMatch.Success -and -not [string]::IsNullOrWhiteSpace($ffmpegMatch.Groups[1].Value)) {
+ $ffmpegRoot = $ffmpegMatch.Groups[1].Value.Trim()
+ }
+}
+$ffmpegBin = Join-Path $ffmpegRoot 'bin'
$applicationFiles = @('veyra.exe','avcodec-63.dll','avformat-63.dll','avutil-61.dll','swresample-7.dll','swscale-10.dll')
+if (Test-Path -LiteralPath (Join-Path $ffmpegBin 'dav1d.dll') -PathType Leaf) {
+ $applicationFiles += 'dav1d.dll'
+}
if ([version]$Version -ge [version]'0.0.5') {
$cache = Get-Content -LiteralPath (Join-Path $bin 'CMakeCache.txt') -Raw
if ($cache -notmatch 'VEYRA_ENABLE_REMOTEPLAY:BOOL=ON') { throw '0.0.5 package requires the real PS5 backend enabled' }
@@ -83,9 +95,13 @@ foreach ($notice in Get-ChildItem -LiteralPath (Join-Path $resolvedRoot 'third_p
Copy-Payload $notice.FullName "licenses/gpu-dis/licenses/$($notice.Name)"
}
Copy-Payload (Join-Path $resolvedRoot 'runtime_local/config/ngx-local.json') 'runtime/config/ngx-local.json'
-Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/copyright' 'licenses/FFMPEG-COPYRIGHT.txt'
-Copy-Payload 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/vcpkg.spdx.json' 'licenses/FFMPEG-SPDX.json'
-$ffmpegLocalBuild = 'C:/veyra-deps/installed/x64-windows/share/ffmpeg/veyra-local-build.json'
+Copy-Payload (Join-Path $ffmpegRoot 'share/ffmpeg/copyright') 'licenses/FFMPEG-COPYRIGHT.txt'
+Copy-Payload (Join-Path $ffmpegRoot 'share/ffmpeg/vcpkg.spdx.json') 'licenses/FFMPEG-SPDX.json'
+$dav1dCopyright = Join-Path $ffmpegRoot 'share/dav1d/copyright'
+$dav1dSpdx = Join-Path $ffmpegRoot 'share/dav1d/vcpkg.spdx.json'
+if (Test-Path -LiteralPath $dav1dCopyright -PathType Leaf) { Copy-Payload $dav1dCopyright 'licenses/DAV1D-COPYRIGHT.txt' }
+if (Test-Path -LiteralPath $dav1dSpdx -PathType Leaf) { Copy-Payload $dav1dSpdx 'licenses/DAV1D-SPDX.json' }
+$ffmpegLocalBuild = Join-Path $ffmpegRoot 'share/ffmpeg/veyra-local-build.json'
if (Test-Path -LiteralPath $ffmpegLocalBuild) {
$ffmpegBuild = Get-Content -LiteralPath $ffmpegLocalBuild -Raw | ConvertFrom-Json
foreach ($file in $ffmpegBuild.files) {
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index c2230404..93b66da2 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -153,7 +153,13 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
width=image.width;height=image.height;options.fg=false;
{std::lock_guard lock(mutex_);desired_.multiplier=1;snapshot_.image=true;snapshot_.desired=desired_;}
}else{
- source::SourceOpenDesc od;od.path=path;od.preferHardwareDecode=false;
+ source::SourceOpenDesc od;od.path=path;
+ // Files use the same shared D3D12 device as the graph. The
+ // source performs a capability check and falls back to
+ // software before returning its first frame; capture/PS5
+ // retain their own decode contracts.
+ od.preferHardwareDecode=!isCapture;
+ if(od.preferHardwareDecode){od.d3d12Device=ctx.device();od.d3d12Queue=ctx.directQueue();}
// Diagnostic uses the production graph/presenter to validate
// D3D12VA imports without needing a paired PS5 or credentials.
if(!isCapture&&GetEnvironmentVariableW(L"VEYRA_TEST_FILE_HW_DECODE",nullptr,0)){
@@ -178,13 +184,30 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
}else
#endif
if(!(physicalCapture?captureSource.configure(od):activeSource->open(od))){status(L"无法打开视频,请查看诊断",true);break;}
+ // A file's actual decoded pixel format and HDR VUI are only
+ // reliable on AVFrame. Prime one frame before constructing
+ // the graph so AV1/MOV 10-bit and HDR inputs do not get an
+ // SDR graph by mistake. The cloned frame is consumed by the
+ // normal owner-thread loop below, preserving its PTS.
+ if(!isCapture){
+ pipeline::FramePacket firstPacket;const AVFrame* firstFrame=nullptr;
+ const auto firstStatus=activeSource->read(firstPacket,&firstFrame);
+ if(firstStatus!=source::SourceReadStatus::Frame||firstFrame==nullptr||firstPacket.pts.isUnknown()){
+ status(activeSource->info().kind==pipeline::SourceKind::File&&source.errorMessage().empty()
+ ?L"视频首帧无法解码或没有有效时间戳,请查看诊断":source.errorMessage().empty()?L"视频首帧读取失败":source.errorMessage(),true);
+ break;
+ }
+ cachedFrame=av_frame_clone(firstFrame);
+ if(!cachedFrame){status(L"视频首帧缓存失败",true);break;}
+ cachedPacket=firstPacket;
+ }
width=activeSource->info().width;height=activeSource->info().height;duration=isCapture?0:activeSource->info().duration.toDouble();
}
if(!pipeline::Extent{width,height}.valid()){status(L"图像尺寸超出单张GPU纹理能力,需要分块处理",true);break;}
pipeline::EnhanceGraphDesc gd;gd.sourceWidth=width;gd.sourceHeight=height;gd.hdrInput=!isImage&&activeSource->info().color.isHdrPath();
gd.highQualityPresentation=isRemote&&activeSource->info().color.reconstructChroma;
gd.rgbInput=isImage||(isCapture&&activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::Bgra8);
- if(physicalCapture)gd.captureBitDepth=activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P010?10:activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P016?16:8;
+ gd.captureBitDepth=activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P010?10:activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::P016?16:8;
gd.yuy2Input=isCapture&&activeSource->info().color.pixelFormat==pipeline::SourcePixelFormat::Yuy2;gd.stillImage=isImage;
const auto resolution=pipeline::ResolutionPlan::make({width,height},options.sr,options.realtime?pipeline::NrSizePolicy::Realtime:pipeline::NrSizePolicy::Native,isImage,options.settings.revision,options.settings.srTarget,options.settings.lowLatency&&options.nr);
gd.workWidth=resolution.base.width;gd.workHeight=resolution.base.height;gd.nrWidth=resolution.nr.width;gd.nrHeight=resolution.nr.height;gd.flowWidth=resolution.flow.width;gd.flowHeight=resolution.flow.height;
@@ -214,6 +237,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
status(isImage?L"图片已增强,可保存PNG/JPEG":std::format(L"{} | 输入 {}×{} / 底图 {}×{} / NR {}×{} / 光流 {}×{} / FG与输出 {}×{} | {}",isRemote?L"PS5 串流":isCapture?L"实时采集":L"播放",width,height,gd.workWidth,gd.workHeight,gd.nrWidth,gd.nrHeight,gd.flowWidth,gd.flowHeight,gd.workWidth,gd.workHeight,gd.nrBeforeSr?L"低延迟 · NR先行后超分":gd.nrWidth<gd.workWidth?L"实时内部处理并回填":L"原生NR(性能成本较高)"));
pipeline::EnhanceGraph::FrameOutputs out;bool reset=true,hasOutput=false,audioRebuffering=false,seekPreviewPending=false;
bool initialRemoteFramePending=isRemote;
+ bool initialFileFramePending=!isImage&&!isCapture;
uint64_t activeSeekId=0;
bool fileAwaitingVideo=true,fileAudioAlignPending=true,fileInputEnded=false;double lastFilePresentedMs=0,lastFilePresentLateness=0;std::deque<double> latenessSamples;
if(!isImage&&!isCapture&&audioPipe.open(path)){
@@ -492,7 +516,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
if(Clock::now()<*sourceGapUntil){advanceLive();waitLive();continue;}
}
pipeline::FramePacket pkt;const AVFrame* frame=imageFrame;
- if(cachedFrame&&(initialRemoteFramePending||(transaction&&(!isCapture||paused_)))){frame=cachedFrame;pkt=cachedPacket;initialRemoteFramePending=false;}
+ if(cachedFrame&&((initialRemoteFramePending||initialFileFramePending)||(transaction&&(!isCapture||paused_)))){frame=cachedFrame;pkt=cachedPacket;initialRemoteFramePending=false;initialFileFramePending=false;}
else if(!isImage){
auto rs=physicalCapture?captureSource.tryRead(pkt,&frame):activeSource->read(pkt,&frame);
// Keep the accepted transaction and rollback state alive until
diff --git a/src/media/FFmpegDemuxer.cpp b/src/media/FFmpegDemuxer.cpp
index 73812af0..05935b7e 100644
--- a/src/media/FFmpegDemuxer.cpp
+++ b/src/media/FFmpegDemuxer.cpp
@@ -137,6 +137,14 @@ int FFmpegDemuxer::videoTimeBaseDen() const
return context_->streams[videoStreamIndex_]->time_base.den;
}
+std::string FFmpegDemuxer::formatName() const
+{
+ if (context_ == nullptr || context_->iformat == nullptr || context_->iformat->name == nullptr) {
+ return {};
+ }
+ return context_->iformat->name;
+}
+
bool FFmpegDemuxer::readVideoPacket(bool& endOfFile)
{
endOfFile = false;
diff --git a/src/media/FFmpegVideoDecoder.cpp b/src/media/FFmpegVideoDecoder.cpp
index a010cd8d..41a735b6 100644
--- a/src/media/FFmpegVideoDecoder.cpp
+++ b/src/media/FFmpegVideoDecoder.cpp
@@ -49,7 +49,19 @@ bool FFmpegVideoDecoder::openSoftware(const AVCodecParameters* codecParameters,
frameTimeBaseNum_ = streamTimeBaseNum;
frameTimeBaseDen_ = streamTimeBaseDen;
- const AVCodec* codec = avcodec_find_decoder(codecParameters->codec_id);
+ // The FFmpeg native AV1 decoder is hardware-path oriented in the
+ // pinned Windows build. When the optional LGPL-compatible dav1d
+ // backend is present, prefer it for software playback so AV1 files do
+ // not fail after the demuxer has already accepted them. Keep the
+ // native decoder as a fallback for installations that do not ship
+ // dav1d (and let the caller report the actual decode error).
+ const AVCodec* codec = nullptr;
+ if (codecParameters->codec_id == AV_CODEC_ID_AV1) {
+ codec = avcodec_find_decoder_by_name("libdav1d");
+ }
+ if (codec == nullptr) {
+ codec = avcodec_find_decoder(codecParameters->codec_id);
+ }
if (codec == nullptr) {
log::error("media", std::format("decoder: no software decoder for codecId={}", static_cast<int>(codecParameters->codec_id)));
return false;
@@ -169,6 +181,30 @@ void FFmpegVideoDecoder::close()
if (context_ != nullptr) {
avcodec_free_context(&context_);
}
+ hwAccelActive_ = false;
+ lastFrameFormat_ = -1;
+ gpuQueueWaitCount_ = 0;
+}
+
+bool FFmpegVideoDecoder::hardwareFrameImportable() const
+{
+ if (!hardwareActive() || frame_ == nullptr || frame_->format != AV_PIX_FMT_D3D12) {
+ return false;
+ }
+ auto* d3dFrame = reinterpret_cast<AVD3D12VAFrame*>(frame_->data[0]);
+ if (d3dFrame == nullptr || d3dFrame->texture == nullptr) {
+ return false;
+ }
+ const auto desc = d3dFrame->texture->GetDesc();
+ if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || desc.DepthOrArraySize == 0 ||
+ desc.MipLevels != 1 || desc.SampleDesc.Count != 1) {
+ return false;
+ }
+ if (desc.Format != DXGI_FORMAT_NV12 && desc.Format != DXGI_FORMAT_P010) {
+ return false;
+ }
+ return context_ != nullptr && desc.Width == static_cast<UINT64>(context_->width) &&
+ desc.Height == static_cast<UINT>(context_->height);
}
int FFmpegVideoDecoder::width() const
diff --git a/src/source/MediaFileSource.cpp b/src/source/MediaFileSource.cpp
index b51d37ca..d5dc0695 100644
--- a/src/source/MediaFileSource.cpp
+++ b/src/source/MediaFileSource.cpp
@@ -4,11 +4,13 @@
#include <climits>
#include <cmath>
#include <format>
+#include <string_view>
#include "veyra/Log.h"
extern "C" {
#include <libavcodec/avcodec.h>
+#include <libavutil/pixdesc.h>
}
namespace veyra::source {
@@ -29,6 +31,36 @@ MediaFileSource::~MediaFileSource()
close();
}
+bool MediaFileSource::fallbackToSoftware(std::string_view reason)
+{
+ if (!decoder_.hardwareActive() || framesRead_ != 0 || path_.empty()) {
+ return false;
+ }
+ veyra::log::warn("source-file", std::format(
+ "D3D12VA first-frame fallback to software reason={} path=redacted", reason));
+ decoder_.close();
+ demuxer_.close();
+ if (!demuxer_.open(path_)) {
+ veyra::log::error("source-file", "software fallback could not reopen demuxer");
+ return false;
+ }
+ const auto* params = demuxer_.videoCodecParameters();
+ if (params == nullptr || !decoder_.openSoftware(params, demuxer_.videoTimeBaseNum(),
+ demuxer_.videoTimeBaseDen(), params->width > 1920 || params->height > 1080 ? 4u : 1u)) {
+ veyra::log::error("source-file", "software fallback decoder open failed");
+ return false;
+ }
+ info_.hardwareDecodeActive = false;
+ info_.containerName = demuxer_.formatName();
+ info_.videoPixelFormatName = params->format >= 0 && av_get_pix_fmt_name(static_cast<AVPixelFormat>(params->format))
+ ? av_get_pix_fmt_name(static_cast<AVPixelFormat>(params->format)) : "unknown";
+ draining_ = false;
+ eofSignalled_ = false;
+ pendingSeekFlag_ = false;
+ lastPtsUs_ = INT64_MIN;
+ return true;
+}
+
pipeline::ColorDescription MediaFileSource::parseColor(const AVCodecParameters* params) const
{
pipeline::ColorDescription cd;
@@ -80,6 +112,8 @@ pipeline::ColorDescription MediaFileSource::parseColor(const AVCodecParameters*
bool MediaFileSource::open(const SourceOpenDesc& desc)
{
close();
+ path_ = desc.path;
+ preferHardwareDecode_ = desc.preferHardwareDecode && desc.d3d12Device != nullptr && desc.d3d12Queue != nullptr;
if (!demuxer_.open(desc.path)) {
veyra::log::error("source-file", "demuxer open failed");
return false;
@@ -127,7 +161,11 @@ bool MediaFileSource::open(const SourceOpenDesc& desc)
info_.nominalRateNum = demuxer_.nominalRateNum();
info_.nominalRateDen = demuxer_.nominalRateDen();
info_.timestampQuantum = demuxer_.videoTimeBaseDen() > 0 ? double(demuxer_.videoTimeBaseNum()) / demuxer_.videoTimeBaseDen() : 0;
- info_.hardwareDecodeActive = decoder_.usingD3D12Frames();
+ info_.hardwareDecodeActive = decoder_.hardwareActive();
+ info_.containerName = demuxer_.formatName();
+ info_.videoCodecName = avcodec_get_name(params->codec_id);
+ info_.videoPixelFormatName = params->format >= 0 && av_get_pix_fmt_name(static_cast<AVPixelFormat>(params->format))
+ ? av_get_pix_fmt_name(static_cast<AVPixelFormat>(params->format)) : "unknown";
info_.color = parseColor(params);
sequence_ = 0;
@@ -141,10 +179,10 @@ bool MediaFileSource::open(const SourceOpenDesc& desc)
++epoch_; // fresh open = new epoch
veyra::log::info("source-file", std::format(
- "opened {}x{} dur={}s avgFps={:.3f} hw={} matrix={}{} range={}{} transfer={}{}",
+ "opened {}x{} dur={}s avgFps={:.3f} container={} codec={} pixelFmt={} hw={} matrix={}{} range={}{} transfer={}{}",
info_.width, info_.height,
info_.duration.isUnknown() ? -1.0 : info_.duration.toDouble(),
- info_.averageFps, info_.hardwareDecodeActive,
+ info_.averageFps, info_.containerName, info_.videoCodecName, info_.videoPixelFormatName, info_.hardwareDecodeActive,
static_cast<int>(info_.color.matrix), info_.color.matrixAssumed ? "(assumed)" : "",
static_cast<int>(info_.color.range), info_.color.rangeAssumed ? "(assumed)" : "",
static_cast<int>(info_.color.transfer), info_.color.transferAssumed ? "(assumed)" : ""));
@@ -164,7 +202,14 @@ SourceReadStatus MediaFileSource::read(pipeline::FramePacket& out, const AVFrame
if (decoder_.receiveStatus() == media::DecodeReceiveStatus::EndOfStream) {
return SourceReadStatus::Eos;
}
- if (decoder_.receiveStatus() == media::DecodeReceiveStatus::Error || draining_) {
+ if (decoder_.receiveStatus() == media::DecodeReceiveStatus::Error) {
+ if (fallbackToSoftware("decoder-error")) {
+ continue;
+ }
+ errorMessage_ = L"视频解码失败,已停止处理,请检查源文件是否损坏";
+ return SourceReadStatus::Error;
+ }
+ if (draining_) {
errorMessage_ = L"视频解码失败,已停止处理,请检查源文件是否损坏";
return SourceReadStatus::Error;
}
@@ -184,11 +229,22 @@ SourceReadStatus MediaFileSource::read(pipeline::FramePacket& out, const AVFrame
return SourceReadStatus::Error;
}
if (!decoder_.sendPacket(demuxer_.currentPacket())) {
+ if (fallbackToSoftware("send-packet-error")) {
+ continue;
+ }
errorMessage_ = L"视频解码失败,已停止处理,请检查源文件是否损坏";
return SourceReadStatus::Error;
}
}
+ if (decoder_.hardwareActive() && !decoder_.hardwareFrameImportable()) {
+ if (fallbackToSoftware("unsupported-d3d12-surface")) {
+ return read(out, decodedFrame);
+ }
+ errorMessage_ = L"硬件解码输出格式无法导入,且软件回退失败";
+ return SourceReadStatus::Error;
+ }
+
if ((frame->flags & AV_FRAME_FLAG_CORRUPT) || frame->decode_error_flags) {
veyra::log::error("source-file", std::format("corrupt decoded frame flags={} decodeErrors={}", frame->flags, frame->decode_error_flags));
errorMessage_ = L"源视频包含损坏画面,已停止处理";
@@ -218,6 +274,27 @@ SourceReadStatus MediaFileSource::read(pipeline::FramePacket& out, const AVFrame
}
out.sourceKind = pipeline::SourceKind::File;
out.colorInfo = pipeline::resolveFrameColor(*frame,info_.color);
+ // D3D12VA frames expose the underlying surface through AV_PIX_FMT_D3D12,
+ // so resolveFrameColor cannot infer NV12/P010 from frame->format. HDR
+ // hardware surfaces are P010 by contract; SDR surfaces are NV12. Software
+ // AV1/ProRes paths retain the exact planar format mapping above.
+ if (frame->format == AV_PIX_FMT_D3D12 && out.colorInfo.pixelFormat == pipeline::SourcePixelFormat::Unknown) {
+ out.colorInfo.pixelFormat = out.colorInfo.isHdrPath()
+ ? pipeline::SourcePixelFormat::P010 : pipeline::SourcePixelFormat::NV12;
+ }
+ info_.color = out.colorInfo;
+ if (frame->format == AV_PIX_FMT_D3D12) {
+ info_.videoPixelFormatName = out.colorInfo.pixelFormat == pipeline::SourcePixelFormat::P010 ? "p010(d3d12)" : "nv12(d3d12)";
+ } else if (const auto* name = av_get_pix_fmt_name(static_cast<AVPixelFormat>(frame->format))) {
+ info_.videoPixelFormatName = name;
+ }
+ if (framesRead_ == 0) {
+ veyra::log::info("source-file", std::format(
+ "first-frame codec={} format={} hw={} hdr={} matrix={} transfer={} range={} chromaLocation={}",
+ info_.videoCodecName, info_.videoPixelFormatName, decoder_.hardwareActive(), out.colorInfo.isHdrPath(),
+ static_cast<int>(out.colorInfo.matrix), static_cast<int>(out.colorInfo.transfer),
+ static_cast<int>(out.colorInfo.range), static_cast<int>(out.colorInfo.chromaLocation)));
+ }
out.sourceEpoch = epoch_;
uint32_t flags = 0;
@@ -269,6 +346,8 @@ void MediaFileSource::close() noexcept
decoder_.close();
demuxer_.close();
info_ = SourceInfo{};
+ path_.clear();
+ preferHardwareDecode_ = false;
}
} // namespace veyra::source