Node / Video Ffmpeg · guide
Frame extraction & previews
Current Apexify.js 6.0.0 documentation for Frame extraction & previews.
Same jobs without createVideo: Imperative video helpers (getVideoInfo, extractFrameAtTime, extractFrameByNumber, …).
extractFrame
What it does: Decodes one image from the video at a chosen time or frame index, optionally scales it.
Options explained
| Field | Effect |
|---|---|
time | Seek to this second before grabbing (most intuitive). If set, it drives extraction; frame is ignored for positioning. |
frame | Index (0 = start). Converted to time with frame / fps when time is omitted (fps from probe or assumed 30). |
width, height | Resize on a canvas after decode. Omit = native resolution. |
outputFormat | jpg or png for the intermediate FFmpeg output. |
quality | JPEG -q:v (lower = better quality, typical 2–5). PNG path ignores quality in practice. |
Return value: createVideo wraps the bitmap in a PNG buffer plus canvas: { width, height } (VideoCreator), even if you asked jpg internally.
Example — poster at 10s
extractFrames — mode A: times
What it does: Calls extractVideoFrame once per timestamp → Buffer[] in order.
| Field | Effect |
|---|---|
times | Array of seconds. |
outputFormat, quality | Same semantics as extractFrame. |
extractFrames — mode B: interval
What it does: Runs ApexPainter.extractFrames — FFmpeg -vf fps= derived from interval in milliseconds (fps = 1000 / interval).
| Field | Effect |
|---|---|
interval | Ms between samples (must be > 0). Smaller = more frames, larger disk use. |
frameSelection.start, end | Frame indices within the extracted sequence (trim the list). |
outputFormat, quality | JPEG/PNG quality flags. |
outputDirectory | Typed on VideoCreationOptions but not used by current extractFrames implementation — files land under .temp-frames/frames-<id>/. |
extractAllFrames
What it does: Dumps every frame in [startTime, endTime] to disk (large outputs).
| Field | Default | Effect |
|---|---|---|
outputDirectory | ./extracted-frames | Where prefix-%06d.ext files go. |
outputFormat | png | jpg smaller but lossy. |
quality | 2 | JPEG -q:v. |
prefix | frame | Filename prefix. |
startTime, endTime | 0 … duration | Time window in seconds. |
Returns { source, frameNumber, time }[] with time stepped by 1/fps (approximate).
generateThumbnail
What it does: Builds one PNG sheet: count thumbnails evenly spaced in time, arranged in grid.
| Field | Default | Effect |
|---|---|---|
count | 9 | How many stills. |
grid | 3×3 | cols × rows must fit count sensibly. |
width, height | 320×180 | Per-cell size (total canvas = cell × grid). |
outputFormat, quality | Passed through frame extraction. |
generatePreview
What it does: Writes count images to outputDirectory (like a storyboard dump, not one montage).
| Field | Default |
|---|---|
count | 10 |
outputDirectory | ./video-preview |
outputFormat | png |
quality | 2 |
detectScenes
What it does: Runs FFmpeg scene-detection filter and parses timestamps (shell pipeline — most reliable on Unix/Git Bash/WSL).
| Field | Default | Effect |
|---|---|---|
threshold | 0.3 | Higher → fewer cuts detected. |
outputPath | — | Optional JSON file [{ time, scene }]. |