Skip to content

Write HTML. Render video. Built for agents.

fix(engine): reconcile metadata duration after extraction delivers fewer frames (#4371)

xiayewang-heygenb021cb77be16
diff --git a/packages/engine/src/services/videoFrameExtractor.ts b/packages/engine/src/services/videoFrameExtractor.ts
index d456376e5c..2901240b31 100644
--- a/packages/engine/src/services/videoFrameExtractor.ts
+++ b/packages/engine/src/services/videoFrameExtractor.ts
@@ -923,6 +923,20 @@ export async function extractVideoFramesRange(
);
}
+ // Post-extraction reconciliation: when FFmpeg delivers <=60% of the
+ // frames predicted by the probed duration, the duration is likely
+ // inflated (container duration includes a longer audio track). Correct
+ // it so downstream coverage accounting uses the actual video extent.
+ if (framePaths.size > 0 && duration > 0 && !options.finalFrameOnly) {
+ const expectedAtFps = extractionFrameCountForDuration(duration, normalizedFps, metadata.isVFR);
+ if (expectedAtFps > 0 && framePaths.size <= expectedAtFps * 0.6) {
+ const correctedDuration = startTime + framePaths.size / fps;
+ if (correctedDuration < metadata.videoStreamDurationSeconds) {
+ metadata.videoStreamDurationSeconds = correctedDuration;
+ }
+ }
+ }
+
return {
videoId,
srcPath: videoPath,