fix: export frame counter exceeding total frames

This commit is contained in:
Theodor Peifer
2026-04-10 22:24:37 +02:00
parent 68295b21ec
commit d21dd1cbf1
3 changed files with 20 additions and 7 deletions
+16 -3
View File
@@ -536,11 +536,24 @@ export class StreamingVideoDecoder {
return segments;
}
getEffectiveDuration(trimRegions?: TrimRegion[], speedRegions?: SpeedRegion[]): number {
getExportMetrics(
targetFrameRate: number,
trimRegions?: TrimRegion[],
speedRegions?: SpeedRegion[],
): { effectiveDuration: number; totalFrames: number } {
if (!this.metadata) throw new Error("Must call loadMetadata() first");
const trimSegments = this.computeSegments(this.metadata.duration, trimRegions);
const speedSegments = this.splitBySpeed(trimSegments, speedRegions);
return speedSegments.reduce((sum, seg) => sum + (seg.endSec - seg.startSec) / seg.speed, 0);
const segments = this.splitBySpeed(trimSegments, speedRegions);
return {
effectiveDuration: segments.reduce(
(sum, seg) => sum + (seg.endSec - seg.startSec) / seg.speed,
0,
),
totalFrames: segments.reduce(
(sum, seg) => sum + Math.ceil(((seg.endSec - seg.startSec) / seg.speed) * targetFrameRate),
0,
),
};
}
private splitBySpeed(