Making clips

With another player

Use splice's core with Video.js, Plyr, hls.js or a plain <video>, without @munsonlabs/video-player.

Splice's core doesn't need @munsonlabs/video-player or Vue: @munsonlabs/splice depends only on Mediabunny. Only the editor is built on our player, because it uses the player as its preview. With any other player you call the core yourself and build the picker around it.

import { canSplice, createSplice } from '@munsonlabs/splice'

const video = document.querySelector<HTMLVideoElement>('#player video')!

const check = await canSplice(video, { crop: { aspect: '9:16' } })
if (check.ok) {
  const clip = await createSplice({
    source: video,
    start: video.currentTime,
    end: video.currentTime + 10,
    crop: { aspect: '9:16' },
  })
}

What to pass as the source

A <video> is read through its currentSrc, so it works when the player plays a file: a plain <video>, or Video.js and Plyr playing an MP4. Find the player's <video> (player.el().querySelector('video') in Video.js, player.media in Plyr) or pass the file's URL.

A player that plays HLS or DASH through hls.js, dash.js, Shaka or Video.js's own streaming feeds its <video> from a MediaSource. There's no file behind it, so createSplice refuses it with a clear error. Pass the stream's URL instead; splice reads the playlist itself and downloads only the smallest variant the clip needs.

const source = hls.url // the playlist hls.js was given, not the <video>

A <video> playing DRM-protected media or a live MediaStream (a camera, a screen or a call) can't be clipped at all. canSplice says so before you offer the button. See the errors.

Your own picker

The editor's range, crop window and filmstrip are yours to build. The core gives you the pieces:

  • The range is start and end in seconds on the source's timeline. Take them from your own handles, or around video.currentTime.
  • The crop is crop: { aspect, focus }, with focus from 0 to 1 across and down the frame. canSplice resolves the source's size in check.info, so you can draw the window over the picture. See crop.
  • A filmstrip comes from createThumbnails, each keyframe painted as it's decoded. See thumbnails.
  • Progress and cancel are onProgress and signal. See createSplice.

Captions

The editor burns in the captions the viewer has on. Without it, pass captions yourself: a WebVTT URL, WebVTT text or cues. To burn in what the player is showing, read the cues from the <video>'s text track. They're there for a track that's showing or hidden, and Video.js, Plyr and hls.js all put their captions on the <video> as text tracks.

const track = [...video.textTracks].find((track) => track.mode === 'showing')
const captions = [...(track?.cues ?? [])].map((cue) => ({
  start: cue.startTime,
  end: cue.endTime,
  text: (cue as VTTCue).text,
}))

await createSplice({ source, start, end, captions })

An HLS stream's subtitles load segment by segment, so only the cues around what's been played are there. See captions.

With an origin, the clip's metadata carries a link back to the moment: the page's URL with #ml-t=42,52 in its hash. Our player's deep-link answers it. With another player, read the hash yourself and seek:

const link = new URLSearchParams(location.hash.slice(1)).get('ml-t') // '42,52'
const [start, end] = link ? link.split(',').map(Number) : []

const stopAtEnd = () => {
  if (video.currentTime < end) return
  video.pause()
  video.removeEventListener('timeupdate', stopAtEnd)
}

if (start !== undefined) {
  video.currentTime = start
  if (end !== undefined) video.addEventListener('timeupdate', stopAtEnd)
}

createClipLink(origin, start, end) builds the same link, for a "copy link" button of your own. See origin and links.

munsonlabs · MIT licensed · © 2026