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
subtitleStyleobjectdefault ffmpegSubtitle appearance configuration

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.

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'
chunkOptionsobjectPunctuation-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