From 7d55abb5fcd41e8605c59cb132acd3bd813695c1 Mon Sep 17 00:00:00 2001 From: nieve Date: Sat, 15 Jun 2024 18:58:39 -0400 Subject: [PATCH] Update useSegments.ts --- src/renderer/src/hooks/useSegments.ts | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/renderer/src/hooks/useSegments.ts b/src/renderer/src/hooks/useSegments.ts index 646ed4b0..158aaaf0 100644 --- a/src/renderer/src/hooks/useSegments.ts +++ b/src/renderer/src/hooks/useSegments.ts @@ -282,8 +282,8 @@ function useSegments({ filePath, workingRef, setWorking, setCutProgress, videoSt const { mode, startOrEnd } = response; if (filePath == null) throw new Error(); - const frameTime=1/(getStreamFps(videoStream)||1000); - const duration=await getDuration(filePath); + const frameTime = 1 / (getStreamFps(videoStream) || 1000); + const duration = await getDuration(filePath); await modifySelectedSegmentTimes(async (segment) => { const newSegment = { ...segment }; @@ -292,34 +292,34 @@ function useSegments({ filePath, workingRef, setWorking, setCutProgress, videoSt const time = newSegment[key]; if (filePath == null) throw new Error(); let keyframe = await findKeyframeNearTime({ filePath, streamIndex: videoStream.index, time, mode }); - if (keyframe == null){ - if(mode!='consistent'){ + if (keyframe == null) { + if (mode != 'consistent') { throw new Error(`Cannot find any keyframe within 60 seconds of frame ${time}`); } - keyframe=duration; - } + keyframe = duration; + } newSegment[key] = keyframe; } - if (startOrEnd.includes('start')){ - if(mode=='consistent'){ - newSegment.start+=frameTime*0.3; + if (startOrEnd.includes('start')) { + if (mode == 'consistent') { + newSegment.start += frameTime * 0.3; } await align('start'); - if(mode=='consistent'){ - newSegment.start-=frameTime*0.7; + if (mode == 'consistent') { + newSegment.start -= frameTime * 0.7; } - } + } if (startOrEnd.includes('end')) { await align('end'); - if(mode=='consistent'&&newSegment.end!=duration){ - newSegment.end-=frameTime*0.3; + if (mode == 'consistent' && newSegment.end != duration) { + newSegment.end -= frameTime * 0.3; } } - if (startOrEnd.includes('start')){ - newSegment.start=Math.min(newSegment.start,newSegment.end-frameTime*0.99); //don't know how ffmpeg interprets cuts between frames + if (startOrEnd.includes('start')) { + newSegment.start = Math.min(newSegment.start, newSegment.end - frameTime * 0.99); //don't know how ffmpeg interprets cuts between frames } else { - newSegment.end=Math.max(newSegment.start+frameTime*0.99,newSegment.end); + newSegment.end = Math.max(newSegment.start + frameTime * 0.99, newSegment.end); }