Skip to main content

insertBasicCaptions()v4.0.544

Adds captions to an audio or video node. When the media can be extracted without capturing values from its surrounding component, creates a reusable Interactive.create() component containing the media and inline captions. Timing props move to the shared component, so trimming, splitting, and changing playback speed affect both together.

Uses the same safety analysis as pre-compose. If extraction is unsafe, such as when the media uses props, frame-dependent values, or spread attributes, inserts sibling captions and copies the media timing instead. Creates a reusable Basic captions renderer file when needed in either case.

When composition is provided, also exports and registers the extracted component as a connected composition. If registration cannot be edited safely, keeps the grouped source without a registration.

warning

Draft API: This API is experimental and may change.

insert-basic-captions.ts
import {insertBasicCaptions, type CodemodProject, type NodeReference} from '@remotion/codemods'; declare const project: CodemodProject; declare const node: NodeReference; const result = insertBasicCaptions({ project, node, composition: null, importPath: null, captions: [{text: 'Hello', startMs: 0, endMs: 1000, timestampMs: 0, confidence: null}], }); console.log(result.changes);

Options​

project​

An in-memory CodemodProject.

node​

The target NodeReference.

captions​

Caption objects with text, startMs, endMs, timestampMs, confidence, and optional pageBreakAfter. See the Caption type.

durationInFrames?​

Fallback duration for sibling captions when extraction is unsafe and the media node does not specify one. Defaults to null. Extracted components retain the media's authored timing and inherit any surrounding clip boundary.

importPath​

The module exporting BasicCaptions, or the custom element. When null, the result includes a new basic-captions.element.tsx file beside the media source, or reuses an existing matching component. An unrelated file with that name is preserved and another name is selected.

composition​

Registration settings for the extracted component, or null to skip registration. Only used when the media can be extracted safely.

fileName​

The source file containing composition registrations. It must be present in project.files.

existingCompositionIds​

Existing composition IDs across the project. The generated ID avoids these and the IDs in the registration file.

metadata​

An object containing width, height, fps, and durationInFrames. Use the parent's dimensions and FPS, and the full untrimmed media duration in frames. Clip timing remains on the instance in the parent timeline.

element?​

A custom caption component description, or null for Basic captions. Defaults to null. Requires an explicit importPath.

componentName​

The component's exported name.

initialProps​

Initial values for the component's props, or null. Captions and media timing are filled by this operation.

prettierConfigOverride?​

Formatting options for generated source. Defaults to null, which follows the existing source style.

Return value​

An object with the following properties.

changes​

File changes to apply with applyCodemodChanges(). The input project is not mutated.

nodePathRemappings​

Mappings from the original node paths to their new paths. See node references.

insertedNodes​

References to the newly inserted root nodes.

updatedNode​

The media node's reference after insertion.

editDetails​

The edited media source file and line.

newCompositionId​

The registered composition's ID, or null when no composition was registered.

Errors​

Throws when the target cannot be resolved or the requested edit is invalid. Failed edits leave the input project unchanged.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​