Making clips
Thumbnails
Make a filmstrip of keyframe thumbnails, painted as each one lands.
createThumbnails(options) makes evenly spaced thumbnails of a source for a filmstrip, handing each to onThumbnail as it's decoded.
const ctx = strip.getContext('2d')
const tile = strip.width / 10
await createThumbnails({
source: '/video/interview.mp4',
count: 10,
onThumbnail: (index, image) => ctx.drawImage(image, index * tile, 0, tile, strip.height),
})
| Option | Type | Default | Description |
|---|---|---|---|
source | Blob | string | URL | HTMLVideoElement | - | What to read |
start | number | 0 | First thumbnail's time |
end | number | the end of the source | Thumbnails stop before this |
count | number | 10 | How many |
width | number | 160 | Thumbnail width; the height follows the source |
onThumbnail | (index, image, time) => void | - | Each thumbnail as it lands; draw it straight away |
signal | AbortSignal | - | Stops reading, cancelling any download in flight |
Each thumbnail is the nearest keyframe at or before its time, and thumbnails sharing a keyframe share one decode, so nothing after a keyframe is ever decoded. From an HLS stream, only the smallest variant that covers a thumbnail is read. The picture is reused once onThumbnail returns, so draw or copy it synchronously.