Trim / clip
Play only a specific time window of a video — set a start and/or end in seconds. The player repeats the selected time range. A visually seamless loop also requires matching source poses and lighting at its boundaries. Works in both live streaming and preExtract modes.
Live preview
Plays the full video, looping from start.
{ /* no trim */ }Repeats only the selected 2s–5s window.
{ trim: { start: 2, end: 5 } }Usage
import { asciifyVideo } from 'asciify-engine';
// Loop seconds 2–8 only
const stop = await asciifyVideo('/clip.mp4', canvas, {
trim: { start: 2, end: 8 },
});
// Start at 5s, loop to end of file
const stop = await asciifyVideo('/clip.mp4', canvas, {
trim: { start: 5 },
});
// End at 10s from the beginning (no offset)
const stop = await asciifyVideo('/clip.mp4', canvas, {
trim: { end: 10 },
});With preExtract
In preExtract mode, only frames within the trim window are decoded — no wasted memory.
asciifyVideo('/clip.mp4', canvas, {
preExtract: true,
trim: { start: 2, end: 6 }, // only extracts 4 seconds worth of frames
});asciifyVideo('/greenscreen.mp4', canvas, {
trim: { start: 1, end: 7 },
options: {
chromaKey: true,
colorMode: 'fullcolor',
},
});Scroll-scrubbed video
Pass scroll to map page scroll to video time instead of playing on a clock. true uses native viewport progress; pass your installed gsap and ScrollTrigger to drive it from ScrollTrigger. Leave preExtract off: scrubbing works in live mode, and maxCachedFrames bounds the frames kept near the playhead.
import { asciifyVideo } from 'asciify-engine';
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
// Native scroll progress:
const stop = await asciifyVideo('/hero.mp4', canvas, { fitTo: '#hero', scroll: true });
// GSAP ScrollTrigger:
const stop = await asciifyVideo('/hero.mp4', canvas, {
fitTo: '#hero',
trim: { start: 1, end: 5 },
scroll: {
gsap, ScrollTrigger,
trigger: '#hero',
start: 'top bottom',
end: 'bottom top',
scrub: 1,
speed: 1.5,
},
});| Option | Type | Default | Description |
|---|---|---|---|
trigger | HTMLElement | string | fitTo or canvas | Element whose scroll progress drives the video. |
gsap / ScrollTrigger | instances | none | Your own GSAP and plugin. ScrollTrigger is optional when available as gsap.ScrollTrigger. |
start / end / scrub | string / boolean | number | scrub: true | Passed to ScrollTrigger. The native fallback ignores start and end and always scrubs. |
speed | number | 1 | 2 reaches the end in half the scroll distance; 0.5 takes twice as long. It changes progress mapping, not the source frame rate. |
from / to | seconds | trim range | Video time mapped from and to. Defaults to the trim start and end, or the whole clip. |
ease / onUpdate | function | none | Transform progress before mapping, and observe it with the video element. |