Skip to content

🎥 Make videos programmatically with React

Internal testbed: Reproduce caption left edge trimming in a trimmed series

Jonny Burgerf600ea9acb8d
diff --git a/packages/example/src/CaptionLeftEdgeTrimRepro.tsx b/packages/example/src/CaptionLeftEdgeTrimRepro.tsx
new file mode 100644
index 0000000000..c5f5a57bcd
--- /dev/null
+++ b/packages/example/src/CaptionLeftEdgeTrimRepro.tsx
@@ -0,0 +1,88 @@
+import {createTikTokStyleCaptions, type Caption} from '@remotion/captions';
+import React, {useMemo} from 'react';
+import {
+ AbsoluteFill,
+ Interactive,
+ Series,
+ useCurrentFrame,
+ useVideoConfig,
+ type InteractiveTransformProps,
+} from 'remotion';
+
+const CaptionsContent: React.FC<
+ InteractiveTransformProps & {readonly captions: Caption[]}
+> = ({captions, style}) => {
+ const frame = useCurrentFrame();
+ const {fps} = useVideoConfig();
+ const {pages} = useMemo(
+ () =>
+ createTikTokStyleCaptions({
+ captions,
+ combineTokensWithinMilliseconds: 3000,
+ }),
+ [captions],
+ );
+ const currentTimeMs = (frame / fps) * 1000;
+ const page = pages.find(
+ (candidate) =>
+ currentTimeMs >= candidate.startMs &&
+ currentTimeMs < candidate.startMs + candidate.durationMs,
+ );
+
+ return <div style={style}>{page?.text.trim()}</div>;
+};
+
+const BasicCaptions = Interactive.withSchema({
+ Component: CaptionsContent,
+ componentName: '<BasicCaptions>',
+ schema: Interactive.captionsSchema,
+ wrapInSequence: true,
+});
+
+// https://github.com/remotion-dev/remotion/issues/11891
+// In Visual Mode, expand "Presenter introduction (2)" and drag the left edge
+// of its captions to the right. The captions' visible start should move.
+// Currently, the source props change but the visible start stays at frame 30.
+export const CaptionLeftEdgeTrimRepro: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ backgroundColor: '#111827',
+ color: 'white',
+ fontFamily: 'sans-serif',
+ fontSize: 64,
+ }}
+ >
+ <Series>
+ <Series.Sequence name="Lead-in" durationInFrames={30}>
+ <AbsoluteFill
+ style={{justifyContent: 'center', alignItems: 'center'}}
+ >
+ Caption left edge trim reproduction
+ </AbsoluteFill>
+ </Series.Sequence>
+ <Series.Sequence
+ name="Presenter introduction (2)"
+ durationInFrames={129}
+ premountFor={30}
+ trimBefore={369}
+ >
+ <BasicCaptions
+ name="Presenter introduction (2) captions"
+ captions={[
+ {
+ text: 'Drag the left edge of this caption track',
+ startMs: 12000,
+ endMs: 18000,
+ timestampMs: 15000,
+ confidence: null,
+ },
+ ]}
+ style={{position: 'absolute', left: 100, bottom: 100}}
+ />
+ </Series.Sequence>
+ <Series.Sequence name="Tail" durationInFrames={30} />
+ </Series>
+ </AbsoluteFill>
+ );
+};
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index f583806a2e..6572f5850f 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -17,6 +17,7 @@ import {NativeBufferStateForImage} from './BufferState/Image';
import {NativeBufferState} from './BufferState/Simple';
import {NativeBufferStateForVideo} from './BufferState/Video';
import {CancelRender} from './CancelRender';
+import {CaptionLeftEdgeTrimRepro} from './CaptionLeftEdgeTrimRepro';
import {
CAPTIONS_DURATION_IN_FRAMES,
CAPTIONS_HEIGHT,
@@ -3100,6 +3101,14 @@ export const Index: React.FC = () => {
durationInFrames={300}
/>
<Folder name="VisualModeTests">
+ <Composition
+ id="caption-left-edge-trim-repro"
+ component={CaptionLeftEdgeTrimRepro}
+ width={1920}
+ height={1080}
+ fps={30}
+ durationInFrames={189}
+ />
<Composition
id="keyframe-delete-flash"
component={KeyframeDeleteFlash}