From fafbe91e3f40ac10c9b003c883e6c0254a6cfc75 Mon Sep 17 00:00:00 2001 From: nieve Date: Fri, 30 Aug 2024 22:15:22 -0400 Subject: [PATCH] rename option --- src/renderer/src/dialogs/index.tsx | 4 ++-- src/renderer/src/ffmpeg.ts | 4 ++-- src/renderer/src/hooks/useSegments.ts | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/dialogs/index.tsx b/src/renderer/src/dialogs/index.tsx index 9a3b0c70..5ff72fcd 100644 --- a/src/renderer/src/dialogs/index.tsx +++ b/src/renderer/src/dialogs/index.tsx @@ -329,9 +329,9 @@ export async function askForAlignSegments() { nearest: i18n.t('Nearest keyframe'), before: i18n.t('Previous keyframe'), after: i18n.t('Next keyframe'), - consistent: i18n.t('True keyframe cut'), + keyframeCutFix: i18n.t('True keyframe cut'), }, - inputValue: 'consistent', + inputValue: 'keyframeCutFix', text: i18n.t('Do you want to align segment times to the nearest, previous or next keyframe?'), }); diff --git a/src/renderer/src/ffmpeg.ts b/src/renderer/src/ffmpeg.ts index 344a2c01..f884b107 100644 --- a/src/renderer/src/ffmpeg.ts +++ b/src/renderer/src/ffmpeg.ts @@ -106,7 +106,7 @@ export const findNextKeyframe = (keyframes: Keyframe[], time: number) => keyfram const findPreviousKeyframe = (keyframes: Keyframe[], time: number) => keyframes.findLast((keyframe) => keyframe.time <= time); const findNearestKeyframe = (keyframes: Keyframe[], time: number) => minBy(keyframes, (keyframe) => Math.abs(keyframe.time - time)); -export type FindKeyframeMode = 'nearest' | 'before' | 'after' | 'consistent'; +export type FindKeyframeMode = 'nearest' | 'before' | 'after' | 'keyframeCutFix'; function findKeyframe(keyframes: Keyframe[], time: number, mode: FindKeyframeMode) { switch (mode) { @@ -119,7 +119,7 @@ function findKeyframe(keyframes: Keyframe[], time: number, mode: FindKeyframeMod case 'after': { return findNextKeyframe(keyframes, time); } - case 'consistent': { + case 'keyframeCutFix': { return findNextKeyframe(keyframes,time); } default: { diff --git a/src/renderer/src/hooks/useSegments.ts b/src/renderer/src/hooks/useSegments.ts index 158aaaf0..31dacca1 100644 --- a/src/renderer/src/hooks/useSegments.ts +++ b/src/renderer/src/hooks/useSegments.ts @@ -290,10 +290,10 @@ function useSegments({ filePath, workingRef, setWorking, setCutProgress, videoSt async function align(key: string) { const time = newSegment[key]; - if (filePath == null) throw new Error(); + 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 !== 'keyframeCutFix') { throw new Error(`Cannot find any keyframe within 60 seconds of frame ${time}`); } keyframe = duration; @@ -301,17 +301,17 @@ function useSegments({ filePath, workingRef, setWorking, setCutProgress, videoSt newSegment[key] = keyframe; } if (startOrEnd.includes('start')) { - if (mode == 'consistent') { + if (mode === 'keyframeCutFix') { newSegment.start += frameTime * 0.3; } await align('start'); - if (mode == 'consistent') { + if (mode === 'keyframeCutFix') { newSegment.start -= frameTime * 0.7; } } if (startOrEnd.includes('end')) { await align('end'); - if (mode == 'consistent' && newSegment.end != duration) { + if (mode === 'keyframeCutFix' && newSegment.end !== duration) { newSegment.end -= frameTime * 0.3; } }