Skip to content

🎥 Make videos programmatically with React

Fix multi-selection timeline resize flicker

JonnyBurger8b640dc0228a
diff --git a/packages/example/public/whats1.mov b/packages/example/public/whats1.mov
new file mode 100644
index 0000000000..bda58df6b3
Binary files /dev/null and b/packages/example/public/whats1.mov differ
diff --git a/packages/example/src/E2eTestRoot.tsx b/packages/example/src/E2eTestRoot.tsx
index 453ac02ab7..a13a1f4a5c 100644
--- a/packages/example/src/E2eTestRoot.tsx
+++ b/packages/example/src/E2eTestRoot.tsx
@@ -20,6 +20,7 @@ import {MovingPillCaptionsComposition} from './MovingPillCaptionsComposition';
import {NewVideoComp} from './NewVideo';
import {SchemaTest, schemaTestSchema} from './SchemaTest';
import {SequencePlaybackRateE2e} from './SequencePlaybackRateE2e';
+import {TimelineMultiSelectResizeFlickerComposition} from './TimelineMultiSelectResizeFlicker';
import {TimelineNegativeFromResize} from './TimelineNegativeFromResize';
import {VisualControls} from './VisualControls';
import {VisualMode3D} from './VisualMode3D';
@@ -210,6 +211,7 @@ export const E2eTestRoot: React.FC = () => {
fps={30}
durationInFrames={90}
/>
+ <TimelineMultiSelectResizeFlickerComposition />
<Composition
id="interactive-html-elements"
component={InteractiveHtmlElements}
diff --git a/packages/example/src/TimelineMultiSelectResizeFlicker/basic-captions.element.tsx b/packages/example/src/TimelineMultiSelectResizeFlicker/basic-captions.element.tsx
new file mode 100644
index 0000000000..c10ce18919
--- /dev/null
+++ b/packages/example/src/TimelineMultiSelectResizeFlicker/basic-captions.element.tsx
@@ -0,0 +1,107 @@
+import type {Caption} from '@remotion/captions';
+import {createTikTokStyleCaptions} from '@remotion/captions';
+import React, {useMemo} from 'react';
+import {
+ Interactive,
+ useCurrentFrame,
+ useVideoConfig,
+ type InteractiveTransformProps,
+ type InteractivitySchema,
+ type SequenceProps,
+} from 'remotion';
+
+type BasicCaptionsProps = InteractiveTransformProps &
+ Pick<SequenceProps, 'width'> & {
+ readonly captions: Caption[];
+ readonly combineTokensWithinMilliseconds?: number;
+ };
+
+const BasicCaptionsContent: React.FC<BasicCaptionsProps> = ({
+ captions,
+ combineTokensWithinMilliseconds = 2000,
+ style,
+ width = 900,
+}) => {
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const pages = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds,
+ }).pages,
+ [captions, combineTokensWithinMilliseconds],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const page = pages.find(
+ (candidate) =>
+ currentTimeMs >= candidate.startMs &&
+ currentTimeMs < candidate.startMs + candidate.durationMs,
+ );
+
+ return (
+ <div
+ style={{
+ alignItems: 'center',
+ display: 'flex',
+ justifyContent: 'center',
+ position: 'absolute',
+ bottom: 120,
+ left: '50%',
+ transform: 'translateX(-50%)',
+ width,
+ ...style,
+ }}
+ >
+ {page ? (
+ <div
+ style={{
+ backgroundColor: 'rgba(64, 64, 64, 0.75)',
+ color: '#ffffff',
+ display: '-webkit-box',
+ fontFamily: 'Arial, Helvetica, sans-serif',
+ fontSize: 64,
+ fontWeight: 400,
+ lineHeight: 1.2,
+ overflow: 'hidden',
+ padding: '14px 22px',
+ textAlign: 'center',
+ textWrap: 'balance',
+ WebkitBoxOrient: 'vertical',
+ WebkitLineClamp: 2,
+ whiteSpace: 'pre-wrap',
+ }}
+ >
+ {page.text.trim()}
+ </div>
+ ) : null}
+ </div>
+ );
+};
+
+const basicCaptionsSchema = {
+ ...Interactive.captionsSchema,
+ width: {
+ type: 'number',
+ min: 1,
+ step: 1,
+ default: undefined,
+ description: 'Caption area width',
+ hiddenFromList: false,
+ },
+ combineTokensWithinMilliseconds: {
+ type: 'number',
+ min: 0,
+ step: 50,
+ default: 2000,
+ description: 'Time between caption pages',
+ hiddenFromList: false,
+ },
+} as const satisfies InteractivitySchema;
+
+export const BasicCaptions = Interactive.withSchema({
+ Component: BasicCaptionsContent,
+ componentName: '<BasicCaptions>',
+ schema: basicCaptionsSchema,
+ wrapInSequence: true,
+});
diff --git a/packages/example/src/TimelineMultiSelectResizeFlicker/index.tsx b/packages/example/src/TimelineMultiSelectResizeFlicker/index.tsx
new file mode 100644
index 0000000000..7a368e4495
--- /dev/null
+++ b/packages/example/src/TimelineMultiSelectResizeFlicker/index.tsx
@@ -0,0 +1,117 @@
+import {Video} from '@remotion/media';
+import {Composition, staticFile} from 'remotion';
+import {BasicCaptions} from './basic-captions.element';
+
+export function Precomposition() {
+ return (
+ <>
+ <Video src={staticFile('whats1.mov')} durationInFrames={64} />
+ <BasicCaptions
+ style={{
+ height: 'auto',
+ translate: '510px -259.1px',
+ }}
+ captions={[
+ {
+ text: 'Here',
+ startMs: 1440,
+ endMs: 1620,
+ timestampMs: 1530,
+ confidence: null,
+ },
+ {
+ text: ' are',
+ startMs: 1620,
+ endMs: 1820,
+ timestampMs: 1720,
+ confidence: null,
+ },
+ {
+ text: ' some',
+ startMs: 1820,
+ endMs: 1960,
+ timestampMs: 1890,
+ confidence: null,
+ },
+ {
+ text: ' of',
+ startMs: 1960,
+ endMs: 2060,
+ timestampMs: 2010,
+ confidence: null,
+ },
+ {
+ text: ' the',
+ startMs: 2060,
+ endMs: 2300,
+ timestampMs: 2180,
+ confidence: null,
+ },
+ {
+ text: ' things',
+ startMs: 2300,
+ endMs: 2480,
+ timestampMs: 2390,
+ confidence: null,
+ },
+ {
+ text: ' that',
+ startMs: 2480,
+ endMs: 2660,
+ timestampMs: 2570,
+ confidence: null,
+ },
+ {
+ text: ' we',
+ startMs: 2660,
+ endMs: 3020,
+ timestampMs: 2840,
+ confidence: null,
+ },
+ {
+ text: ' recently',
+ startMs: 3020,
+ endMs: 3560,
+ timestampMs: 3290,
+ confidence: null,
+ },
+ {
+ text: ' improved',
+ startMs: 3560,
+ endMs: 3880,
+ timestampMs: 3720,
+ confidence: null,
+ },
+ {
+ text: ' in',
+ startMs: 3880,
+ endMs: 4080,
+ timestampMs: 3980,
+ confidence: null,
+ },
+ {
+ text: ' Remotion.',
+ startMs: 4080,
+ endMs: 5000,
+ timestampMs: 4540,
+ confidence: null,
+ },
+ ]}
+ durationInFrames={64}
+ />
+ </>
+ );
+}
+
+export const TimelineMultiSelectResizeFlickerComposition: React.FC = () => {
+ return (
+ <Composition
+ id="timeline-multi-select-resize-flicker"
+ component={Precomposition}
+ durationInFrames={150}
+ fps={30}
+ width={1920}
+ height={1080}
+ />
+ );
+};
diff --git a/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx b/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
index c197c7c4a1..96c89a17f8 100644
--- a/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
+++ b/packages/studio/src/components/InspectorPanel/MultiSequenceField.tsx
@@ -1,4 +1,10 @@
-import React, {useCallback, useContext, useEffect, useState} from 'react';
+import React, {
+ useCallback,
+ useContext,
+ useEffect,
+ useRef,
+ useState,
+} from 'react';
import type {SequencePropsSubscriptionKey, TSequence} from 'remotion';
import {Internals} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
@@ -65,7 +71,15 @@ export const MultiSequenceField: React.FC<{
clearDragOverrides(target.nodePath);
}
}, [clearDragOverrides, targets]);
- useEffect(() => clear, [clear]);
+ const targetsRef = useRef(targets);
+ targetsRef.current = targets;
+ useEffect(() => {
+ return () => {
+ for (const target of targetsRef.current) {
+ clearDragOverrides(target.nodePath);
+ }
+ };
+ }, [clearDragOverrides]);
const preview = useCallback(
(nextValues: unknown[]) => {
if (!editable) {