Skip to content

🎥 Make videos programmatically with React

condense studio layxout

Jonny Burger8978c45b6961
diff --git a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
index a0a61ffc1c..a7d2ea2747 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectFieldRow.tsx
@@ -10,16 +10,12 @@ import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';
import {callApi} from '../call-api';
import {getComputedStatusLabel} from './get-timeline-keyframes';
import {enqueueSavePropChange} from './save-prop-queue';
-import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';
+import {TimelineFieldLabel} from './TimelineFieldLabel';
import {TimelineLayerEyeSpacer} from './TimelineLayerEye';
import {TimelineRowChrome} from './TimelineRowChrome';
import {TimelineFieldValue, UnsupportedStatus} from './TimelineSchemaField';
-import {
- getTimelineSelectedLabelStyle,
- TIMELINE_SELECTED_LABEL_TEXT,
- useTimelineRowSelection,
-} from './TimelineSelection';
+import {useTimelineRowSelection} from './TimelineSelection';
const fieldRowBase: React.CSSProperties = {};
@@ -32,12 +28,6 @@ const valueColumnStyle: React.CSSProperties = {
paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
};
-const fieldName: React.CSSProperties = {
- fontSize: 12,
- color: 'rgba(255, 255, 255, 0.8)',
- userSelect: 'none',
-};
-
const Value: React.FC<{
readonly field: EffectSchemaFieldInfo;
readonly nodePath: SequencePropsSubscriptionKey;
@@ -238,25 +228,6 @@ export const TimelineEffectFieldRow: React.FC<{
};
}, [field.rowHeight]);
- const labelRowStyle = useMemo(
- (): React.CSSProperties => ({
- ...getTimelineFieldLabelRowStyle(rowDepth),
- ...getTimelineSelectedLabelStyle(selection.selected),
- alignSelf: 'stretch',
- }),
- [rowDepth, selection.selected],
- );
-
- const fieldNameStyle = useMemo(
- (): React.CSSProperties => ({
- ...fieldName,
- color: selection.selected
- ? TIMELINE_SELECTED_LABEL_TEXT
- : fieldName.color,
- }),
- [selection.selected],
- );
-
return (
<TimelineRowChrome
depth={rowDepth}
@@ -268,9 +239,11 @@ export const TimelineEffectFieldRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
>
- <div style={labelRowStyle}>
- <span style={fieldNameStyle}>{field.description ?? field.key}</span>
- </div>
+ <TimelineFieldLabel
+ rowDepth={rowDepth}
+ selected={selection.selected}
+ label={field.description ?? field.key}
+ />
<div style={valueColumnStyle}>
<Value
field={field}
diff --git a/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx b/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx
new file mode 100644
index 0000000000..f6055df98c
--- /dev/null
+++ b/packages/studio/src/components/Timeline/TimelineFieldLabel.tsx
@@ -0,0 +1,48 @@
+import React, {useMemo} from 'react';
+import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
+import {
+ getTimelineSelectedLabelStyle,
+ TIMELINE_SELECTED_LABEL_TEXT,
+} from './TimelineSelection';
+
+const fieldNameBase: React.CSSProperties = {
+ fontSize: 12,
+ color: 'rgba(255, 255, 255, 0.8)',
+ userSelect: 'none',
+ whiteSpace: 'nowrap',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ flex: 1,
+ minWidth: 0,
+};
+
+export const TimelineFieldLabel: React.FC<{
+ readonly rowDepth: number;
+ readonly selected: boolean;
+ readonly label: string;
+}> = ({rowDepth, selected, label}) => {
+ const labelRowStyle = useMemo(
+ (): React.CSSProperties => ({
+ ...getTimelineFieldLabelRowStyle(rowDepth),
+ ...getTimelineSelectedLabelStyle(selected),
+ alignSelf: 'stretch',
+ }),
+ [rowDepth, selected],
+ );
+
+ const fieldNameStyle = useMemo(
+ (): React.CSSProperties => ({
+ ...fieldNameBase,
+ color: selected ? TIMELINE_SELECTED_LABEL_TEXT : fieldNameBase.color,
+ }),
+ [selected],
+ );
+
+ return (
+ <div style={labelRowStyle}>
+ <span style={fieldNameStyle} title={label}>
+ {label}
+ </span>
+ </div>
+ );
+};
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index a52e05e70d..9a23c748f0 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -15,19 +15,15 @@ import type {
} from '../../helpers/timeline-layout';
import {EXPANDED_SECTION_PADDING_RIGHT} from '../../helpers/timeline-layout';
import {saveSequenceProp} from './save-sequence-prop';
-import {getTimelineFieldLabelRowStyle} from './timeline-field-row-layout';
import {TimelineExpandArrowSpacer} from './TimelineExpandArrowButton';
+import {TimelineFieldLabel} from './TimelineFieldLabel';
import {TimelineLayerEyeSpacer} from './TimelineLayerEye';
import {TimelineRowChrome} from './TimelineRowChrome';
import {
TimelineFieldValue,
TimelineNonEditableStatus,
} from './TimelineSchemaField';
-import {
- getTimelineSelectedLabelStyle,
- TIMELINE_SELECTED_LABEL_TEXT,
- useTimelineRowSelection,
-} from './TimelineSelection';
+import {useTimelineRowSelection} from './TimelineSelection';
const fieldRowBase: React.CSSProperties = {};
@@ -40,12 +36,6 @@ const valueColumnStyle: React.CSSProperties = {
paddingRight: EXPANDED_SECTION_PADDING_RIGHT,
};
-const fieldName: React.CSSProperties = {
- fontSize: 12,
- color: 'rgba(255, 255, 255, 0.8)',
- userSelect: 'none',
-};
-
const Value: React.FC<{
readonly field: SchemaFieldInfo;
readonly nodePath: SequencePropsSubscriptionKey;
@@ -187,25 +177,6 @@ export const TimelineFieldRow: React.FC<{
};
}, [field.rowHeight]);
- const labelRowStyle = useMemo(
- (): React.CSSProperties => ({
- ...getTimelineFieldLabelRowStyle(rowDepth),
- ...getTimelineSelectedLabelStyle(selection.selected),
- alignSelf: 'stretch',
- }),
- [rowDepth, selection.selected],
- );
-
- const fieldNameStyle = useMemo(
- (): React.CSSProperties => ({
- ...fieldName,
- color: selection.selected
- ? TIMELINE_SELECTED_LABEL_TEXT
- : fieldName.color,
- }),
- [selection.selected],
- );
-
if (codeValue === null) {
return null;
}
@@ -221,9 +192,11 @@ export const TimelineFieldRow: React.FC<{
onSelect={selection.onSelect}
showSelectedBackground
>
- <div style={labelRowStyle}>
- <span style={fieldNameStyle}>{field.description ?? field.key}</span>
- </div>
+ <TimelineFieldLabel
+ rowDepth={rowDepth}
+ selected={selection.selected}
+ label={field.description ?? field.key}
+ />
{codeValue.canUpdate ? (
<div style={valueColumnStyle}>
<Value
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 005cedc604..f71f650c3a 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -371,10 +371,7 @@ export const TimelineListItem: React.FC<{
</TimelineRowChrome>
{mediaSrc ? (
<div style={mediaInfoStyle}>
- <TimelineMediaInfo
- src={mediaSrc}
- type={sequence.type as 'audio' | 'video' | 'image'}
- />
+ <TimelineMediaInfo src={mediaSrc} />
</div>
) : null}
</div>
diff --git a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
index 5af58cd142..26e0cc455b 100644
--- a/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
+++ b/packages/studio/src/components/Timeline/TimelineMediaInfo.tsx
@@ -1,10 +1,7 @@
-import {getImageDimensions} from '@remotion/media-utils';
-import React, {useCallback, useEffect, useMemo, useState} from 'react';
+import React, {useCallback, useMemo, useState} from 'react';
import {Internals} from 'remotion';
import {LIGHT_TEXT, VERY_LIGHT_TEXT} from '../../helpers/colors';
-import {formatMediaDuration} from '../../helpers/format-media-duration';
import {pushUrl} from '../../helpers/url-state';
-import {useMediaMetadata} from '../../helpers/use-media-metadata';
const containerStyle: React.CSSProperties = {
fontFamily: 'Arial, Helvetica, sans-serif',
@@ -25,6 +22,7 @@ const lineStyle: React.CSSProperties = {
fontSize: 12,
color: VERY_LIGHT_TEXT,
lineHeight: 1.3,
+ paddingLeft: 2, // to compensate for selection padding
};
type LinkInfo =
@@ -117,80 +115,13 @@ const useAssetLink = (src: string) => {
export const TimelineMediaInfo: React.FC<{
readonly src: string;
- readonly type: 'audio' | 'video' | 'image';
-}> = ({src, type}) => {
+}> = ({src}) => {
// Images aren't supported by mediabunny, so don't even try.
- const metadata = useMediaMetadata(type === 'image' ? null : src);
const fileName = useMemo(() => Internals.getAssetDisplayName(src), [src]);
const {linkInfo, onClick, onPointerEnter, onPointerLeave, fileNameStyle} =
useAssetLink(src);
- const [imageDimensions, setImageDimensions] = useState<{
- width: number;
- height: number;
- } | null>(null);
-
- useEffect(() => {
- if (type !== 'image') {
- return;
- }
-
- let cancelled = false;
- setImageDimensions(null);
-
- getImageDimensions(src)
- .then((dims) => {
- if (cancelled) {
- return;
- }
-
- setImageDimensions({width: dims.width, height: dims.height});
- })
- .catch(() => {
- // Non-image or load failure — ignore silently.
- });
-
- return () => {
- cancelled = true;
- };
- }, [src, type]);
-
- const detailsLine = useMemo(() => {
- if (type === 'image') {
- if (!imageDimensions) {
- return null;
- }
-
- return `${imageDimensions.width}x${imageDimensions.height}`;
- }
-
- if (!metadata) {
- return null;
- }
-
- const parts: string[] = [];
- if (metadata.format) {
- parts.push(metadata.format);
- }
-
- if (type === 'video' && metadata.videoCodec) {
- parts.push(metadata.videoCodec);
- }
-
- if (metadata.audioCodec) {
- parts.push(metadata.audioCodec);
- }
-
- if (metadata.width !== null && metadata.height !== null) {
- parts.push(`${metadata.width}x${metadata.height}`);
- }
-
- parts.push(formatMediaDuration(metadata.duration));
-
- return parts.join(' · ');
- }, [imageDimensions, metadata, type]);
-
return (
<div style={containerStyle}>
<div
@@ -202,11 +133,6 @@ export const TimelineMediaInfo: React.FC<{
>
{fileName}
</div>
- {detailsLine ? (
- <div style={lineStyle} title={detailsLine}>
- {detailsLine}
- </div>
- ) : null}
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineSelection.tsx b/packages/studio/src/components/Timeline/TimelineSelection.tsx
index 0618254c16..1824f90155 100644
--- a/packages/studio/src/components/Timeline/TimelineSelection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSelection.tsx
@@ -20,17 +20,10 @@ export const TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING = 2;
export const getTimelineSelectedLabelStyle = (
selected: boolean,
): CSSProperties => {
- if (!selected) {
- return {};
- }
-
- const padding = TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING;
return {
- backgroundColor: TIMELINE_SELECTED_LABEL_BACKGROUND,
- marginLeft: -padding,
- marginRight: -padding,
- paddingLeft: padding,
- paddingRight: padding,
+ paddingLeft: TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING,
+ paddingRight: TIMELINE_SELECTED_LABEL_HORIZONTAL_PADDING,
+ ...(selected ? {backgroundColor: TIMELINE_SELECTED_LABEL_BACKGROUND} : {}),
};
};
@@ -44,7 +37,7 @@ export const getTimelineSelectedTrackHighlightStyle = (): CSSProperties => ({
top: 0,
});
-export const SELECTION_ENABLED = false;
+export const SELECTION_ENABLED = true;
export type TimelineSelection =
| {
diff --git a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
index a13fa5102c..9942c911e0 100644
--- a/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
+++ b/packages/studio/src/components/Timeline/TimelineVideoInfo.tsx
@@ -15,12 +15,13 @@ import {
import React, {useEffect, useMemo, useRef, useState} from 'react';
import type {LoopDisplay} from 'remotion';
import {useVideoConfig} from 'remotion';
-import {TIMELINE_VIDEO_INFO_WAVEFORM_HEIGHT} from '../../helpers/timeline-layout';
+import {
+ TIMELINE_LAYER_FILMSTRIP_HEIGHT,
+ TIMELINE_VIDEO_INFO_WAVEFORM_HEIGHT,
+} from '../../helpers/timeline-layout';
import {AudioWaveform} from '../AudioWaveform';
import {getTimelineVideoInfoWidths} from './get-timeline-video-info-widths';
-const FILMSTRIP_HEIGHT = 48;
-
const outerStyle: React.CSSProperties = {
width: '100%',
height: '100%',
@@ -29,7 +30,7 @@ const outerStyle: React.CSSProperties = {
};
const filmstripContainerStyle: React.CSSProperties = {
- height: FILMSTRIP_HEIGHT,
+ height: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
backgroundColor: 'rgba(0, 0, 0, 0.3)',
display: 'flex',
borderTopLeftRadius: 2,
@@ -90,7 +91,7 @@ export const TimelineVideoInfo: React.FC<{
const canvas = document.createElement('canvas');
canvas.width = mediaVisualizationWidth;
- canvas.height = FILMSTRIP_HEIGHT;
+ canvas.height = TIMELINE_LAYER_FILMSTRIP_HEIGHT;
const ctx = canvas.getContext('2d');
if (!ctx) {
return;
@@ -157,7 +158,7 @@ export const TimelineVideoInfo: React.FC<{
fromSeconds,
toSeconds,
aspectRatio: aspectRatio.current,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
fillWithCachedFrames({
@@ -168,7 +169,7 @@ export const TimelineVideoInfo: React.FC<{
segmentDuration: toSeconds - fromSeconds,
fromSeconds,
devicePixelRatio: window.devicePixelRatio,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
repeatTarget();
@@ -199,7 +200,7 @@ export const TimelineVideoInfo: React.FC<{
toSeconds,
naturalWidth: targetWidth,
aspectRatio: aspectRatio.current,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
return Array.from(filledSlots.keys()).map(
@@ -212,7 +213,8 @@ export const TimelineVideoInfo: React.FC<{
try {
frame = sample.toVideoFrame();
const scale =
- (FILMSTRIP_HEIGHT / frame.displayHeight) * window.devicePixelRatio;
+ (TIMELINE_LAYER_FILMSTRIP_HEIGHT / frame.displayHeight) *
+ window.devicePixelRatio;
const transformed = resizeVideoFrame({
frame,
@@ -238,7 +240,7 @@ export const TimelineVideoInfo: React.FC<{
toSeconds,
naturalWidth: targetWidth,
aspectRatio: aspectRatio.current,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
fillFrameWhereItFits({
ctx: targetCtx,
@@ -248,7 +250,7 @@ export const TimelineVideoInfo: React.FC<{
segmentDuration: toSeconds - fromSeconds,
fromSeconds,
devicePixelRatio: window.devicePixelRatio,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
repeatTarget();
} catch (e) {
@@ -276,7 +278,7 @@ export const TimelineVideoInfo: React.FC<{
segmentDuration: toSeconds - fromSeconds,
fromSeconds,
devicePixelRatio: window.devicePixelRatio,
- frameHeight: FILMSTRIP_HEIGHT,
+ frameHeight: TIMELINE_LAYER_FILMSTRIP_HEIGHT,
});
repeatTarget();
})
diff --git a/packages/studio/src/components/Timeline/timeline-field-row-layout.ts b/packages/studio/src/components/Timeline/timeline-field-row-layout.ts
index 15f22873e3..a680f53700 100644
--- a/packages/studio/src/components/Timeline/timeline-field-row-layout.ts
+++ b/packages/studio/src/components/Timeline/timeline-field-row-layout.ts
@@ -6,6 +6,7 @@ export const getTimelineFieldLabelRowStyle = (
): React.CSSProperties => {
return {
flex: `0 0 ${getTimelineFieldLabelFlexBasis(depth)}`,
+ minWidth: 0,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
diff --git a/packages/studio/src/helpers/timeline-layout.ts b/packages/studio/src/helpers/timeline-layout.ts
index 53598bc26b..64e845edd3 100644
--- a/packages/studio/src/helpers/timeline-layout.ts
+++ b/packages/studio/src/helpers/timeline-layout.ts
@@ -241,14 +241,17 @@ export const getExpandedTrackHeight = ({
return totalRowsHeight + separators;
};
-export const TIMELINE_LAYER_HEIGHT_VIDEO = 75;
-export const TIMELINE_LAYER_HEIGHT_IMAGE = 58;
-export const TIMELINE_LAYER_HEIGHT_AUDIO = 58;
-export const TIMELINE_LAYER_HEIGHT_DEFAULT = 25;
-// The horizontal row inside a timeline list item (eye + arrow + label).
-export const TIMELINE_LIST_ITEM_ROW_HEIGHT = 25;
+export const TIMELINE_LAYER_FILMSTRIP_HEIGHT = 36;
// The waveform stripe rendered underneath the filmstrip in TimelineVideoInfo.
export const TIMELINE_VIDEO_INFO_WAVEFORM_HEIGHT = 25;
+export const TIMELINE_LAYER_HEIGHT_VIDEO =
+ 2 + TIMELINE_LAYER_FILMSTRIP_HEIGHT + TIMELINE_VIDEO_INFO_WAVEFORM_HEIGHT;
+
+export const TIMELINE_LAYER_HEIGHT_IMAGE = 42;
+export const TIMELINE_LAYER_HEIGHT_AUDIO = 34;
+export const TIMELINE_LAYER_HEIGHT_DEFAULT = 21;
+// The horizontal row inside a timeline list item (eye + arrow + label).
+export const TIMELINE_LIST_ITEM_ROW_HEIGHT = 21;
export const getTimelineLayerHeight = (
type: 'video' | 'image' | 'audio' | 'sequence' | 'other',