Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Fix composition duration input in timecode mode

JonnyBurger5d5f34df7e0a
diff --git a/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx b/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
index 59b2e24b66..875475fb9a 100644
--- a/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
+++ b/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
@@ -283,7 +283,7 @@ const CompositionMetadataValue: React.FC<{
showFrames || fps === null
? String(Math.round(Number(newValue)))
: formatValue(newValue),
- parse: (text: string) => parseCompositionDuration(text, fps),
+ parse: (text: string) => parseCompositionDuration(text, fps, showFrames),
invalidMessage: 'Enter a duration such as 5s, 1:30, or 150f.',
onCancel: () => setDragValue(null),
};
diff --git a/packages/studio/src/components/InspectorPanel/parse-composition-duration.ts b/packages/studio/src/components/InspectorPanel/parse-composition-duration.ts
index fda5c3f2a1..7e75ad7a16 100644
--- a/packages/studio/src/components/InspectorPanel/parse-composition-duration.ts
+++ b/packages/studio/src/components/InspectorPanel/parse-composition-duration.ts
@@ -3,12 +3,16 @@ import {parseInputDraggerNumber} from '../NewComposition/InputDragger';
export const parseCompositionDuration = (
input: string,
fps: number | null,
+ showFrames: boolean,
): number | null => {
const text = input.trim().toLowerCase();
const frameValue = parseInputDraggerNumber(
text.replace(/\s*f(?:rames?)?$/, ''),
);
- if (frameValue !== null) {
+ if (
+ frameValue !== null &&
+ (showFrames || fps === null || /\s*f(?:rames?)?$/.test(text))
+ ) {
return frameValue;
}
@@ -16,13 +20,20 @@ export const parseCompositionDuration = (
return null;
}
- const timecode = text.match(/^(?:(\d+):)?(\d+):(\d{1,2})(?:\.(\d+))?$/);
+ const timecode = text.match(
+ showFrames
+ ? /^(?:(\d+):)?(\d+):(\d{1,2})(?:\.(\d+))?$/
+ : /^(?:(?:(\d+):)?(\d+):)?(\d+)(?:\.(\d+))?$/,
+ );
if (timecode) {
const hours = Number(timecode[1] ?? 0);
- const minutes = Number(timecode[2]);
+ const minutes = Number(timecode[2] ?? 0);
const timecodeSeconds = Number(timecode[3]);
const frames = Number(timecode[4] ?? 0);
- if (timecodeSeconds >= 60 || (timecode[1] !== undefined && minutes >= 60)) {
+ if (
+ (timecode[2] !== undefined && timecodeSeconds >= 60) ||
+ (timecode[1] !== undefined && minutes >= 60)
+ ) {
return null;
}
@@ -32,6 +43,10 @@ export const parseCompositionDuration = (
return Number.isFinite(timecodeDuration) ? timecodeDuration : null;
}
+ if (frameValue !== null) {
+ return frameValue;
+ }
+
const units = text.matchAll(/(\d+(?:\.\d*)?|\.\d+)\s*([hms])\s*/g);
let consumed = 0;
let previousUnit = -1;