{"record":{"id":"8d7ab98b943ad038","repo":"mifi/lossless-cut","slug":"cannot-find-any-keyframe-within-60-seconds-of-fram","errorCode":null,"errorMessage":"Cannot find any keyframe within 60 seconds of frame {{time}}","messagePattern":"Cannot find any keyframe within 60 seconds of frame (.+?)\\}","errorType":"exception","errorClass":"UserFacingError","httpStatus":null,"severity":"error","filePath":"src/renderer/src/hooks/useSegments.tsx","lineNumber":518,"sourceCode":"    try {\n      const response = await askForAlignSegments();\n      if (response == null) return;\n      setWorking({ text: i18n.t('Aligning segments to keyframes') });\n      const { mode, startOrEnd } = response;\n      await modifySelectedSegmentTimes(async (segment) => {\n        const newSegment = { ...segment };\n\n        const align = async (key: 'start' | 'end') => {\n          const time = newSegment[key];\n          invariant(filePath != null);\n          if (time != null) {\n            const keyframe = await findKeyframeNearTime({\n              filePath,\n              streamIndex: videoStream.index,\n              time,\n              mode: mode === 'opposing' ? (key === 'start' ? 'before' : 'after') : mode,\n            });\n            if (keyframe == null) throw new UserFacingError(i18n.t('Cannot find any keyframe within 60 seconds of frame {{time}}', { time }));\n            newSegment[key] = keyframe;\n          }\n        };\n        if (startOrEnd.includes('start')) await align('start');\n        if (startOrEnd.includes('end')) await align('end');\n        return newSegment;\n      });\n    } catch (err) {\n      handleError({ err });\n    } finally {\n      setWorking(undefined);\n    }\n  }, [videoStream, workingRef, setWorking, modifySelectedSegmentTimes, filePath, handleError]);\n\n  const updateSegOrder = useCallback((index: number, newOrder: number) => {\n    if (newOrder > cutSegments.length - 1 || newOrder < 0) return;\n    const newSegments = [...cutSegments];\n    const removedSeg = newSegments.splice(index, 1)[0];","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/mifi/lossless-cut/blob/3b9a59c288bf6e11076b583c932cfa48ddab3b02/src/renderer/src/hooks/useSegments.tsx#L500-L536","documentation":"Thrown during keyframe alignment of segments when findKeyframeNearTime() returns null for a start or end boundary. The function probes keyframes near the given time within a bounded window (the 60s referenced in the message), and null means no keyframe was found on the requested side (before/after) of that time. It surfaces from a try/catch that routes the error through handleError.","triggerScenarios":"Invoking the align-segments-to-keyframes action on a segment whose start or end has no keyframe within the probe window on the requested side; aligning 'before' at the file start (no earlier keyframe) or 'after' near the file end (no later keyframe); a keyframe probe that returned empty due to a read error.","commonSituations":"Aligning a segment edge that sits at the extreme start or end of the file; very sparse keyframes (>60s apart) in long-GOP surveillance/HEVC footage; a damaged keyframe index; aligning on a stream type that has no keyframes.","solutions":["Move the segment edge inward so a keyframe exists within 60s on the requested side before aligning.","Re-encode the source with denser keyframes (-g / -force_key_frames) so alignment can succeed.","If aligning at file boundaries is common, skip alignment for edges that are already at the first/last keyframe.","Verify keyframe positions with `ffprobe -select_streams v -show_frames -skip_frame nokey`."],"exampleFix":"// before\nconst keyframe = await findKeyframeNearTime({ filePath, streamIndex, time, mode });\nif (keyframe == null) throw new UserFacingError(...);\n\n// after\nconst keyframe = await findKeyframeNearTime({ filePath, streamIndex, time, mode });\nif (keyframe == null) {\n  // leave the edge unaligned rather than throwing\n  return newSegment;\n}","handlingStrategy":"fallback","validationCode":"const keyframe = await findKeyframeNearTime({ filePath, streamIndex, time, mode });\nif (keyframe == null) {\n  // leave edge unaligned rather than throwing\n  return newSegment;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await alignSegmentsToKeyframes(segments);\n} catch (err) {\n  if (err instanceof UserFacingError && /Cannot find any keyframe within 60 seconds/.test(err.message)) {\n    showError('Could not align one or more edges: no keyframe within 60s.');\n    return segments; // keep unaligned\n  }\n  throw err;\n}","preventionTips":["Move segment edges inward so a keyframe exists within 60s on the requested side before aligning.","Re-encode sources with denser keyframes (-g / -force_key_frames) for reliable alignment.","Skip alignment for edges already at the first/last keyframe (file boundaries).","Verify keyframe spacing with ffprobe before relying on alignment."],"tags":["segments","keyframe","alignment","ffmpeg","validation"],"backgroundTag":null,"analyzedSha":"3b9a59c288bf6e11076b583c932cfa48ddab3b02","analyzedAt":"2026-08-12T20:54:25.651Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}