Skip to content

Commit

Permalink
Update useSegments.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ac615223s5 committed Jun 15, 2024
1 parent 110bdfa commit 7d55abb
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/renderer/src/hooks/useSegments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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);
}


Expand Down

0 comments on commit 7d55abb

Please sign in to comment.