09
Trim / Clip
Play only a specific time window of a video — set a start and/or end in seconds. The player loops seamlessly within the clip. Works in both live streaming and preExtract modes.
Live preview
Live preview
no trim — full loop
press run →
Plays the full video, looping from start.
{ /* no trim */ }trim: 2s → 5s loop
press run →
Loops only the 2s–5s window, seamlessly.
{ trim: { start: 2, end: 5 } }Usage
trim.ts
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.
ts
asciifyVideo('/clip.mp4', canvas, {
preExtract: true,
trim: { start: 2, end: 6 }, // only extracts 4 seconds worth of frames
});Tip
Combine with
chromaKey to loop a trimmed green screen clip with full transparency:ts
asciifyVideo('/greenscreen.mp4', canvas, {
trim: { start: 1, end: 7 },
options: {
chromaKey: true,
colorMode: 'fullcolor',
},
});