UNPKG

media-trimmer

Version:

A simple WebM and MP4 video trimmer using the WebCodecs API

53 lines (49 loc) 1.66 kB
export interface TrimOptions { /** The time in seconds of the original video to trim from. */ start: number /** The time in seconds of the original video to trim until. */ end: number /** Whether to include the existing audio track in the output. */ mute?: boolean /** * A subset set of VideoEncoder config options. * https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder/encode */ videoEncoderConfig?: { codec?: string bitrate?: number latencyMode?: LatencyMode hardwareAcceleration?: HardwareAcceleration } /** Credentials for fetching and demuxing URL */ credentials?: RequestCredentials /** How to handle cross origin URL for RVFC decoder */ crossOrigin?: 'anonymous' | 'use-credentials' | null /** A callback function that will be called with the progress of the trim */ onProgress?: ( /** A value between 0 and 1 */ value: number, ) => unknown } /** * @example * import { trim } from 'media-trimmer' * * try { * const blob = await trim('video.mp4', { * start: 2, // start time in seconds * end: 10, // end time in seconds * mute: false, // ignore the audio track? * }) * } catch (error) { * alert(error) * } * * @param source The url string or Blob of the input video file with a video track that the browser's * WebCodecs API can decode. * @param options An object with start, end, and other options. * @returns A promise that resolves to a Blob of the new, trimmed video file. */ export declare const trim: (source: string | Blob, options: TrimOptions) => Promise<Blob> export default trim export type * from './ui.ts'