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(ui-mig): add export queue and rate control

Veyra Goal Agentbabebbb24ab1
diff --git a/docs/UI_FULL_GOAL_PLAN_2026-09-26.md b/docs/UI_FULL_GOAL_PLAN_2026-09-26.md
index 3981c8ba..d6139b31 100644
--- a/docs/UI_FULL_GOAL_PLAN_2026-09-26.md
+++ b/docs/UI_FULL_GOAL_PLAN_2026-09-26.md
@@ -19,7 +19,7 @@
| G2 外壳 | 完成 | checkpoint/ui-mig-g2.5 | G2.1 dock 热区;G2.2 页面切换 sink/rise(探针同曲线);G2.3 视频窗随渲染帧同步;G2.4 拖放/快捷键/V 看原画/电源/导出徽标/toast;G2.5 全屏独立控制窗(CineBar 抽出共用)、1.6s 自动隐藏、Ctrl+L 锁定——PresentMon 未安装,用引擎 present P95 对比显示/隐藏无退化(D1 保留独立窗);显示器休眠期间截图未执行(拖放后画面、全屏条待亮屏复拍);下一步 G3 |
| G3 四主屏 | 进行中(G3.1 完成;极简页小细节暂缓) | checkpoint/ui-mig-g3.1 | R0/R1 窗口分层尚未做完整总验收;用户要求先继续前后端主线 |
| B1 小项 + 桥接补齐 | 部分完成(按垂直切片) | checkpoint/ui-mig-r5.2-a | 预设隔离、导出状态桥接已落地;B1 其余能力仍未完成 |
-| B2 导出补齐(S2.5) | 进行中(R5.2-a/b) | checkpoint/ui-mig-r5.2-b | 已接独立导出预设、分辨率、码率、音轨、剪辑入出点;队列/码率模式/ETA/取消验收仍未完成 |
+| B2 导出补齐(S2.5) | 进行中(R5.2-a/b/c) | checkpoint/ui-mig-r5.2-c | 已接独立导出预设、分辨率、音轨、剪辑入出点、CBR/VBR/CQ、ETA、顺序队列入口;队列自动推进/取消完整运行、MF 实卡路径和性能门槛仍未执行 |
| B3 独立调色 pass(S2.2) | 未开始 | | |
| B4 可排序执行器(S2.3) | 未开始 | | |
| B5 节点链运行(S2.4) | 未开始 | | |
diff --git a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md b/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
index e8910d54..4cc76fc5 100644
--- a/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
+++ b/docs/UI_MIGRATION_EXECUTION_2026-09-25.md
@@ -280,3 +280,11 @@
- 构建命令:`cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && cmake --build E:\项目\Veyra\build\qt-probe-20260926 --target veyra_qml_ui veyra_qml_quick_tests veyra_export_probe --parallel 4'`,exit 0;产物在 `E:\项目\Veyra\build\qt-probe-20260926\`,探针 staging 在 `E:\项目\Veyra\tests\ui-qml-migration-20260925\app\veyra_export_probe.exe`。
- `audio-tracks-fixture.mkv`:`2→5s` exit 0,91 源帧/91 编码帧,视频约 3.033333s、音频约 3.029s;stream 2 英语音轨同样通过。非法 `5→2s` exit 1,证据 `E:\项目\Veyra\logs\ui-qml-migration-20260926\invalid-range.txt`。`7.9→8.02s` 输出 3 帧、约 0.100333s;`7.98→8.02s` 无入点之后的完整帧而拒绝,符合当前合同。日志显示 RTX 5070 / NVENC / D3D12,未发生 GPU→CPU 视频回读。
- Quick Test:`tools/qt_probe/run-quick-tests.ps1 -Out E:\项目\Veyra\logs\ui-qml-migration-20260925\goal\r5.2-b-trim\quick-tests.txt`,9 passed, 0 failed。slider 目视截图、拖动/点击跳转回归、R0/R1 窗口分层总验收:未执行(用户要求暂缓小 UI 细节)。
+
+### R5.2-c(2026-09-26)导出队列与编码策略
+- `ExportRateControl` 从 QML bridge 贯通到 `PlayerOptions`、导出 worker 共享内存、`VideoExportJob`、NVENC 和 Media Foundation;CBR/VBR 没有码率时拒绝,CQ 使用恒定质量路径。
+- `ExportJobManager` 增加顺序等待队列、完成后启动下一项、ETA、队列数和取消时清空等待项;QML 导出页增加策略、ETA、队列入口。页面注释已同步为真实范围。
+- 构建:`cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && cmake --build E:\项目\Veyra\build\qt-probe-20260926 --target veyra_export_probe veyra_qml_quick_tests --parallel 4'`,exit 0;产物:`E:\项目\Veyra\build\qt-probe-20260926\veyra_export_probe.exe`、`E:\项目\Veyra\build\qt-probe-20260926\veyra_qml_quick_tests.exe`。
+- Quick Test:`E:\项目\Veyra\logs\ui-qml-migration-20260925\goal\r5.2-c\quick-tests.txt`,9 passed, 0 failed, 0 skipped。
+- 真实 `audio-tracks-fixture.mkv` NVENC/D3D12:CQ、VBR 6 Mbps、CBR 6 Mbps 均 exit 0,stdout 与 worker 日志记录对应策略;CBR 无码率 exit 2,输出 `CBR/VBR require --bitrate-mbps N` 且没有输出文件。原始 stdout:`cq.stdout.log`、`vbr.stdout.log`、`cbr.stdout.log`、`invalid-cbr.stdout.log`,均在 `E:\项目\Veyra\logs\ui-qml-migration-20260925\goal\r5.2-c\`。
+- 未执行:队列自动推进/取消的完整运行 harness;Media Foundation 实卡路径;B 阶段 hash/perf/delivery/unit 全门槛;导出页截图与真实 UI 多文件操作;缩略图、拖动/点击跳转、R0/R1 窗口分层总验收。旧 worker failure/audio 组合测试未作为本轮通过证据。
diff --git a/docs/UI_MIGRATION_RECOVERY_PLAN_2026-09-26.md b/docs/UI_MIGRATION_RECOVERY_PLAN_2026-09-26.md
index 9023905b..b056e996 100644
--- a/docs/UI_MIGRATION_RECOVERY_PLAN_2026-09-26.md
+++ b/docs/UI_MIGRATION_RECOVERY_PLAN_2026-09-26.md
@@ -16,12 +16,12 @@
## 当前判断
-- 当前 HEAD 为 `8a1be6a`,最后 UI 标签为 `checkpoint/ui-mig-r1.1`;工作区包含已授权的 R5.2-a/b 改动。
+- 当前 HEAD 为 `7444a2d`,最后已提交标签为 `checkpoint/ui-mig-r5.2-b`;工作区包含待提交的 R5.2-c 改动,提交后标签为 `checkpoint/ui-mig-r5.2-c`。
- G0/G1/G2/G3.1 已有代码和证据;R1.1 只修复字幕/音轨菜单遮挡局部问题,R0/R1 窗口分层尚未做完整总验收。
- 用户已确认先继续前后端主线,进度条缩略图、拖动/点击跳转等小 UI 细节暂缓;未验收项仍必须保留“未执行”口径。
- R5.2-a 已完成:导出预设、分辨率和码率状态与播放设置隔离,真实导出探针通过。
- R5.2-b 已完成主路径:剪辑入出点、音轨选择、音画同步和 NVIDIA 零拷贝导出通过;非法范围拒绝;接近文件尾部若没有“入点之后的完整帧”会按合同拒绝。
-- B1/B2 其余能力、G3.3、G3.4、G4、W 尚未完成,不能把垂直切片写成整块 B 阶段完成。
+- R5.2-c 已实现 CBR/VBR/CQ 参数贯通、顺序队列、ETA、取消清空等待队列和多文件选择入口;队列自动推进/取消完整运行、Media Foundation 实卡路径、性能门槛、截图和 R0/R1 窗口分层总验收仍未执行。B1/B2 其余能力、G3.3、G3.4、G4、W 尚未完成,不能把垂直切片写成整块 B 阶段完成。
## 施工规则
@@ -116,4 +116,4 @@
## 下一目标
-当前目标模式继续 **R5.2-c:导出队列与编码策略**。范围限定为顺序队列、CBR/VBR/CQ 真实映射、ETA 和取消路径;完成后再进入 R5.3 独立调色 pass。R0/R1 窗口分层总验收、G3.3/G3.4 和小 UI 细节保留为未完成项,不在本切片中伪装通过。
+当前目标模式继续 **R5.3:独立调色 pass**。R5.2-c 的代码与最小真实 NVENC 策略验证已完成并打 checkpoint;队列自动推进/取消完整运行、Media Foundation 实卡路径、性能门槛、截图和 R0/R1 窗口分层总验收仍未执行。R0/R1 窗口分层总验收、G3.3/G3.4 和小 UI 细节保留为未完成项,不在本切片中伪装通过。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 9c40b249..a081797f 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -6698,3 +6698,9 @@ release. 5090 live acceptance, 15-second hitch and user flicker remain unresolve
- 未执行:多音轨真实切换、全屏/多显示器/DPI 复查、字幕流选择(后端未接入)。R0/R1 窗口分层总验收未据此宣布通过;进度条缩略图、点击跳转和拖动问题仍需单独验收。
- 2026-09-26 / R5.2-b:完成导出剪辑入出点垂直切片。桥接、worker 共享内存和 `VideoExportJob` 传递剪辑范围;视频从首个完整入点帧开始,音频同步裁剪,出点停止写入;QML 导出页 slider 和导出探针参数已接线。`2→5s` 与英语音轨真实 NVENC/D3D12 导出通过,非法范围拒绝,7.9 秒尾段通过;7.98 秒因无入点后的完整帧拒绝,按合同记录。Quick Test 9/9。证据:`E:\项目\Veyra\logs\ui-qml-migration-20260925\goal\r5.2-b-trim\`、`E:\项目\Veyra\logs\ui-qml-migration-20260926\`。slider 目视、拖动/点击跳转、R0/R1 总验收未执行,按用户要求暂缓。下一目标 R5.2-c:导出队列与编码策略。
+### 2026-09-26 / R5.2-c 导出队列与编码策略
+- 实现 CBR/VBR/CQ 从 QML 设置到 NVENC 与 Media Foundation 的真实参数映射;CBR/VBR 无码率拒绝,CQ 走恒定质量。
+- 实现 `ExportJobManager` 顺序等待队列、完成后自动启动下一项、ETA、队列数和取消时清空等待项;导出页增加多文件选择入口、策略、ETA 和队列状态。
+- 构建命令:`cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && cmake --build E:\项目\Veyra\build\qt-probe-20260926 --target veyra_export_probe veyra_qml_quick_tests --parallel 4'`,exit 0。
+- 原始运行证据:`E:\项目\Veyra\logs\ui-qml-migration-20260925\goal\r5.2-c\cq.stdout.log`、`vbr.stdout.log`、`cbr.stdout.log`、`invalid-cbr.stdout.log`、`quick-tests.txt`;三种真实 NVENC/D3D12 策略均成功,Quick Test `9 passed, 0 failed, 0 skipped`,CBR 无码率 exit 2 且无输出。
+- 未执行:队列自动推进/取消完整运行、Media Foundation 实卡、hash/perf/delivery/unit 门槛、导出页截图及用户暂缓的缩略图/进度条/R0/R1 总验收。`veyra_export_worker_failure_tests` 与 `veyra_audio_track_output_tests` 的混合结果不纳入本轮通过证据。
diff --git a/include/veyra/engine/EngineController.h b/include/veyra/engine/EngineController.h
index 324cfe0a..8b2a1bf5 100644
--- a/include/veyra/engine/EngineController.h
+++ b/include/veyra/engine/EngineController.h
@@ -13,6 +13,7 @@
#include "veyra/sink/CaptureAudioSession.h"
#include "veyra/remoteplay/SessionInbox.h"
#include "veyra/media/AudioTrack.h"
+#include "veyra/sink/VideoEncoder.h"
namespace veyra::source { struct RemotePlayConnectDesc; class RemotePlaySessionSource; }
namespace veyra::remoteplay { struct ControllerState;struct ControllerFeedback; }
namespace veyra::sink { struct RgbaImage; }
@@ -23,6 +24,7 @@ struct PlayerOptions { bool nr=false,sr=false,fg=false,realtime=true; uint32_t f
int audioStreamIndex=-1; // export selection; -1 selects the container default
double exportStartSeconds=0.0; // export-only trim; first complete frame at/after this time
double exportEndSeconds=0.0; // export-only trim; 0 means source end
+ sink::ExportRateControl exportRateControl=sink::ExportRateControl::Cq;
bool captureReplayForTest=false; // file-backed live scheduler test; never enabled by UI
bool captureCpuUnpack=false; // N1 diagnostic: legacy per-pixel CPU unpack
EnhancementSettings snapshot()const{auto s=settings;s.nr=nr;s.sr=sr;s.multiplier=fg?fgMultiplier:1;s.nrPolicy=realtime?(settings.nrPolicy==pipeline::NrSizePolicy::Native?pipeline::NrSizePolicy::Realtime:settings.nrPolicy):pipeline::NrSizePolicy::Native;return s;}
diff --git a/include/veyra/engine/ExportJobManager.h b/include/veyra/engine/ExportJobManager.h
index 60e86781..cf963d6d 100644
--- a/include/veyra/engine/ExportJobManager.h
+++ b/include/veyra/engine/ExportJobManager.h
@@ -1,6 +1,7 @@
#pragma once
#include "veyra/engine/EngineController.h"
#include <memory>
+#include <vector>
namespace veyra::engine {
enum class ExportState { Idle, Preparing, Running, Paused, Finishing, Succeeded, Failed, Cancelled };
struct ExportJobSnapshot {
@@ -10,6 +11,8 @@ struct ExportJobSnapshot {
EnhancementSettings frozen;
std::wstring message,output,workerLog;
uint32_t workerPid=0;
+ double etaSeconds=0;
+ uint64_t queuePosition=0,queued=0;
bool active()const{return state>=ExportState::Preparing&&state<=ExportState::Finishing;}
};
// One isolated NGX context in a child process. Anonymous inherited mapping is
@@ -17,7 +20,10 @@ struct ExportJobSnapshot {
class ExportJobManager {
public:
ExportJobManager();~ExportJobManager();
- bool start(const std::wstring&,const std::wstring&,EnhancementSettings,bool hevc,unsigned maxFrames=0,int audioStreamIndex=-1,double trimStartSeconds=0.0,double trimEndSeconds=0.0);
+ bool start(const std::wstring&,const std::wstring&,EnhancementSettings,bool hevc,unsigned maxFrames=0,int audioStreamIndex=-1,double trimStartSeconds=0.0,double trimEndSeconds=0.0,sink::ExportRateControl rateControl=sink::ExportRateControl::Cq);
+ bool enqueue(const std::wstring&,const std::wstring&,EnhancementSettings,bool hevc,unsigned maxFrames=0,int audioStreamIndex=-1,double trimStartSeconds=0.0,double trimEndSeconds=0.0,sink::ExportRateControl rateControl=sink::ExportRateControl::Cq);
+ void clearQueue();
+ size_t queuedCount() const;
void cancel();void pause(bool);void watching(bool);
ExportJobSnapshot poll();
private:struct Impl;std::unique_ptr<Impl> p_;
diff --git a/include/veyra/sink/VideoEncoder.h b/include/veyra/sink/VideoEncoder.h
index d10ad139..fa2bf95f 100644
--- a/include/veyra/sink/VideoEncoder.h
+++ b/include/veyra/sink/VideoEncoder.h
@@ -20,6 +20,16 @@ namespace veyra::pipeline { class EnhanceGraph; }
namespace veyra::sink {
+enum class ExportRateControl : uint32_t { Cbr = 0, Vbr = 1, Cq = 2 };
+constexpr std::string_view exportRateControlName(ExportRateControl mode) {
+ switch (mode) {
+ case ExportRateControl::Cbr: return "CBR";
+ case ExportRateControl::Vbr: return "VBR";
+ case ExportRateControl::Cq: return "CQ";
+ }
+ return "unknown";
+}
+
// (bitstream, bytes, output frame index, keyframe) -> accepted?
using PacketWriter=std::function<bool(const uint8_t*,size_t,int64_t,bool)>;
@@ -41,6 +51,7 @@ struct EncoderConfig {
// Export target bitrate in Mbps; 0 keeps the backend's constant-quality
// default (NVENC CONSTQP / MFT quality mode).
uint32_t bitrateMbps=0;
+ ExportRateControl rateControl=ExportRateControl::Cq;
// Active adapter identity. A machine can have several vendors' hardware
// MFTs registered at once (an AMD driver's MFT is visible on an NVIDIA
// host), so the Media Foundation path must prefer the MFT of the GPU that
diff --git a/include/veyra/ui/QmlPlayerBridge.h b/include/veyra/ui/QmlPlayerBridge.h
index 4184c8ae..ed814f7f 100644
--- a/include/veyra/ui/QmlPlayerBridge.h
+++ b/include/veyra/ui/QmlPlayerBridge.h
@@ -223,6 +223,9 @@ class QmlPlayerBridge : public QObject {
Q_PROPERTY(int exportGenerated READ exportGenerated NOTIFY exportChanged)
Q_PROPERTY(bool exportHevc READ exportHevc WRITE setExportHevc NOTIFY exportChanged)
Q_PROPERTY(int exportBitrateMbps READ exportBitrateMbps WRITE setExportBitrateMbps NOTIFY exportChanged)
+ Q_PROPERTY(int exportRateControl READ exportRateControl WRITE setExportRateControl NOTIFY exportChanged)
+ Q_PROPERTY(double exportEtaSeconds READ exportEtaSeconds NOTIFY exportChanged)
+ Q_PROPERTY(int exportQueueCount READ exportQueueCount NOTIFY exportChanged)
// The preset the export will use. The design requires export to select a
// preset (list or node) rather than assembling effects separately.
Q_PROPERTY(QString exportPresetName READ exportPresetName NOTIFY exportChanged)
@@ -432,6 +435,10 @@ public:
void setExportHevc(bool value);
int exportBitrateMbps() const;
void setExportBitrateMbps(int value);
+ int exportRateControl() const;
+ void setExportRateControl(int value);
+ double exportEtaSeconds() const;
+ int exportQueueCount() const;
QString exportPresetName() const;
int exportSrTargetIndex() const;
void setExportSrTargetIndex(int index);
@@ -493,6 +500,8 @@ public:
// The export target without the dialog (the dialog's result, or --export-out in a test).
void setExportPath(const QString& path);
Q_INVOKABLE void startExport();
+ Q_INVOKABLE void enqueueExportFile(const QString& input, const QString& output);
+ Q_INVOKABLE void addExportFilesDialog();
Q_INVOKABLE void cancelExport();
Q_INVOKABLE void pauseExport(bool paused);
Q_INVOKABLE void quit();
diff --git a/qml/Veyra/ExportPage.qml b/qml/Veyra/ExportPage.qml
index a244cc97..b712bbb7 100644
--- a/qml/Veyra/ExportPage.qml
+++ b/qml/Veyra/ExportPage.qml
@@ -4,9 +4,10 @@
// card spans rows 2-3 on the left; the video sits in the middle with the trim range
// under it; output settings fill the right column.
//
-// Scope, stated on the page rather than hidden: this build has no multi-file queue.
-// What is real - preset selection, codec, output size, bitrate and progress - is
-// wired to the engine's export job.
+// Scope: preset selection, codec, output size, rate control, queueing and
+// progress are wired to the engine's export job. Queue execution is serialized
+// by ExportJobManager; full multi-file cancellation/ordering acceptance remains
+// a separate runtime check.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
@@ -32,7 +33,7 @@ VPage {
font.pixelSize: Theme.fsBody
}
Item { Layout.fillWidth: true }
- VButton { text: "添加文件"; onClicked: veyra.openFileDialog() }
+ VButton { text: "添加文件"; onClicked: veyra.addExportFilesDialog() }
}
// --- left column: what is being exported ------------------------------
@@ -71,11 +72,17 @@ VPage {
font.pixelSize: Theme.fsSmall
}
Rectangle { Layout.fillWidth: true; implicitHeight: 1; color: Theme.stroke }
- // The design's card is a queue of several files. The engine exports one
- // at a time, so no queue is drawn and the card says why.
Text {
+ visible: veyra.exportQueueCount > 0
Layout.fillWidth: true
- text: "本版本一次导出当前打开的一个文件;多文件队列尚未实现。"
+ text: "等待队列 " + veyra.exportQueueCount + " 项"
+ color: Theme.accent
+ font.family: Theme.fontMono
+ font.pixelSize: 11
+ }
+ Text {
+ Layout.fillWidth: true
+ text: "按加入顺序逐项导出;每项独立保留 partial。"
color: Theme.t3
font.family: Theme.fontUi
font.pixelSize: 11
@@ -142,6 +149,14 @@ VPage {
onMoved: veyra.exportBitrateMbps = Math.round(value)
}
}
+ VRow {
+ label: "策略"
+ VSeg {
+ options: [{ id: "0", label: "CBR" }, { id: "1", label: "VBR" }, { id: "2", label: "CQ" }]
+ current: String(veyra.exportRateControl)
+ onPicked: id => veyra.exportRateControl = parseInt(id)
+ }
+ }
}
VGroup {
@@ -169,7 +184,8 @@ VPage {
spacing: 3
Text {
text: (veyra.exportHevc ? "HEVC" : "H.264") + " · "
- + (veyra.exportBitrateMbps > 0 ? veyra.exportBitrateMbps + " Mbps" : "恒定质量")
+ + (["CBR", "VBR", "CQ"][veyra.exportRateControl]) + " · "
+ + (veyra.exportBitrateMbps > 0 ? veyra.exportBitrateMbps + " Mbps" : "自动质量")
color: Theme.t2
font.family: Theme.fontMono
font.pixelSize: Theme.fsSmall
@@ -223,6 +239,13 @@ VPage {
font.family: Theme.fontMono
font.pixelSize: 11
}
+ Text {
+ visible: veyra.exportRunning && veyra.exportEtaSeconds > 0
+ text: "剩余约 " + veyra.formatTime(veyra.exportEtaSeconds)
+ color: Theme.t3
+ font.family: Theme.fontMono
+ font.pixelSize: 11
+ }
}
Rectangle {
Layout.fillWidth: true
diff --git a/src/engine/ExportJobManager.cpp b/src/engine/ExportJobManager.cpp
index c472276f..11945b02 100644
--- a/src/engine/ExportJobManager.cpp
+++ b/src/engine/ExportJobManager.cpp
@@ -7,6 +7,7 @@
#include <format>
#include <chrono>
#include <type_traits>
+#include <deque>
namespace veyra::engine {
namespace {
std::string utf8(std::wstring_view value) {
@@ -22,13 +23,14 @@ struct Shared {
// chain is fixed-capacity and trivially copyable, so it can cross the
// process boundary; a worker that sees another version refuses the job
// instead of reading a mismatched layout.
- DWORD signature=magic,version=3,bytes=sizeof(Shared);
+ DWORD signature=magic,version=4,bytes=sizeof(Shared);
EnhancementSettings settings;
EffectChain chain;
wchar_t input[32768]{},output[32768]{};
unsigned hevc=0,maxFrames=0;
int audioStreamIndex=-1;
double trimStartSeconds=0.0,trimEndSeconds=0.0;
+ uint32_t rateControl=uint32_t(sink::ExportRateControl::Cq);
volatile LONG64 sourceFrames=0,generated=0,holds=0,encoded=0;
volatile LONG messageLock=0;wchar_t message[1024]{};
volatile LONG cancel=0,pause=0,watching=0,state=LONG(ExportState::Preparing),progress=0;
@@ -39,7 +41,9 @@ const wchar_t* label(ExportState s){switch(s){case ExportState::Preparing:return
}
struct ExportJobManager::Impl {
HANDLE mapping=nullptr,process=nullptr,job=nullptr;Shared* shared=nullptr;
- ExportJobSnapshot snapshot;ULONGLONG cancelAt=0;
+ ExportJobSnapshot snapshot;ULONGLONG cancelAt=0,startTick=0;
+ struct Request { std::wstring input,output; EnhancementSettings settings; bool hevc=false; unsigned maxFrames=0; int audioStreamIndex=-1; double trimStart=0,trimEnd=0; sink::ExportRateControl rateControl=sink::ExportRateControl::Cq; };
+ std::deque<Request> queue;
void clear(){if(shared){UnmapViewOfFile(shared);shared=nullptr;}close(process);close(job);close(mapping);cancelAt=0;}
~Impl(){clear();}
};
@@ -47,18 +51,19 @@ ExportJobManager::ExportJobManager():p_(std::make_unique<Impl>()){}
// Shutdown is bounded: the job object is KILL_ON_CLOSE, so a worker still
// draining NVENC is terminated by clear() after a short grace instead of
// stalling process exit for up to five seconds.
-ExportJobManager::~ExportJobManager(){cancel();if(p_->process)WaitForSingleObject(p_->process,1000);p_->clear();}
-bool ExportJobManager::start(const std::wstring& input,const std::wstring& output,EnhancementSettings settings,bool hevc,unsigned maxFrames,int audioStreamIndex,double trimStartSeconds,double trimEndSeconds){
+ExportJobManager::~ExportJobManager(){cancel();clearQueue();if(p_->process)WaitForSingleObject(p_->process,1000);p_->clear();}
+bool ExportJobManager::start(const std::wstring& input,const std::wstring& output,EnhancementSettings settings,bool hevc,unsigned maxFrames,int audioStreamIndex,double trimStartSeconds,double trimEndSeconds,sink::ExportRateControl rateControl){
if(poll().active())return false;p_->clear();p_->snapshot={};
auto fail=[&](const wchar_t* message){const DWORD error=GetLastError();p_->clear();p_->snapshot.state=ExportState::Failed;p_->snapshot.message=message;log::error("export-worker",std::format("launch failed error={}",error));return false;};
if(input.empty()||output.empty()||input.size()>=32768||output.size()>=32768||!settings.validate().empty()||input.starts_with(L"capture:")||input.starts_with(L"capture2:"))return fail(L"请选择本地视频与有效导出设置");
+ if(rateControl!=sink::ExportRateControl::Cq&&settings.exportBitrateMbps==0)return fail(L"CBR/VBR 需要指定码率;CQ 不使用码率");
if(std::filesystem::exists(output)||std::filesystem::exists(output+L".partial"))return fail(L"输出或partial文件已存在,请选择新文件名");
SECURITY_ATTRIBUTES sa{sizeof(sa),nullptr,TRUE};
p_->mapping=CreateFileMappingW(INVALID_HANDLE_VALUE,&sa,PAGE_READWRITE,0,sizeof(Shared),nullptr);
if(!p_->mapping)return fail(L"无法创建导出通信资源");
p_->shared=static_cast<Shared*>(MapViewOfFile(p_->mapping,FILE_MAP_ALL_ACCESS,0,0,sizeof(Shared)));if(!p_->shared)return fail(L"无法映射导出通信资源");
if(!std::isfinite(trimStartSeconds)||!std::isfinite(trimEndSeconds)||trimStartSeconds<0||trimEndSeconds<0||(trimEndSeconds>0&&trimEndSeconds<=trimStartSeconds))return fail(L"导出剪辑范围无效");
- new(p_->shared) Shared{};auto& s=*p_->shared;s.settings=settings;s.settings.nrPolicy=pipeline::NrSizePolicy::Native;s.chain=toChain(s.settings);s.hevc=hevc;s.maxFrames=maxFrames;
+ new(p_->shared) Shared{};auto& s=*p_->shared;s.settings=settings;s.settings.nrPolicy=pipeline::NrSizePolicy::Native;s.chain=toChain(s.settings);s.hevc=hevc;s.maxFrames=maxFrames;s.rateControl=uint32_t(rateControl);
s.audioStreamIndex=audioStreamIndex;
s.trimStartSeconds=trimStartSeconds;s.trimEndSeconds=trimEndSeconds;
wcscpy_s(s.input,input.c_str());wcscpy_s(s.output,output.c_str());
@@ -74,17 +79,30 @@ bool ExportJobManager::start(const std::wstring& input,const std::wstring& outpu
if(!started)return fail(L"无法启动导出进程");p_->process=pi.hProcess;
if(!AssignProcessToJobObject(p_->job,p_->process)){TerminateProcess(p_->process,1);CloseHandle(pi.hThread);return fail(L"导出进程隔离失败");}
if(ResumeThread(pi.hThread)==DWORD(-1)){TerminateProcess(p_->process,1);CloseHandle(pi.hThread);return fail(L"无法运行导出进程");}CloseHandle(pi.hThread);
- p_->snapshot.state=ExportState::Preparing;p_->snapshot.output=output;p_->snapshot.jobId=(GetTickCount64()<<16)^pi.dwProcessId;p_->snapshot.frozenRevision=settings.revision;p_->snapshot.frozen=s.settings;
+ p_->snapshot.state=ExportState::Preparing;p_->snapshot.output=output;p_->snapshot.jobId=(GetTickCount64()<<16)^pi.dwProcessId;p_->snapshot.frozenRevision=settings.revision;p_->snapshot.frozen=s.settings;p_->startTick=GetTickCount64();
p_->snapshot.workerPid=pi.dwProcessId;
p_->snapshot.workerLog=std::filesystem::absolute(runtime::logsDirectory()/std::format("export-worker-{}.log",pi.dwProcessId)).wstring();
log::info("export-worker",std::format("started jobId={} pid={} frozenRevision={} nativeNR=true independentPlayback=true log={}",p_->snapshot.jobId,pi.dwProcessId,settings.revision,std::filesystem::path(p_->snapshot.workerLog).string()));return true;
}
-void ExportJobManager::cancel(){if(p_->shared&&p_->snapshot.active()){InterlockedExchange(&p_->shared->cancel,1);if(!p_->cancelAt)p_->cancelAt=GetTickCount64();}}
+bool ExportJobManager::enqueue(const std::wstring& input,const std::wstring& output,EnhancementSettings settings,bool hevc,unsigned maxFrames,int audioStreamIndex,double trimStartSeconds,double trimEndSeconds,sink::ExportRateControl rateControl){
+ if(poll().active()){p_->queue.push_back({input,output,settings,hevc,maxFrames,audioStreamIndex,trimStartSeconds,trimEndSeconds,rateControl});return true;}
+ return start(input,output,settings,hevc,maxFrames,audioStreamIndex,trimStartSeconds,trimEndSeconds,rateControl);
+}
+void ExportJobManager::clearQueue(){p_->queue.clear();}
+size_t ExportJobManager::queuedCount() const{return p_->queue.size();}
+void ExportJobManager::cancel(){if(p_->shared&&p_->snapshot.active()){InterlockedExchange(&p_->shared->cancel,1);if(!p_->cancelAt)p_->cancelAt=GetTickCount64();}p_->queue.clear();}
void ExportJobManager::pause(bool v){if(p_->shared)InterlockedExchange(&p_->shared->pause,v);}
void ExportJobManager::watching(bool v){if(p_->shared)InterlockedExchange(&p_->shared->watching,v);}
ExportJobSnapshot ExportJobManager::poll(){
- if(!p_->shared)return p_->snapshot;
- auto& s=*p_->shared;p_->snapshot.sourceFrames=InterlockedCompareExchange64(&s.sourceFrames,0,0);p_->snapshot.generated=InterlockedCompareExchange64(&s.generated,0,0);p_->snapshot.holds=InterlockedCompareExchange64(&s.holds,0,0);p_->snapshot.encoded=InterlockedCompareExchange64(&s.encoded,0,0);p_->snapshot.state=static_cast<ExportState>(InterlockedCompareExchange(&s.state,0,0));p_->snapshot.progress=InterlockedCompareExchange(&s.progress,0,0)/10000.0;
+ if(!p_->shared&&!p_->queue.empty()){
+ auto next=std::move(p_->queue.front());p_->queue.pop_front();
+ if(!start(next.input,next.output,next.settings,next.hevc,next.maxFrames,next.audioStreamIndex,next.trimStart,next.trimEnd,next.rateControl)){
+ p_->snapshot.queuePosition=0;p_->snapshot.queued=p_->queue.size();return p_->snapshot;
+ }
+ }
+ if(!p_->shared){p_->snapshot.queued=p_->queue.size();return p_->snapshot;}
+ auto& s=*p_->shared;p_->snapshot.sourceFrames=InterlockedCompareExchange64(&s.sourceFrames,0,0);p_->snapshot.generated=InterlockedCompareExchange64(&s.generated,0,0);p_->snapshot.holds=InterlockedCompareExchange64(&s.holds,0,0);p_->snapshot.encoded=InterlockedCompareExchange64(&s.encoded,0,0);p_->snapshot.state=static_cast<ExportState>(InterlockedCompareExchange(&s.state,0,0));p_->snapshot.progress=InterlockedCompareExchange(&s.progress,0,0)/10000.0;p_->snapshot.queued=p_->queue.size();p_->snapshot.queuePosition=p_->queue.empty()?0:1;
+ if(p_->snapshot.progress>0.001&&p_->startTick){const double elapsed=double(GetTickCount64()-p_->startTick)/1000.0;p_->snapshot.etaSeconds=std::max(0.0,elapsed*(1.0-p_->snapshot.progress)/p_->snapshot.progress);}else p_->snapshot.etaSeconds=0;
if(p_->cancelAt&&GetTickCount64()-p_->cancelAt>5000&&WaitForSingleObject(p_->process,0)==WAIT_TIMEOUT)TerminateJobObject(p_->job,3);
if(WaitForSingleObject(p_->process,0)==WAIT_OBJECT_0){DWORD code=1;GetExitCodeProcess(p_->process,&code);p_->snapshot.state=code==0?ExportState::Succeeded:code==3||p_->cancelAt?ExportState::Cancelled:ExportState::Failed;if(code==0)p_->snapshot.progress=1;
// Preserve the worker's actual outcome, including codec substitutions.
@@ -94,12 +112,17 @@ ExportJobSnapshot ExportJobManager::poll(){
log::info("export-worker",std::format("finished jobId={} pid={} exit={} state={} source={} generated={} holds={} encoded={} log={}",final.jobId,final.workerPid,code,int(final.state),final.sourceFrames,final.generated,final.holds,final.encoded,std::filesystem::path(final.workerLog).string()));
log::info("export-worker",utf8(final.message));
if(final.state==ExportState::Failed)p_->snapshot.message+=L"\n日志:"+final.workerLog;
- p_->clear();}
+ p_->clear();
+ if(!p_->queue.empty()){
+ auto next=std::move(p_->queue.front());p_->queue.pop_front();
+ if(!start(next.input,next.output,next.settings,next.hevc,next.maxFrames,next.audioStreamIndex,next.trimStart,next.trimEnd,next.rateControl))p_->snapshot.queued=p_->queue.size();
+ }
+ }
if(p_->shared&&InterlockedCompareExchange(&p_->shared->messageLock,1,0)==0){if(p_->shared->message[0])p_->snapshot.message=p_->shared->message;InterlockedExchange(&p_->shared->messageLock,0);}if(p_->snapshot.message.empty()||p_->snapshot.state==ExportState::Paused||p_->snapshot.state==ExportState::Cancelled)p_->snapshot.message=label(p_->snapshot.state);return p_->snapshot;
}
int runExportWorker(HANDLE mapping){
auto s=static_cast<Shared*>(MapViewOfFile(mapping,FILE_MAP_ALL_ACCESS,0,0,sizeof(Shared)));if(!s)return 1;
- if(s->signature!=magic||s->version!=3||s->bytes!=sizeof(Shared)||s->audioStreamIndex< -1||!std::isfinite(s->trimStartSeconds)||!std::isfinite(s->trimEndSeconds)||s->trimStartSeconds<0||s->trimEndSeconds<0||(s->trimEndSeconds>0&&s->trimEndSeconds<=s->trimStartSeconds)||!s->settings.validate().empty()||s->input[32767]||s->output[32767]){UnmapViewOfFile(s);CloseHandle(mapping);return 1;}
+ if(s->signature!=magic||s->version!=4||s->bytes!=sizeof(Shared)||s->audioStreamIndex< -1||s->rateControl>uint32_t(sink::ExportRateControl::Cq)||!std::isfinite(s->trimStartSeconds)||!std::isfinite(s->trimEndSeconds)||s->trimStartSeconds<0||s->trimEndSeconds<0||(s->trimEndSeconds>0&&s->trimEndSeconds<=s->trimStartSeconds)||!s->settings.validate().empty()||s->input[32767]||s->output[32767]){UnmapViewOfFile(s);CloseHandle(mapping);return 1;}
Logger::instance().openFile((runtime::logsDirectory()/std::format("export-worker-{}.log",GetCurrentProcessId())).wstring());
// The chain is the description of record for this job; the settings struct
// stays the runtime input until the executor consumes chains directly.
@@ -116,7 +139,7 @@ int runExportWorker(HANDLE mapping){
if(InterlockedCompareExchange(&s->watching,0,0))for(int i=0;i<5&&!cancel;++i)std::this_thread::sleep_for(std::chrono::milliseconds(10));
return !cancel;
};
- auto options=PlayerOptions::from(settings);options.audioStreamIndex=s->audioStreamIndex;options.exportStartSeconds=s->trimStartSeconds;options.exportEndSeconds=s->trimEndSeconds;
+ auto options=PlayerOptions::from(settings);options.audioStreamIndex=s->audioStreamIndex;options.exportStartSeconds=s->trimStartSeconds;options.exportEndSeconds=s->trimEndSeconds;options.exportRateControl=static_cast<sink::ExportRateControl>(s->rateControl);
bool ok=false;try{ok=exportVideo(s->input,s->output,options,s->hevc!=0,cancel,[&](double p,const std::wstring& message){if(InterlockedCompareExchange(&s->messageLock,1,0)==0){wcsncpy_s(s->message,message.c_str(),_TRUNCATE);InterlockedExchange(&s->messageLock,0);}
InterlockedExchange(&s->progress,LONG(std::clamp(p,0.0,.999)*10000));if(p>=.99)InterlockedExchange(&s->state,LONG(ExportState::Finishing));},s->maxFrames,frameBoundary,[&](const ExportCounts& count){InterlockedExchange64(&s->sourceFrames,count.source);InterlockedExchange64(&s->generated,count.generated);InterlockedExchange64(&s->holds,count.holds);InterlockedExchange64(&s->encoded,count.encoded);});}catch(...){log::error("export-worker","unhandled job exception");}
done=true;monitor.join();InterlockedExchange(&s->state,LONG(ok?ExportState::Succeeded:cancel?ExportState::Cancelled:ExportState::Failed));UnmapViewOfFile(s);CloseHandle(mapping);return ok?0:cancel?3:1;
diff --git a/src/engine/VideoExportJob.cpp b/src/engine/VideoExportJob.cpp
index 536bc552..c0185996 100644
--- a/src/engine/VideoExportJob.cpp
+++ b/src/engine/VideoExportJob.cpp
@@ -200,7 +200,7 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
};
// Must drain before rate/writeAudioUntil/writer leave scope, including cancel/error.
struct EncoderCloser {std::unique_ptr<sink::VideoEncoder>& encoder;~EncoderCloser(){encoder.reset();}} closer{encoder};
- sink::EncoderConfig encoderConfig;encoderConfig.hevc=hevc;encoderConfig.fpsNum=unsigned(rate.num);encoderConfig.fpsDen=unsigned(rate.den);encoderConfig.bitrateMbps=options.settings.exportBitrateMbps;
+ sink::EncoderConfig encoderConfig;encoderConfig.hevc=hevc;encoderConfig.fpsNum=unsigned(rate.num);encoderConfig.fpsDen=unsigned(rate.den);encoderConfig.bitrateMbps=options.settings.exportBitrateMbps;encoderConfig.rateControl=options.exportRateControl;
std::wstring encoderDetail;
encoder=sink::openVideoEncoder(ctx,ring,graph,encoderConfig,writer,encoderDetail);
if(!encoder){
@@ -210,7 +210,7 @@ bool exportVideo(const std::wstring& input,const std::wstring& output,PlayerOpti
break;
}
encoderName=encoder->describe();
- veyra::log::info("export",std::format("encoder={} codec={} bitrateMbps={} rate={}/{}",std::string(sink::encoderBackendName(encoder->backend())),hevc?"HEVC":"H264",encoderConfig.bitrateMbps,rate.num,rate.den));
+ veyra::log::info("export",std::format("encoder={} codec={} rateControl={} bitrateMbps={} rate={}/{}",std::string(sink::encoderBackendName(encoder->backend())),hevc?"HEVC":"H264",std::string(sink::exportRateControlName(encoderConfig.rateControl)),encoderConfig.bitrateMbps,rate.num,rate.den));
auto headers=encoder->headers();cp->extradata=static_cast<uint8_t*>(av_mallocz(headers.size()+AV_INPUT_BUFFER_PADDING_SIZE));if(!cp->extradata)break;memcpy(cp->extradata,headers.data(),headers.size());cp->extradata_size=int(headers.size());
int muxResult=avio_open(&mux->pb,utf8(partial).c_str(),AVIO_FLAG_WRITE);
if(muxResult<0){failAv(L"创建输出文件",muxResult);break;}
diff --git a/src/sink/MfVideoEncoder.cpp b/src/sink/MfVideoEncoder.cpp
index 21b18ec3..f0a5d827 100644
--- a/src/sink/MfVideoEncoder.cpp
+++ b/src/sink/MfVideoEncoder.cpp
@@ -178,6 +178,7 @@ private:
bool check(HRESULT hr,const wchar_t* stage){if(SUCCEEDED(hr))return true;error_=std::format(L"{} HRESULT=0x{:08X}",stage,unsigned(hr));log::error("mf-encoder",std::string(error_.begin(),error_.end()));return false;}
bool hevc_=false;
uint32_t bitrateMbps_=0;
+ ExportRateControl rateControl_=ExportRateControl::Cq;
unsigned fpsNum_=1,fpsDen_=1;
uint32_t width_=0,height_=0;
ComputePass convert_;
@@ -195,7 +196,7 @@ private:
bool MfVideoEncoder::open(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing& ring,EnhanceGraph& graph,const EncoderConfig& config,PacketWriter writer){
ctx_=&ctx;ring_=&ring;graph_=&graph;writer_=std::move(writer);
- hevc_=config.hevc;bitrateMbps_=config.bitrateMbps;
+ hevc_=config.hevc;bitrateMbps_=config.bitrateMbps;rateControl_=config.rateControl;
fpsNum_=std::max(1u,config.fpsNum);fpsDen_=std::max(1u,config.fpsDen);
width_=graph.workWidth();height_=graph.workHeight();
error_=L"Media Foundation startup failed; see worker log";
@@ -308,7 +309,14 @@ bool MfVideoEncoder::applyRateControl(){
value.ulVal=1;set(kPropLowLatencyMode,value,"LowLatencyMode");
value.ulVal=std::max(1u,fpsNum_*2);set(kPropGOPSize,value,"GOPSize");
value.ulVal=70;set(kPropQualityVsSpeed,value,"QualityVsSpeed");
- if(bitrateMbps_>0){
+ if(rateControl_==ExportRateControl::Cbr){
+ const uint32_t bitsPerSecond=bitrateMbps_*1000000u;
+ value.ulVal=bitsPerSecond;set(kPropMeanBitRate,value,"MeanBitRate");
+ set(kPropMaxBitRate,value,"MaxBitRate");
+ value.ulVal=bitsPerSecond/2;set(kPropBufferSize,value,"BufferSize");
+ value.ulVal=uint32_t(eAVEncCommonRateControlMode_CBR);set(kPropRateControlMode,value,"RateControlMode");
+ log::info("mf-encoder",std::format("rate control CBR target={}Mbps",bitrateMbps_));
+ }else if(rateControl_==ExportRateControl::Vbr){
const uint32_t bitsPerSecond=bitrateMbps_*1000000u;
value.ulVal=bitsPerSecond;set(kPropMeanBitRate,value,"MeanBitRate");
set(kPropMaxBitRate,value,"MaxBitRate");
diff --git a/src/sink/NvencD3D12Encoder.cpp b/src/sink/NvencD3D12Encoder.cpp
index 8cb472bb..1578a51a 100644
--- a/src/sink/NvencD3D12Encoder.cpp
+++ b/src/sink/NvencD3D12Encoder.cpp
@@ -87,7 +87,15 @@ bool NvencD3D12Encoder::open(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&
NV_ENC_PRESET_CONFIG preset{};preset.version=NV_ENC_PRESET_CONFIG_VER;preset.presetCfg.version=NV_ENC_CONFIG_VER;
if(!p.check(p.api.nvEncGetEncodePresetConfigEx(p.encoder,codec,NV_ENC_PRESET_P4_GUID,NV_ENC_TUNING_INFO_LOW_LATENCY,&preset),"GetPreset"))return false;
preset.presetCfg.frameIntervalP=1;preset.presetCfg.gopLength=120;preset.presetCfg.rcParams.enableLookahead=0;
- if(p.bitrateMbps>0){
+ if(config.rateControl==ExportRateControl::Cbr){
+ const uint32_t bitsPerSecond=p.bitrateMbps*1000000u;
+ preset.presetCfg.rcParams.rateControlMode=NV_ENC_PARAMS_RC_CBR;
+ preset.presetCfg.rcParams.averageBitRate=bitsPerSecond;
+ preset.presetCfg.rcParams.maxBitRate=bitsPerSecond;
+ preset.presetCfg.rcParams.vbvBufferSize=bitsPerSecond/2;
+ preset.presetCfg.rcParams.vbvInitialDelay=preset.presetCfg.rcParams.vbvBufferSize;
+ veyra::log::info("nvenc",std::format("rate control CBR target={}Mbps",p.bitrateMbps));
+ }else if(config.rateControl==ExportRateControl::Vbr){
// Explicit user bitrate: VBR with the target as both average and peak,
// which is what "编码码率" means to users (the VBV cap keeps peaks
// bounded so the average is actually met).
diff --git a/src/ui/QmlPlayerBridge.cpp b/src/ui/QmlPlayerBridge.cpp
index 7efff647..bfde7c2f 100644
--- a/src/ui/QmlPlayerBridge.cpp
+++ b/src/ui/QmlPlayerBridge.cpp
@@ -81,6 +81,7 @@ struct QmlPlayerBridge::Impl {
engine::ExportJobSnapshot exportSnapshot;
bool exportHevc = false;
uint32_t exportBitrateMbps = 0;
+ sink::ExportRateControl exportRateControl = sink::ExportRateControl::Cq;
int exportResolutionIndex = -1;
double exportTrimStartSeconds = 0.0;
double exportTrimEndSeconds = 0.0;
@@ -1014,6 +1015,8 @@ QString QmlPlayerBridge::exportTarget() const {
}
int QmlPlayerBridge::exportEncoded() const { return int(impl_->exportSnapshot.encoded); }
int QmlPlayerBridge::exportGenerated() const { return int(impl_->exportSnapshot.generated); }
+double QmlPlayerBridge::exportEtaSeconds() const { return impl_->exportSnapshot.etaSeconds; }
+int QmlPlayerBridge::exportQueueCount() const { return int(impl_->exportSnapshot.queued); }
// HEVC or H.264: the engine's export entry takes this as a flag, so it is a real
// choice with a real effect rather than a label.
@@ -1034,6 +1037,15 @@ void QmlPlayerBridge::setExportBitrateMbps(int value) {
emit exportChanged();
}
+int QmlPlayerBridge::exportRateControl() const { return int(impl_->exportRateControl); }
+void QmlPlayerBridge::setExportRateControl(int value) {
+ if (value < 0 || value > 2) return;
+ const auto want = static_cast<sink::ExportRateControl>(value);
+ if (impl_->exportRateControl == want) return;
+ impl_->exportRateControl = want;
+ emit exportChanged();
+}
+
QString QmlPlayerBridge::exportPresetName() const {
return impl_->exportPresetName.empty() ? tr("当前播放设置") : utf8Of(impl_->exportPresetName);
}
@@ -1294,7 +1306,8 @@ void QmlPlayerBridge::startExport() {
settings, impl_->exportHevc, 0,
impl_->snapshot.selectedAudioTrack,
impl_->exportTrimStartSeconds,
- impl_->exportTrimEndSeconds);
+ impl_->exportTrimEndSeconds,
+ impl_->exportRateControl);
if (!started) { emit notice(tr("导出启动失败;详见诊断"), true); return; }
pollExport();
emit navigate(QStringLiteral("exp"));
@@ -1455,6 +1468,29 @@ bool QmlPlayerBridge::applyPresetIndex(int index) {
emit chainChanged();
return true;
}
+
+void QmlPlayerBridge::enqueueExportFile(const QString& input, const QString& output) {
+ if (input.isEmpty() || output.isEmpty()) { emit notice(tr("队列项目缺少输入或输出"), true); return; }
+ auto settings = impl_->facade.pendingSettings();
+ engine::fromChain(impl_->chain, settings);
+ settings.exportBitrateMbps = impl_->exportBitrateMbps;
+ const bool queued = impl_->exportJob.enqueue(wideOf(input), wideOf(output), settings, impl_->exportHevc, 0,
+ -1, 0.0, 0.0, impl_->exportRateControl);
+ if (!queued) { emit notice(tr("加入导出队列失败;详见诊断"), true); return; }
+ pollExport();
+}
+
+void QmlPlayerBridge::addExportFilesDialog() {
+ const auto files = QFileDialog::getOpenFileNames(nullptr, tr("加入导出队列"), QString(),
+ tr("媒体文件 (*.mp4 *.mkv *.mov *.avi *.webm *.ts *.m2ts);;所有文件 (*)"));
+ if (files.isEmpty()) return;
+ const QString folder = QFileDialog::getExistingDirectory(nullptr, tr("选择队列输出目录"));
+ if (folder.isEmpty()) return;
+ for (const auto& file : files) {
+ const QFileInfo info(file);
+ enqueueExportFile(file, QDir(folder).filePath(info.completeBaseName() + QStringLiteral(".mp4")));
+ }
+}
bool QmlPlayerBridge::selectExportPreset(int index) {
if (index == -1) {
impl_->exportPresetName.clear();
diff --git a/tools/export_probe/main.cpp b/tools/export_probe/main.cpp
index 341b3daf..83982c48 100644
--- a/tools/export_probe/main.cpp
+++ b/tools/export_probe/main.cpp
@@ -5,20 +5,23 @@
//
// veyra_export_probe <input> <output> [--hevc] [--max-frames N]
// [--trim-start seconds] [--trim-end seconds]
-// [--audio-stream index]
+// [--audio-stream index] [--rate-control cbr|vbr|cq]
+// [--bitrate-mbps N]
//
// Exit codes: 0 completed, 1 export refused/failed, 2 bad arguments.
#include "veyra/engine/VideoExportJob.h"
#include <atomic>
+#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
+#include "veyra/sink/VideoEncoder.h"
int wmain(int argc, wchar_t** argv)
{
if (argc < 3) {
- std::fwprintf(stderr, L"usage: veyra_export_probe <input> <output> [--hevc] [--video-hdr] [--max-frames N] [--trim-start seconds] [--trim-end seconds] [--audio-stream index]\n");
+ std::fwprintf(stderr, L"usage: veyra_export_probe <input> <output> [--hevc] [--video-hdr] [--max-frames N] [--trim-start seconds] [--trim-end seconds] [--audio-stream index] [--rate-control cbr|vbr|cq] [--bitrate-mbps N]\n");
return 2;
}
const std::wstring input = argv[1];
@@ -27,6 +30,8 @@ int wmain(int argc, wchar_t** argv)
unsigned maxFrames = 0;
double trimStart = 0.0, trimEnd = 0.0;
int audioStream = -1;
+ auto rateControl = veyra::sink::ExportRateControl::Cq;
+ unsigned bitrateMbps = 0;
for (int i = 3; i < argc; ++i) {
const std::wstring arg = argv[i];
if (arg == L"--hevc") {
@@ -41,6 +46,21 @@ int wmain(int argc, wchar_t** argv)
trimEnd = std::wcstod(argv[++i], nullptr);
} else if (arg == L"--audio-stream" && i + 1 < argc) {
audioStream = int(std::wcstol(argv[++i], nullptr, 10));
+ } else if (arg == L"--rate-control" && i + 1 < argc) {
+ const std::wstring value = argv[++i];
+ if (value == L"cbr") rateControl = veyra::sink::ExportRateControl::Cbr;
+ else if (value == L"vbr") rateControl = veyra::sink::ExportRateControl::Vbr;
+ else if (value == L"cq") rateControl = veyra::sink::ExportRateControl::Cq;
+ else {
+ std::fwprintf(stderr, L"invalid rate control: %ls\n", value.c_str());
+ return 2;
+ }
+ } else if (arg == L"--bitrate-mbps" && i + 1 < argc) {
+ bitrateMbps = unsigned(std::wcstoul(argv[++i], nullptr, 10));
+ if (bitrateMbps > 300) {
+ std::fwprintf(stderr, L"bitrate must be 0..300 Mbps\n");
+ return 2;
+ }
} else {
std::fwprintf(stderr, L"unknown argument: %ls\n", arg.c_str());
return 2;
@@ -52,6 +72,12 @@ int wmain(int argc, wchar_t** argv)
options.exportStartSeconds = trimStart;
options.exportEndSeconds = trimEnd;
options.audioStreamIndex = audioStream;
+ options.exportRateControl = rateControl;
+ options.settings.exportBitrateMbps = bitrateMbps;
+ if (rateControl != veyra::sink::ExportRateControl::Cq && bitrateMbps == 0) {
+ std::fwprintf(stderr, L"CBR/VBR require --bitrate-mbps N\n");
+ return 2;
+ }
std::atomic<bool> cancel{false};
const bool ok = veyra::engine::exportVideo(input, output, options, hevc, cancel,
[](double progress, const std::wstring& message) {