From 0b8dc1f7af083a3aa0588e89bd7951b55e578b8a Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 19 May 2026 22:20:38 +0800 Subject: [PATCH] fix(video): populate NTV2 fileInfo.time with the real duration (receiver was rendering 00:00) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NTV2 upload request for video carried `time: 0` on the main mp4 sub-file, mirroring NapCat's transformer. But NapCat lives on top of the desktop QQ-NT client's IPC layer, which patches the duration into the resulting MsgInfo before the wire send — we don't have that layer, so the `time: 0` we passed in ended up baked into the `VideoFile. fileTime` field of every video the bot sent. Receivers then rendered every video bubble as "00:00". Cross-checked acidify's `RichMediaUpload.kt::buildVideoUploadInfoList` (2026-04 refactor) — they're a protocol-direct client too and write `time = payload.videoDuration` for exactly this reason. We already have `video.duration` from `loadVideo` (probed via ffprobe), so it's a one-liner. Width/height kept at 0 deliberately — acidify fills them, NapCat zeros them, and our earlier comment recorded "QQ NT server treats non-zero values here as schema mismatch on c2c sends". Out of scope for this fix; revisit if a c2c regression surfaces. Test asserts `fileInfo.time === 10` for the main sub-file (matches FINGERPRINT.duration) and stays 0 on the thumb. --- .../core/src/bridge/highway/video-upload.ts | 20 ++++++++++++++----- .../core/tests/highway/video-upload.test.ts | 15 ++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/core/src/bridge/highway/video-upload.ts b/packages/core/src/bridge/highway/video-upload.ts index 96191ad3..bc7568a6 100644 --- a/packages/core/src/bridge/highway/video-upload.ts +++ b/packages/core/src/bridge/highway/video-upload.ts @@ -480,14 +480,24 @@ export async function uploadVideoMsgInfo( fileHash: video.md5Hex, fileSha1: video.sha1Hex, fileName: 'nya.mp4', - // NapCat sends type.videoFormat=0 and width/height/time=0 - // for the main video sub-file (only the thumb carries - // dimensions). The QQ NT server treats non-zero values - // here as a schema mismatch on c2c sends. type: { type: 2, picFormat: 0, videoFormat: 0, voiceFormat: 0 }, + // Width/height kept at 0 — NapCat does the same and the QQ-NT + // server has been observed to reject non-zero dimensions + // here on c2c sends with a schema-mismatch error. acidify + // *does* fill them (`payload.videoWidth/Height`) but we + // leave that alone until c2c regression coverage exists. height: 0, width: 0, - time: 0, + // `time` MUST be the real duration in seconds, otherwise + // every receiving client renders "00:00" on the video. + // NapCat ships `time: 0` because it sits on top of QQ-NT's + // IPC layer, which the desktop client patches up before + // the wire message goes out. We're a protocol-direct + // client (same position as acidify), so we own this field. + // acidify writes `payload.videoDuration` here for the same + // reason — verified against `RichMediaUpload.kt:: + // buildVideoUploadInfoList` (2026-04 refactor). + time: video.duration, original: 0, }, subFileType: 0, diff --git a/packages/core/tests/highway/video-upload.test.ts b/packages/core/tests/highway/video-upload.test.ts index 00837a7f..0d352d31 100644 --- a/packages/core/tests/highway/video-upload.test.ts +++ b/packages/core/tests/highway/video-upload.test.ts @@ -90,6 +90,21 @@ describe('video-upload', () => { expect((uploadInfo[1] as any).fileInfo.type.type).toBe(1); // pic (thumb) }); + it('main video carries the real `time` (duration in seconds) — regression: was 0', async () => { + // NTV2 server bakes the `time` field into the resulting MsgInfo + // bytes that ride along as `commonElem.pbElem`; the receiver + // reads it back via `VideoFile.fileTime` and renders it as the + // playable duration. NapCat ships `time: 0` only because it sits + // on top of QQ-NT's IPC layer which patches the value in before + // the wire send; we're a protocol-direct client (same position + // as acidify) and must populate it ourselves. Without this the + // receiver shows "00:00" on every video the bot sends. + await uploadVideoMsgInfo({} as any, true, 12345, FINGERPRINT); + const uploadInfo = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploadInfo; + expect((uploadInfo[0] as any).fileInfo.time).toBe(10); // matches FINGERPRINT.duration + expect((uploadInfo[1] as any).fileInfo.time).toBe(0); // thumb stays at 0 (matches acidify) + }); + it('thumb falls back to a synthesized 1x1 PNG with real bytes', async () => { await uploadVideoMsgInfo({} as any, true, 12345, FINGERPRINT); const uploads = vi.mocked(pipeline.runNtv2Upload).mock.calls[0]![0].uploads;