修复DirectShow设置分辨率后丢失MJPG导致帧率减半

This commit is contained in:
tfarcraw 2026-11-18 23:15:19 +08:00
parent 0f6e6def4e
commit 681617f699
2 changed files with 9 additions and 2 deletions

View File

@ -28,6 +28,8 @@ pwsh -File tools/Start-HandAiD3.ps1
主页面只显示运行状态,推理后端诊断记录在运行日志中。SOP 停止采集时保留相机连接;再次开始复用同一设备,USB 参数未改变时不重复设置视频模式。切换相机、设备消失或退出程序时释放连接;采集失败时释放连接以便重试。停止后仍可修改相机配置和编辑配方。
Windows DirectShow 设置分辨率时可能把 MJPG 重置为 YUY2,因此程序在分辨率和帧率设置后再应用视频格式;Linux V4L2 保持先设置格式。2026-11-18 在 USB Camera(0c45:636d)上验证:原顺序在 640×480 和 800×600 下均约 15fps,修复后通过实际 UvcCameraService 采集均约 30fps,格式回读为 MJPG,手动曝光回读 15.625ms。设置接口返回成功和驱动回读 30fps 均不能代替实际采集计数。
SOP 流程视频可在配方编辑器中录制和播放,独立保存在该配方的 `sop_stand` 目录。配方选择和相机选择会记忆;恢复选择不会自动开始采集。
“Agent助手”接收本地标准视频路径,通过工具自主查看不同时间点、继续检查细节,再生成步骤草稿。模型需支持 Chat Completions 工具调用和图片输入,不需要上传完整视频。每次工具读取上限默认 3 张,可修改并记住。草稿包含时间段、参考画面、步骤说明和手部规则,修改后追加到配方,最后手动保存。接口地址、模型名、密钥及生成参数自动保存,下次启动恢复;模型列表可自动获取。运行时仍由 D3-lite 确认步骤完成。详细限制与配置见 [HAND_AI.md](HAND_AI.md)。

View File

@ -135,15 +135,20 @@ public class UvcCameraService : ICameraService
if (!capture.Set(property, value))
throw new InvalidOperationException($"驱动不支持 USB {label},请更换参数或留空使用默认模式");
}
// 先协商传输格式,再协商分辨率和帧率。
if (!string.IsNullOrWhiteSpace(options.Format))
void SetFormat()
{
if (string.IsNullOrWhiteSpace(options.Format)) return;
var format = options.Format.Trim().ToUpperInvariant();
Set(VideoCaptureProperties.FourCC, VideoWriter.FourCC(format[0], format[1], format[2], format[3]), "视频格式 " + format);
}
// DirectShow 设置分辨率会重建媒体类型并将 MJPG 改回 YUY2,最后恢复格式。
// V4L2 仍先设格式,避免用默认原始格式协商高分辨率/帧率。
var formatLast = (VideoCaptureAPIs)capture.Get(VideoCaptureProperties.Backend) == VideoCaptureAPIs.DSHOW;
if (!formatLast) SetFormat();
if (options.Width is { } width) Set(VideoCaptureProperties.FrameWidth, width, "宽度");
if (options.Height is { } height) Set(VideoCaptureProperties.FrameHeight, height, "高度");
if (options.Fps is { } fps) Set(VideoCaptureProperties.Fps, fps, "目标帧率");
if (formatLast) SetFormat();
_exposureOptions = options with { };
var exposureDescription = UvcExposureControl.TryApply(options, (VideoCaptureAPIs)capture.Get(VideoCaptureProperties.Backend),
property => capture.Get(property), (property, value) => capture.Set(property, value));