add new "opposing" align mode

closes #2654
pull/2801/head
Mikael Finstad 4 months ago
parent 26030181c7
commit 260301f94d
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -632,6 +632,7 @@
"Segment mode: \"{{mode1}}\" will create segments bounding the black sections. \"{{mode2}}\" will create segments that start/stop at the center of each black section.": "Segment mode: \"{{mode1}}\" will create segments bounding the black sections. \"{{mode2}}\" will create segments that start/stop at the center of each black section.",
"Segment mode: \"{{mode1}}\" will create segments bounding the silent sections. \"{{mode2}}\" will create segments that start/stop at the center of each silent section.": "Segment mode: \"{{mode1}}\" will create segments bounding the silent sections. \"{{mode2}}\" will create segments that start/stop at the center of each silent section.",
"Segment start time must precede end time": "Segment start time must precede end time",
"Segment start to previous keyframe and end to next keyframe": "Segment start to previous keyframe and end to next keyframe",
"Segment starts after 01:00": "Segment starts after 01:00",
"Segment tag value": "Segment tag value",
"Segment tags": "Segment tags",

@ -334,14 +334,15 @@ export async function askForAlignSegments() {
const startOrEnd = await askForSegmentsStartOrEnd(i18n.t('Do you want to align the segment start or end timestamps to keyframes?'));
if (startOrEnd == null) return undefined;
const { value: mode } = await getSwal().Swal.fire<FindKeyframeMode>({
const { value: mode } = await getSwal().Swal.fire<FindKeyframeMode | 'opposing'>({
input: 'radio',
showCancelButton: true,
inputOptions: {
nearest: i18n.t('Nearest keyframe'),
before: i18n.t('Previous keyframe'),
after: i18n.t('Next keyframe'),
} satisfies Record<FindKeyframeMode, unknown>,
opposing: i18n.t('Segment start to previous keyframe and end to next keyframe'),
} satisfies Record<FindKeyframeMode | 'opposing', unknown>,
inputValue: 'before',
text: i18n.t('Do you want to align segment times to the nearest, previous or next keyframe?'),
});

@ -521,7 +521,12 @@ function useSegments({ filePath, workingRef, setWorking, setProgress, videoStrea
const time = newSegment[key];
invariant(filePath != null);
if (time != null) {
const keyframe = await findKeyframeNearTime({ filePath, streamIndex: videoStream.index, time, mode });
const keyframe = await findKeyframeNearTime({
filePath,
streamIndex: videoStream.index,
time,
mode: mode === 'opposing' ? (key === 'start' ? 'before' : 'after') : mode,
});
if (keyframe == null) throw new UserFacingError(i18n.t('Cannot find any keyframe within 60 seconds of frame {{time}}', { time }));
newSegment[key] = keyframe;
}

Loading…
Cancel
Save