chore: video section issues

This commit is contained in:
2026-03-20 11:49:12 +05:30
parent 87445d757b
commit 96cc4b6f71
2 changed files with 34 additions and 17 deletions

View File

@@ -69,18 +69,22 @@ export const useFrameDetectionMap = (data: DetectionData, detectionType: string)
return map;
}, [data, detectionType]);
const getNearestDetections = (frame: number, sortedFrameIndices: number[], maxSkip = 3) => {
const sortedDetectionIndices = useMemo(() => {
return Array.from(frameDetectionMap.keys()).sort((a, b) => a - b);
}, [frameDetectionMap]);
const getNearestDetections = (frame: number, sortedIndices: number[], maxSkip = 3) => {
const exact = frameDetectionMap.get(frame);
if (exact) return exact;
let low = 0,
high = sortedFrameIndices.length - 1,
high = sortedIndices.length - 1,
targetIndex = -1;
while (low <= high) {
const mid = Math.floor((low + high) / 2);
if (sortedFrameIndices[mid] <= frame) {
targetIndex = sortedFrameIndices[mid];
if (sortedIndices[mid] <= frame) {
targetIndex = sortedIndices[mid];
low = mid + 1;
} else {
high = mid - 1;
@@ -92,5 +96,5 @@ export const useFrameDetectionMap = (data: DetectionData, detectionType: string)
: undefined;
};
return { frameDetectionMap, getNearestDetections };
return { frameDetectionMap, getNearestDetections, sortedDetectionIndices };
};