Skip to content

The swiss army knife of lossless video/audio editing

fix bug

Mikael Finstad8a6dd62d6da4
diff --git a/src/renderer/src/util/duration.test.ts b/src/renderer/src/util/duration.test.ts
index 56dd1890..6085f480 100644
--- a/src/renderer/src/util/duration.test.ts
+++ b/src/renderer/src/util/duration.test.ts
@@ -45,6 +45,8 @@ it('should format and parse duration with correct rounding', () => {
expect(formatDuration({ seconds: parseDuration('00:00:00,00', 30), fps: 30 })).toBe('00:00:00.00');
expect(formatDuration({ seconds: parseDuration('00:00:00,29', 30), fps: 30 })).toBe('00:00:00.29');
expect(formatDuration({ seconds: parseDuration('01:00:01,01', 30), fps: 30 })).toBe('01:00:01.01');
+ expect(parseDuration('0', 30)).toBe(0);
+ expect(parseDuration('0,1', 30)).toBe(0.03333333333333333);
});
// https://github.com/mifi/lossless-cut/issues/1603
diff --git a/src/renderer/src/util/duration.ts b/src/renderer/src/util/duration.ts
index 0126fe12..a0e648a0 100644
--- a/src/renderer/src/util/duration.ts
+++ b/src/renderer/src/util/duration.ts
@@ -40,7 +40,7 @@ export function formatDuration({ seconds: totalSecondsIn, fileNameFriendly, show
}
// todo adapt also to frame counts and frame fractions?
-export const isExactDurationMatch = (str) => /^-?\d{2}:\d{2}:\d{2}.\d{3}$/.test(str);
+export const isExactDurationMatch = (str: string) => /^-?\d{2}:\d{2}:\d{2}.\d{3}$/.test(str);
// See also parseYoutube
export function parseDuration(str: string, fps?: number) {
@@ -60,7 +60,7 @@ export function parseDuration(str: string, fps?: number) {
sec = parseFloat(secWithFraction);
} else {
const [secStr, framesStr] = secWithFraction.split('.');
- sec = parseInt(secStr!, 10) + parseInt(framesStr!, 10) / fps;
+ sec = parseInt(secStr!, 10) + (framesStr != null ? parseInt(framesStr, 10) : 0) / fps;
}
if (min > 59) return undefined;