UNPKG

@diffusionstudio/core-v4

Version:

A fast, browser based video compositing engine powered by WebCodecs

128 lines (127 loc) 3.13 kB
import { Serializer } from '../services'; import { hex } from '../types'; import { Rect } from './interfaces'; type VideoRendererInit = { fps?: number; callback?(): Promise<void>; context?: AudioContext | OfflineAudioContext; audioDestination?: AudioNode; width?: number; height?: number; background?: hex | 'transparent'; resolution?: number; }; /** * Video and audio renderer combined */ export declare class Renderer extends Serializer { _background: hex | 'transparent'; /** * The canvas element */ readonly canvas: HTMLCanvasElement; /** * The main 2d context of the canvas */ readonly videoCtx: CanvasRenderingContext2D; /** * The resolution of the canvas */ resolution: number; /** * The width of the canvas * Initially 0 so the constructor will set the width */ width: number; /** * The height of the canvas * Initially 0 so the constructor will set the height */ height: number; /** * The scale of the text */ textScale: number; /** * The audio context */ readonly audioCtx: AudioContext | OfflineAudioContext; readonly audioDestination: AudioNode; /** * Offset in **seconds** relative to the hardware time when the playback started */ hardwareOffset: number; /** * Offset in **seconds** relative to 0 when the playback started */ playbackOffset: number; /** * The fps used when the ticker is inactive (not playing) */ inactiveFps: number; /** * Defines the current state of the ticker */ playing: boolean; /** * Defines if the ticker is active */ stopped: boolean; /** * The function to call when the ticker is updated */ private callback; /** * The last time the timer was updated */ private lastFrameTime; constructor({ width, height, background, resolution, callback, context, audioDestination, }?: VideoRendererInit); /** * The current time of the hardware in seconds */ get hardwareTime(): number; /** * The current time of the playback in **seconds** relative to 0 */ get playbackTime(): number; /** * Starts the animation loop */ start(): void; /** * Stops the animation loop */ stop(): void; /** * Starts the frame incrementation */ play(): Promise<void>; /** * Pauses the frame incrementation */ pause(): Promise<void>; /** * The animation loop */ private timer; private resumeAudioContext; /** * The background color of the canvas */ get background(): hex | 'transparent'; set background(background: hex | 'transparent'); /** * Resize the canvas */ resize(width?: number, height?: number, resolution?: number): this; clear(region?: Rect): this; /** * Add the renderer to the dom */ mount(element: HTMLElement): void; /** * Remove the renderer from the dom */ unmount(): void; } export {};