API Reference

Recast Class

Complete API reference for the Recast pipeline class — static methods, chainable stages, and terminal operations

The Recast class (exported as Pipeline internally) is the entry point for building video pipelines. It is immutable — every method returns a new pipeline instance. Nothing executes until a terminal operation is called.

import { Recast } from 'playwright-recast'

Static Methods

Recast.from(source)

Create a new pipeline from a trace directory or zip file path.

const pipeline = Recast.from('./test-results/trace.zip')
ParameterTypeDescription
sourcestringPath to a .zip trace file or directory containing trace files

Returns: Pipeline


Chainable Methods

All chainable methods return a new Pipeline instance. The original pipeline is not modified.

.parse()

Parse the Playwright trace into structured data (actions, frames, network, cursor positions).

.parse()

Must be called before any other processing stage. Extracts ParsedTrace from the trace zip.


.hideSteps(predicate)

Filter out steps matching the predicate. Hidden steps do not appear in the output video.

.hideSteps(action => action.keyword === 'Given' && action.text?.includes('logged in'))
ParameterTypeDescription
predicate(action: TraceAction) => booleanReturns true for actions to hide

.speedUp(config)

Adjust video speed based on trace activity classification.

.speedUp({
  duringIdle: 4.0,
  duringUserAction: 1.0,
  duringNetworkWait: 2.0,
  duringNavigation: 2.0,
  minSegmentDuration: 500,
  maxSpeed: 8.0,
})
OptionTypeDefaultDescription
duringIdlenumber4.0Speed during idle periods
duringUserActionnumber1.0Speed during user actions
duringNetworkWaitnumber2.0Speed while waiting for network
duringNavigationnumber2.0Speed during page loads
minSegmentDurationnumber500Minimum segment duration (ms) before speed change
maxSpeednumber100.0Maximum speed multiplier
rulesSpeedRule[]Custom speed rules (evaluated first)
segmentsArray<{startMs, endMs, speed}>Pre-built speed segments (bypasses classification)
recordingPageIdstringFilter actions to this page ID
postFastForwardSettleMsnumber0Extra delay after fast-forward zones

See SpeedConfig for the full type definition.


.subtitles(textFn, options?)

Generate subtitles from trace actions using a custom text extraction function.

.subtitles(action => action.docString ?? action.text)
ParameterTypeDescription
textFn(action: TraceAction) => string | undefinedExtracts display text from each action
optionsSubtitleOptionsOptional format settings

.subtitlesFromSrt(srtPath)

Load subtitles from an external SRT file.

.subtitlesFromSrt('./narration.srt')
ParameterTypeDescription
srtPathstringPath to the SRT file

.subtitlesFromTrace(options?)

Auto-generate subtitles from BDD step titles in the parsed trace.

.subtitlesFromTrace()
ParameterTypeDescription
optionsSubtitleOptionsOptional format settings

.textProcessing(config)

Sanitize subtitle text before TTS synthesis. Writes to ttsText field — visual subtitles keep original text.

.textProcessing({ builtins: true })
OptionTypeDefaultDescription
builtinsbooleanfalseEnable built-in sanitization rules
rulesTextProcessingRule[]Custom regex find/replace rules
transform(text: string) => stringCustom transform function

.autoZoom(config?)

Auto-zoom into user actions detected from the trace.

.autoZoom({ inputLevel: 1.4, clickLevel: 1.5 })
OptionTypeDefaultDescription
clickLevelnumber1.5Zoom level for click actions
inputLevelnumber1.6Zoom level for fill/type actions
idleLevelnumber1.0Zoom during idle (1.0 = none)
centerBiasnumber0.2Blend toward center (0-1)
transitionMsnumber400Transition duration in ms
easingEasingSpec'ease-in-out'Easing function for transitions

.enrichZoomFromReport(steps)

Apply zoom coordinates from external data (e.g., demo report with per-step zoom).

.enrichZoomFromReport([
  { zoom: null },
  { zoom: { x: 0.5, y: 0.8, level: 1.4 } },
])
ParameterTypeDescription
stepsArray<{ zoom?: { x: number; y: number; level: number } | null }>Zoom data per step

.cursorOverlay(config?)

Render an animated cursor that moves between action positions.

.cursorOverlay({ size: 24, easing: 'ease-out' })
OptionTypeDefaultDescription
imagestringCustom cursor image path (PNG)
sizenumber24Cursor size in px (relative to 1080p)
colorstring'#FFFFFF'Dot color (hex)
opacitynumber0.9Opacity 0.0-1.0
easingstring'ease-in-out'Movement easing
hideAfterMsnumber500Fade-out delay after last action
shadowbooleantrueDrop shadow on cursor
filter(action: TraceAction) => booleanFilter which actions generate cursor positions

.clickEffect(config?)

Add animated ripple effects at click positions with optional sound.

.clickEffect({ color: '#3B82F6', sound: true })
OptionTypeDefaultDescription
colorstring'#3B82F6'Ripple color (hex)
opacitynumber0.5Ripple opacity 0.0-1.0
radiusnumber30Max radius in px (relative to 1080p)
durationnumber400Animation duration in ms
soundstring | trueClick sound path, or true for bundled default
soundVolumenumber0.8Sound volume 0.0-1.0
filter(action: TraceAction) => booleanFilter which clicks to highlight

.textHighlight(config?)

Render animated marker overlays on text captured by the highlight() helper.

.textHighlight({ color: '#FFEB3B', opacity: 0.35 })
OptionTypeDefaultDescription
colorstring'#FFEB3B'Highlight color (hex)
opacitynumber0.35Highlight opacity 0.0-1.0
durationnumber3000Visibility duration in ms
fadeOutnumber500Fade-out duration in ms
swipeDurationnumber300Swipe-in animation duration in ms
padding{ x?: number; y?: number }Padding around bounding box in px
filter(highlight: HighlightEvent) => booleanFilter which highlights to render

.intro(config)

Prepend an intro video with a crossfade transition.

.intro({ path: './assets/intro.mp4', fadeDuration: 500 })
OptionTypeDefaultDescription
pathstringrequiredPath to intro video file
fadeDurationnumber500Crossfade duration in ms

.outro(config)

Append an outro video with a crossfade transition.

.outro({ path: './assets/outro.mp4', fadeDuration: 500 })
OptionTypeDefaultDescription
pathstringrequiredPath to outro video file
fadeDurationnumber500Crossfade duration in ms

.interpolate(config?)

Apply frame interpolation for smoother video output using ffmpeg's minterpolate filter.

.interpolate({ fps: 60, mode: 'blend' })
OptionTypeDefaultDescription
fpsnumber60Target frames per second
mode'dup' | 'blend' | 'mci''mci'Interpolation mode
quality'fast' | 'balanced' | 'quality''balanced'Quality preset
passesnumber1Multi-pass count for smoother results

.backgroundMusic(config)

Add background music with auto-ducking during voiceover.

.backgroundMusic({ path: './assets/music.mp3', volume: 0.3 })
OptionTypeDefaultDescription
pathstringrequiredPath to music audio file
volumenumber0.3Base volume 0.0-1.0
duckingbooleantrueAuto-duck during voiceover
duckLevelnumber0.1Volume during voiceover 0.0-1.0
duckFadeMsnumber500Ducking transition duration in ms
fadeOutMsnumber3000Fade-out at end of video in ms
loopbooleantrueLoop if shorter than video

.voiceover(provider)

Generate TTS audio from subtitle text using a provider.

.voiceover(OpenAIProvider({ voice: 'nova' }))
ParameterTypeDescription
providerTtsProviderA TTS provider instance (OpenAI or ElevenLabs)

.render(config?)

Configure video rendering options.

.render({ format: 'mp4', resolution: '1080p', fps: 60, burnSubtitles: true })
OptionTypeDefaultDescription
format'mp4' | 'webm''mp4'Output format
resolutionstring | { width, height }'1080p'Output resolution
fpsnumberOutput frame rate
burnSubtitlesbooleanfalseBurn subtitles into video
subtitleStyleSubtitleStyleSubtitle styling options
codecstringVideo codec override
crfnumberConstant rate factor (quality)

Terminal Operations

Terminal operations execute the pipeline. Nothing runs until one of these is called.

.toFile(outputPath)

Execute the pipeline and write the result to a file.

await pipeline.toFile('demo.mp4')
ParameterTypeDescription
outputPathstringOutput file path

Returns: Promise<void>


.toBuffer()

Execute the pipeline and return the result as a buffer.

const buffer = await pipeline.toBuffer()

Returns: Promise<Buffer>


Inspection Methods

.getStages()

Get the list of stages (for testing/debugging).

Returns: readonly StageDescriptor[]

.getSource()

Get the trace source path.

Returns: string

On this page