import { file } from 'opfs-tools'; import { Log } from '@webav/internal-utils'; import { MP4Sample } from '@webav/mp4box.js'; declare type AnimateImgType = 'avif' | 'webp' | 'png' | 'gif'; /** * 音频素材,为创建、编辑音视频功能提供音频数据 * * @example * new AudioClip((await fetch('')).body, { * loop: true, * }), */ export declare class AudioClip implements IClip { #private; static ctx: AudioContext | null; ready: IClip['ready']; /** * 音频元信息 * * ⚠️ 注意,这里是转换后(标准化)的元信息,非原始音频元信息 */ get meta(): { sampleRate: 48000; chanCount: number; duration: number; width: number; height: number; }; /** * 获取音频素材完整的 PCM 数据 */ getPCMData(): Float32Array[]; /** * * @param dataSource 音频文件流 * @param opts 音频配置,控制音量、是否循环 */ constructor(dataSource: ReadableStream | Float32Array[], opts?: IAudioClipOpts); /** * 拦截 {@link AudioClip.tick} 方法返回的数据,用于对音频数据二次处理 * @param time 调用 tick 的时间 * @param tickRet tick 返回的数据 * * @see [移除视频绿幕背景](https://webav-tech.github.io/WebAV/demo/3_2-chromakey-video) */ tickInterceptor: >>(time: number, tickRet: T) => Promise; /** * 返回上次与当前时刻差对应的音频 PCM 数据; * * 若差值超过 3s 或当前时间小于上次时间,则重置状态 * @example * tick(0) // => [] * tick(1e6) // => [leftChanPCM(1s), rightChanPCM(1s)] * */ tick(time: number): Promise<{ audio: Float32Array[]; state: 'success' | 'done'; }>; /** * 按指定时间切割,返回前后两个音频素材 * @param time 时间,单位微秒 */ split(time: number): Promise<[this, this]>; clone(): Promise; /** * 销毁实例,释放资源 */ destroy(): void; static concatAudioClip: typeof concatAudioClip; } /** * Sprite 基类 * * @see {@link OffscreenSprite} * @see {@link VisibleSprite} */ declare abstract class BaseSprite { #private; /** * 控制素材在视频中的空间属性(坐标、旋转、缩放) */ rect: Rect; get time(): { offset: number; duration: number; playbackRate: number; }; set time(v: { offset: number; duration: number; playbackRate?: number; }); /** * 监听属性变更事件 * @example * sprite.on('propsChange', (changedProps) => {}) */ on: (type: Type, listener: { propsChange: (value: Partial<{ rect: Partial; zIndex: number; }>) => void; }[Type]) => (() => void); get zIndex(): number; /** * 控制素材间的层级关系,zIndex 值较小的素材会被遮挡 */ set zIndex(v: number); /** * 不透明度 */ opacity: number; /** * 水平或垂直方向翻转素材 */ flip: 'horizontal' | 'vertical' | null; /** * @see {@link IClip.ready} */ ready: Promise; constructor(); protected _render(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void; /** * 给素材添加动画,使用方法参考 css animation * * @example * sprite.setAnimation( * { * '0%': { x: 0, y: 0 }, * '25%': { x: 1200, y: 680 }, * '50%': { x: 1200, y: 0 }, * '75%': { x: 0, y: 680 }, * '100%': { x: 0, y: 0 }, * }, * { duration: 4e6, iterCount: 1 }, * ); * * @see [视频水印动画](https://webav-tech.github.io/WebAV/demo/2_1-concat-video) */ setAnimation(keyFrame: TKeyFrameOpts, opts: IAnimationOpts): void; /** * 如果当前 sprite 已被设置动画,将 sprite 的动画属性设定到指定时间的状态 */ animate(time: number): void; /** * 将当前 sprite 的属性赋值到目标 * * 用于 clone,或 {@link VisibleSprite} 与 {@link OffscreenSprite} 实例间的类型转换 */ copyStateTo(target: T): void; protected destroy(): void; } /** * 视频合成器;能添加多个 {@link OffscreenSprite},根据它们位置、层级、时间偏移等信息,合成输出为视频文件 * @see [视频合成](https://webav-tech.github.io/WebAV/demo/2_1-concat-video) * @see [视频配音](https://webav-tech.github.io/WebAV/demo/2_2-video-add-audio) * @example * const spr1 = new OffscreenSprite( * new MP4Clip((await fetch('')).body), * ); * const spr2 = new OffscreenSprite( * new AudioClip((await fetch('