Skip to Content
Pipeline Stages

Render

Encode the final video with format, resolution, FPS, and subtitle burn-in options.

The .render() stage configures the final video encoding. It controls the output format, resolution, frame rate, and subtitle burn-in styling.

Basic usage

await Recast
  .from('./traces')
  .parse()
  .render({ format: 'mp4', resolution: '1080p' })
  .toFile('demo.mp4')

Configuration options

OptionTypeDefaultDescription
formatstring'mp4'Output format
resolutionstring'1080p'Output resolution: '720p', '1080p', '4k'
fpsnumber30Output frame rate
burnSubtitlesbooleanfalseBurn subtitles into the video
embedSubtitlesboolean | objectfalseMux subtitles as a soft (toggleable) track inside the container
subtitleStyleobjectdefault ffmpegSubtitle appearance configuration
zoom.panStabilizationThresholdnumber0 (off)Keep the camera still between nearby zoom targets, see Stabilizing the pan

Output with .toFile()

After configuring the render, call .toFile() to execute the pipeline and write the result:

.render({ format: 'mp4', resolution: '1080p' })
.toFile('demo.mp4')

Subtitle burn-in

Set burnSubtitles: true to render subtitles directly into the video frames. Without subtitleStyle, ffmpeg's default SRT rendering is used.

Embedded (soft) subtitle track

Set embedSubtitles: true to mux subtitles as a toggleable track inside the container. The viewer can switch them on/off in their player. Works for both mp4 (mov_text) and webm (webvtt).

.render({
  format: 'mp4',
  embedSubtitles: true,                        // language: 'eng', title: 'Subtitles'
})

.render({
  format: 'mp4',
  embedSubtitles: { language: 'ger', title: 'Deutsch', default: true },
})

embedSubtitles and burnSubtitles can be combined — viewers see the burned-in text regardless and can also toggle the embedded track.

Voiceover-driven freezes

When the pipeline includes voiceover() and the synthesized audio for a narration is longer than its visual window, the renderer holds the current frame until the audio finishes. The frozen frame keeps any active highlight or zoom overlay; click sounds shift along with the timeline. No configuration required — this happens automatically based on the freezes emitted by the voiceover stage.

Subtitle style options

OptionTypeDefaultDescription
fontFamilystring'Arial'Any system font
fontSizenumber48Font size in pixels (relative to 1080p)
primaryColorstring'#FFFFFF'Text color (hex)
backgroundColorstring'#000000'Box background color (hex)
backgroundOpacitynumber0.75Box opacity (0.0 transparent - 1.0 opaque)
paddingnumber20Box padding in pixels
boldbooleanfalseBold text
positionstring'bottom''bottom' or 'top'
marginVerticalnumber50Distance from edge in pixels
marginHorizontalnumber100Side margins (text wraps within)
wrapStylestring'smart''smart', 'endOfLine', 'none'
chunkOptionsobject—Punctuation-based text splitting

Full subtitle styling example

.render({
  format: 'mp4',
  resolution: '1080p',
  fps: 60,
  burnSubtitles: true,
  subtitleStyle: {
    fontFamily: 'Arial',
    fontSize: 48,
    primaryColor: '#1a1a1a',
    backgroundColor: '#FFFFFF',
    backgroundOpacity: 0.75,
    padding: 20,
    bold: true,
    position: 'bottom',
    marginVertical: 50,
    marginHorizontal: 100,
    wrapStyle: 'smart',
    chunkOptions: {
      maxCharsPerLine: 55,
      minCharsPerChunk: 15,
    },
  },
})

Chunk options

Long subtitle text is split into shorter single-line entries. Time is distributed proportionally by character count.

OptionTypeDefaultDescription
maxCharsPerLinenumber55Split text when it exceeds this length
minCharsPerChunknumber15Merge fragments shorter than this

Splitting priority:

  1. Sentence boundaries (. ! ?)
  2. Clause boundaries (, ; :) if still too long

CLI equivalent

# Basic render
npx playwright-recast -i ./traces -o demo.mp4

# With subtitle burn-in
npx playwright-recast -i ./traces --srt narration.srt --burn-subs -o demo.mp4

Tips

  • Use 720p during development for faster rendering. Switch to 1080p or 4k for final output.
  • Without burnSubtitles, subtitle files (SRT/VTT) are still generated alongside the video for use in video players that support external subtitles.
  • Subtitle font size is relative to 1080p. At other resolutions, the size scales proportionally.
  • The smart wrap style balances line lengths for a centered, even appearance.

On this page