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

Live preview
no trim — full loop
Press Run demo

Plays the full video, looping from start.

{ /* no trim */ }
trim: 2s to 5s loop
Press Run demo

Repeats only the selected 2s–5s window.

{ 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
});
ts
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.

scroll.ts
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,
  },
});
OptionTypeDefaultDescription
triggerHTMLElement | stringfitTo or canvasElement whose scroll progress drives the video.
gsap / ScrollTriggerinstancesnoneYour own GSAP and plugin. ScrollTrigger is optional when available as gsap.ScrollTrigger.
start / end / scrubstring / boolean | numberscrub: truePassed to ScrollTrigger. The native fallback ignores start and end and always scrubs.
speednumber12 reaches the end in half the scroll distance; 0.5 takes twice as long. It changes progress mapping, not the source frame rate.
from / tosecondstrim rangeVideo time mapped from and to. Defaults to the trim start and end, or the whole clip.
ease / onUpdatefunctionnoneTransform progress before mapping, and observe it with the video element.