@remotion/video-matting 4.0.523
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/can-use-video-matting.d.ts +18 -0
- package/dist/create-video-layer-output.d.ts +14 -0
- package/dist/esm/index.mjs +1675 -0
- package/dist/index.d.ts +14 -0
- package/dist/is-video-matting-model-cached.d.ts +5 -0
- package/dist/load-video-matting-model.d.ts +35 -0
- package/dist/models.d.ts +17 -0
- package/dist/output-target.d.ts +13 -0
- package/dist/prepare-audio.d.ts +28 -0
- package/dist/remove-video-matting-model.d.ts +5 -0
- package/dist/separate-video-layers.d.ts +43 -0
- package/dist/video-matting-canvas.d.ts +22 -0
- package/dist/video-matting-quality.d.ts +5 -0
- package/dist/video-timing.d.ts +22 -0
- package/dist/web-fs-target.d.ts +8 -0
- package/dist/with-remotion-model-host.d.ts +10 -0
- package/package.json +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { canUseVideoMatting, VideoMattingUnsupportedReason, } from './can-use-video-matting';
|
|
2
|
+
export type { CanUseVideoMattingOptions, CanUseVideoMattingResult, } from './can-use-video-matting';
|
|
3
|
+
export { disposeVideoMattingModel, loadVideoMattingModel, } from './load-video-matting-model';
|
|
4
|
+
export type { DisposeVideoMattingModelOptions, LoadVideoMattingModelOptions, LoadVideoMattingModelResult, OnVideoMattingModelLoadProgress, VideoMattingModelLoadProgress, } from './load-video-matting-model';
|
|
5
|
+
export { isVideoMattingModelCached } from './is-video-matting-model-cached';
|
|
6
|
+
export type { IsVideoMattingModelCachedOptions } from './is-video-matting-model-cached';
|
|
7
|
+
export { removeVideoMattingModel } from './remove-video-matting-model';
|
|
8
|
+
export type { RemoveVideoMattingModelOptions } from './remove-video-matting-model';
|
|
9
|
+
export { getAvailableModels } from './models';
|
|
10
|
+
export type { VideoMattingModel, VideoMattingModelInfo } from './models';
|
|
11
|
+
export type { VideoLayerOutput, VideoLayerOutputOptions, VideoLayerOutputTarget, } from './output-target';
|
|
12
|
+
export { separateVideoLayers } from './separate-video-layers';
|
|
13
|
+
export type { SeparateVideoLayersOptions, SeparateVideoLayersProgress, SeparateVideoLayersResult, VideoLayerAudio, } from './separate-video-layers';
|
|
14
|
+
export type { VideoMattingBitrate, VideoMattingQuality, } from './video-matting-quality';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type VideoMattingModel } from './models';
|
|
2
|
+
export type VideoMattingModelLoadProgress = {
|
|
3
|
+
status: string;
|
|
4
|
+
file: string | null;
|
|
5
|
+
progress: number | null;
|
|
6
|
+
loadedBytes: number | null;
|
|
7
|
+
totalBytes: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type OnVideoMattingModelLoadProgress = (progress: VideoMattingModelLoadProgress) => void;
|
|
10
|
+
export type VideoMattingImageSource = HTMLCanvasElement | OffscreenCanvas;
|
|
11
|
+
export type VideoMattingPipelineResult = {
|
|
12
|
+
data: Uint8ClampedArray<ArrayBuffer>;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
channels: 4;
|
|
16
|
+
};
|
|
17
|
+
export type LoadedVideoMattingPipeline = (image: VideoMattingImageSource) => Promise<VideoMattingPipelineResult>;
|
|
18
|
+
export type LoadVideoMattingModelOptions = {
|
|
19
|
+
model: VideoMattingModel;
|
|
20
|
+
onProgress?: OnVideoMattingModelLoadProgress;
|
|
21
|
+
};
|
|
22
|
+
export type LoadVideoMattingModelResult = {
|
|
23
|
+
alreadyLoaded: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare const loadVideoMattingModel: ({ model, onProgress, }: LoadVideoMattingModelOptions) => Promise<LoadVideoMattingModelResult>;
|
|
26
|
+
export declare const withLoadedVideoMattingPipeline: <ReturnValue>({ model, onProgress, signal, run, }: {
|
|
27
|
+
model: "ben2-base" | "modnet";
|
|
28
|
+
onProgress?: OnVideoMattingModelLoadProgress | undefined;
|
|
29
|
+
signal: AbortSignal | null;
|
|
30
|
+
run: (pipeline: LoadedVideoMattingPipeline) => Promise<ReturnValue>;
|
|
31
|
+
}) => Promise<ReturnValue>;
|
|
32
|
+
export type DisposeVideoMattingModelOptions = {
|
|
33
|
+
model?: VideoMattingModel;
|
|
34
|
+
};
|
|
35
|
+
export declare const disposeVideoMattingModel: ({ model, }?: DisposeVideoMattingModelOptions) => Promise<void>;
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const VIDEO_MATTING_MODELS: readonly ["modnet", "ben2-base"];
|
|
2
|
+
export type VideoMattingModel = (typeof VIDEO_MATTING_MODELS)[number];
|
|
3
|
+
export type VideoMattingModelInfo = {
|
|
4
|
+
name: VideoMattingModel;
|
|
5
|
+
modelId: string;
|
|
6
|
+
purpose: 'person' | 'general';
|
|
7
|
+
webGpuDownloadSize: number;
|
|
8
|
+
};
|
|
9
|
+
type InternalVideoMattingModelInfo = VideoMattingModelInfo & {
|
|
10
|
+
revision: string;
|
|
11
|
+
dtype: 'fp32' | 'fp16';
|
|
12
|
+
requiresShaderF16: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const getAvailableModels: () => VideoMattingModelInfo[];
|
|
15
|
+
export declare const getVideoMattingModelInfo: (model: "ben2-base" | "modnet") => InternalVideoMattingModelInfo;
|
|
16
|
+
export declare const getHostedVideoMattingModelId: (model: "ben2-base" | "modnet") => string;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StreamTargetChunk } from 'mediabunny';
|
|
2
|
+
export type VideoLayerOutputTarget = 'arraybuffer' | 'web-fs';
|
|
3
|
+
export type VideoLayerOutputOptions = {
|
|
4
|
+
outputTarget?: VideoLayerOutputTarget;
|
|
5
|
+
outputWritable?: never;
|
|
6
|
+
} | {
|
|
7
|
+
outputTarget?: never;
|
|
8
|
+
outputWritable: WritableStream<StreamTargetChunk>;
|
|
9
|
+
};
|
|
10
|
+
export type VideoLayerOutput = {
|
|
11
|
+
getBlob: () => Promise<Blob>;
|
|
12
|
+
dispose: () => Promise<void>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Input, type Output, Quality, type Target, type WebMOutputFormat } from 'mediabunny';
|
|
2
|
+
export type VideoMattingAudioDestination = 'base' | 'foreground' | 'both' | 'none';
|
|
3
|
+
export type PreparedVideoMattingAudio = {
|
|
4
|
+
/**
|
|
5
|
+
* Queues the first audio packet or sample, even when it starts after the
|
|
6
|
+
* first video frame. Call this after the outputs have started.
|
|
7
|
+
*/
|
|
8
|
+
prime: () => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Writes audio whose rebased start timestamp is at or before the given
|
|
11
|
+
* output timestamp. Calls must use monotonically increasing timestamps.
|
|
12
|
+
*/
|
|
13
|
+
writeAudioUntil: (outputTimestamp: number) => Promise<void>;
|
|
14
|
+
/** Writes the remaining audio up to the end of the video and closes it. */
|
|
15
|
+
finishAudio: () => Promise<void>;
|
|
16
|
+
/** Releases decoded samples that have not been written yet. */
|
|
17
|
+
cancel: () => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export declare const prepareAudio: <BaseTarget extends Target, ForegroundTarget extends Target>({ input, baseOutput, foregroundOutput, destination, videoStartTimestamp, videoEndTimestamp, audioQuality, forceTranscode, }: {
|
|
20
|
+
input: Input<import("mediabunny").Source>;
|
|
21
|
+
baseOutput: Output<WebMOutputFormat, BaseTarget>;
|
|
22
|
+
foregroundOutput: Output<WebMOutputFormat, ForegroundTarget>;
|
|
23
|
+
destination: VideoMattingAudioDestination;
|
|
24
|
+
videoStartTimestamp: number;
|
|
25
|
+
videoEndTimestamp: number;
|
|
26
|
+
audioQuality: Quality | null;
|
|
27
|
+
forceTranscode: boolean;
|
|
28
|
+
}) => Promise<PreparedVideoMattingAudio>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type OnVideoMattingModelLoadProgress } from './load-video-matting-model';
|
|
2
|
+
import { type VideoMattingModel } from './models';
|
|
3
|
+
import type { VideoLayerOutput, VideoLayerOutputOptions } from './output-target';
|
|
4
|
+
import { type VideoMattingBitrate } from './video-matting-quality';
|
|
5
|
+
export type VideoLayerAudio = 'base' | 'foreground' | 'both' | 'none';
|
|
6
|
+
type VideoLayerProgressFields = {
|
|
7
|
+
processedFrames: number;
|
|
8
|
+
processedDurationInSeconds: number;
|
|
9
|
+
durationInSeconds: number;
|
|
10
|
+
};
|
|
11
|
+
export type SeparateVideoLayersProgress = (VideoLayerProgressFields & {
|
|
12
|
+
stage: 'processing';
|
|
13
|
+
progress: number;
|
|
14
|
+
}) | (VideoLayerProgressFields & {
|
|
15
|
+
stage: 'finalizing';
|
|
16
|
+
progress: null;
|
|
17
|
+
});
|
|
18
|
+
export type SeparateVideoLayersOptions = {
|
|
19
|
+
src: string | URL | Blob;
|
|
20
|
+
model?: VideoMattingModel;
|
|
21
|
+
audio?: VideoLayerAudio;
|
|
22
|
+
outputs?: {
|
|
23
|
+
base?: VideoLayerOutputOptions;
|
|
24
|
+
foreground?: VideoLayerOutputOptions;
|
|
25
|
+
};
|
|
26
|
+
videoBitrate?: VideoMattingBitrate;
|
|
27
|
+
audioBitrate?: VideoMattingBitrate;
|
|
28
|
+
keyframeIntervalInSeconds?: number;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
onModelLoadProgress?: OnVideoMattingModelLoadProgress;
|
|
31
|
+
onProgress?: (progress: SeparateVideoLayersProgress) => void;
|
|
32
|
+
};
|
|
33
|
+
export type SeparateVideoLayersResult = {
|
|
34
|
+
base: VideoLayerOutput;
|
|
35
|
+
foreground: VideoLayerOutput;
|
|
36
|
+
model: VideoMattingModel;
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
durationInSeconds: number;
|
|
40
|
+
processedFrames: number;
|
|
41
|
+
};
|
|
42
|
+
export declare const separateVideoLayers: (options: SeparateVideoLayersOptions) => Promise<SeparateVideoLayersResult>;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { VideoMattingPipelineResult } from './load-video-matting-model';
|
|
2
|
+
export type VideoMattingCanvas = HTMLCanvasElement | OffscreenCanvas;
|
|
3
|
+
type VideoMattingCanvasContext = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
4
|
+
export declare const createVideoMattingCanvas: ({ width, height, }: {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}) => VideoMattingCanvas;
|
|
8
|
+
export declare const getVideoMattingCanvasContext: (canvas: VideoMattingCanvas) => VideoMattingCanvasContext;
|
|
9
|
+
export declare const drawOpaqueBaseFrame: ({ context, source, width, height, }: {
|
|
10
|
+
context: VideoMattingCanvasContext;
|
|
11
|
+
source: VideoMattingCanvas;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}) => void;
|
|
15
|
+
export declare const drawForegroundFrame: ({ context, result, source, targetWidth, targetHeight, }: {
|
|
16
|
+
context: VideoMattingCanvasContext;
|
|
17
|
+
result: VideoMattingPipelineResult;
|
|
18
|
+
source: VideoMattingCanvas;
|
|
19
|
+
targetWidth: number;
|
|
20
|
+
targetHeight: number;
|
|
21
|
+
}) => void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Quality } from 'mediabunny';
|
|
2
|
+
export declare const VIDEO_MATTING_QUALITIES: readonly ["very-low", "low", "medium", "high", "very-high"];
|
|
3
|
+
export type VideoMattingQuality = (typeof VIDEO_MATTING_QUALITIES)[number];
|
|
4
|
+
export type VideoMattingBitrate = number | VideoMattingQuality;
|
|
5
|
+
export declare const resolveVideoMattingQuality: (value: VideoMattingBitrate) => Quality;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const rebaseVideoTimestamp: ({ timestamp, firstVideoTimestamp, }: {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
firstVideoTimestamp: number;
|
|
4
|
+
}) => number;
|
|
5
|
+
export declare const getClippedVideoFrameTiming: ({ timestamp, duration, videoStartTimestamp, videoEndTimestamp, }: {
|
|
6
|
+
timestamp: number;
|
|
7
|
+
duration: number;
|
|
8
|
+
videoStartTimestamp: number;
|
|
9
|
+
videoEndTimestamp: number;
|
|
10
|
+
}) => {
|
|
11
|
+
timestamp: number;
|
|
12
|
+
duration: number;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare const getVideoProcessingProgress: ({ timestamp, duration, firstVideoTimestamp, durationInSeconds, }: {
|
|
15
|
+
timestamp: number;
|
|
16
|
+
duration: number;
|
|
17
|
+
firstVideoTimestamp: number;
|
|
18
|
+
durationInSeconds: number;
|
|
19
|
+
}) => {
|
|
20
|
+
processedDurationInSeconds: number;
|
|
21
|
+
progress: number;
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StreamTargetChunk } from 'mediabunny';
|
|
2
|
+
export declare const canUseWebFsWriter: () => Promise<boolean>;
|
|
3
|
+
export type WebFsVideoLayerTarget = {
|
|
4
|
+
stream: WritableStream<StreamTargetChunk>;
|
|
5
|
+
getBlob: () => Promise<Blob>;
|
|
6
|
+
remove: () => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare const createWebFsVideoLayerTarget: () => Promise<WebFsVideoLayerTarget>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AutoModelForImageSegmentation, AutoProcessor, BackgroundRemovalPipeline, env, ModelRegistry } from '@huggingface/transformers';
|
|
2
|
+
type TransformersModule = {
|
|
3
|
+
readonly AutoModelForImageSegmentation: typeof AutoModelForImageSegmentation;
|
|
4
|
+
readonly AutoProcessor: typeof AutoProcessor;
|
|
5
|
+
readonly BackgroundRemovalPipeline: typeof BackgroundRemovalPipeline;
|
|
6
|
+
readonly env: typeof env;
|
|
7
|
+
readonly ModelRegistry: typeof ModelRegistry;
|
|
8
|
+
};
|
|
9
|
+
export declare const withRemotionModelHost: <ReturnValue>(operation: (transformers: TransformersModule) => Promise<ReturnValue>) => Promise<ReturnValue>;
|
|
10
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@remotion/video-matting",
|
|
3
|
+
"version": "4.0.523",
|
|
4
|
+
"description": "Separate a video into a base layer and transparent foreground in the browser",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/esm/index.mjs",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/video-matting"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "bun test src/test",
|
|
14
|
+
"formatting": "oxfmt src --check",
|
|
15
|
+
"format": "oxfmt src",
|
|
16
|
+
"lint": "eslint src",
|
|
17
|
+
"watch": "tsgo -w",
|
|
18
|
+
"make": "tsgo && bun --env-file=../.env.bundle bundle.ts"
|
|
19
|
+
},
|
|
20
|
+
"author": "Jonny Burger <jonny@remotion.dev>",
|
|
21
|
+
"contributors": [],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"mediabunny": "1.55.5"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@huggingface/transformers": "4.2.0"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"module": "./dist/esm/index.mjs",
|
|
36
|
+
"import": "./dist/esm/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@huggingface/transformers": "4.2.0",
|
|
42
|
+
"@remotion/eslint-config-internal": "4.0.523",
|
|
43
|
+
"@typescript/native-preview": "7.0.0-dev.20260217.1",
|
|
44
|
+
"eslint": "9.19.0"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"remotion",
|
|
48
|
+
"video-matting",
|
|
49
|
+
"background-removal",
|
|
50
|
+
"webgpu"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://www.remotion.dev/docs/video-matting"
|
|
56
|
+
}
|