@bendyline/squisq-video-react 1.1.1 → 1.2.0
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/dist/index.d.ts +171 -19
- package/dist/index.js +921 -21
- package/dist/index.js.map +1 -1
- package/dist/workers/encode.worker.d.ts +2 -13
- package/dist/workers/encode.worker.js +258 -304
- package/dist/workers/encode.worker.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/encodeParams.test.ts +33 -0
- package/src/workers/encode.worker.ts +1 -13
- package/src/workers/encodeParams.ts +24 -0
- package/dist/VideoExportButton.d.ts +0 -28
- package/dist/VideoExportButton.d.ts.map +0 -1
- package/dist/VideoExportButton.js +0 -18
- package/dist/VideoExportButton.js.map +0 -1
- package/dist/VideoExportModal.d.ts +0 -26
- package/dist/VideoExportModal.d.ts.map +0 -1
- package/dist/VideoExportModal.js +0 -164
- package/dist/VideoExportModal.js.map +0 -1
- package/dist/hooks/useFrameCapture.d.ts +0 -27
- package/dist/hooks/useFrameCapture.d.ts.map +0 -1
- package/dist/hooks/useFrameCapture.js +0 -211
- package/dist/hooks/useFrameCapture.js.map +0 -1
- package/dist/hooks/useVideoExport.d.ts +0 -75
- package/dist/hooks/useVideoExport.d.ts.map +0 -1
- package/dist/hooks/useVideoExport.js +0 -266
- package/dist/hooks/useVideoExport.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mainThreadEncoder.d.ts +0 -44
- package/dist/mainThreadEncoder.d.ts.map +0 -1
- package/dist/mainThreadEncoder.js +0 -123
- package/dist/mainThreadEncoder.js.map +0 -1
- package/dist/mp4Mux.d.ts +0 -22
- package/dist/mp4Mux.d.ts.map +0 -1
- package/dist/mp4Mux.js +0 -32
- package/dist/mp4Mux.js.map +0 -1
- package/dist/workerEncoder.d.ts +0 -17
- package/dist/workerEncoder.d.ts.map +0 -1
- package/dist/workerEncoder.js +0 -103
- package/dist/workerEncoder.js.map +0 -1
- package/dist/workers/encode.worker.d.ts.map +0 -1
- package/dist/workers/workerTypes.d.ts +0 -63
- package/dist/workers/workerTypes.d.ts.map +0 -1
- package/dist/workers/workerTypes.js +0 -8
- package/dist/workers/workerTypes.js.map +0 -1
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useFrameCapture — Hidden div + html2canvas frame capture.
|
|
3
|
-
*
|
|
4
|
-
* Mounts a DocPlayer in renderMode inside a hidden div (same document),
|
|
5
|
-
* then captures individual frames by seeking the player and rendering
|
|
6
|
-
* the DOM to a canvas via html2canvas.
|
|
7
|
-
*
|
|
8
|
-
* Uses React directly — no script injection, no iframes, no eval.
|
|
9
|
-
*
|
|
10
|
-
* Returns an ImageBitmap for each frame (transferable to a Worker).
|
|
11
|
-
*/
|
|
12
|
-
import { createElement } from 'react';
|
|
13
|
-
import { createRoot } from 'react-dom/client';
|
|
14
|
-
import { useRef, useCallback, useMemo } from 'react';
|
|
15
|
-
import { DocPlayer, MediaContext } from '@bendyline/squisq-react';
|
|
16
|
-
import html2canvas from 'html2canvas';
|
|
17
|
-
/** Extension → MIME type map (hoisted to avoid per-image allocation). */
|
|
18
|
-
const MIME_MAP = {
|
|
19
|
-
jpg: 'image/jpeg',
|
|
20
|
-
jpeg: 'image/jpeg',
|
|
21
|
-
png: 'image/png',
|
|
22
|
-
gif: 'image/gif',
|
|
23
|
-
webp: 'image/webp',
|
|
24
|
-
svg: 'image/svg+xml',
|
|
25
|
-
bmp: 'image/bmp',
|
|
26
|
-
avif: 'image/avif',
|
|
27
|
-
};
|
|
28
|
-
/** Convert an ArrayBuffer to a base64 data URI using chunked encoding (O(n)). */
|
|
29
|
-
function arrayBufferToDataUrl(buffer, mime) {
|
|
30
|
-
const bytes = new Uint8Array(buffer);
|
|
31
|
-
const chunks = [];
|
|
32
|
-
const CHUNK = 8192;
|
|
33
|
-
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
34
|
-
chunks.push(String.fromCharCode(...bytes.subarray(i, i + CHUNK)));
|
|
35
|
-
}
|
|
36
|
-
return `data:${mime};base64,${btoa(chunks.join(''))}`;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create an inline MediaProvider from a map of paths to ArrayBuffers.
|
|
40
|
-
*/
|
|
41
|
-
function createInlineProvider(images) {
|
|
42
|
-
const dataUrls = new Map();
|
|
43
|
-
const mimeTypes = new Map();
|
|
44
|
-
for (const [path, buffer] of images) {
|
|
45
|
-
const ext = path.split('.').pop()?.toLowerCase() ?? '';
|
|
46
|
-
const mime = MIME_MAP[ext] ?? 'application/octet-stream';
|
|
47
|
-
dataUrls.set(path, arrayBufferToDataUrl(buffer, mime));
|
|
48
|
-
mimeTypes.set(path, mime);
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
async resolveUrl(relativePath) {
|
|
52
|
-
return dataUrls.get(relativePath) ?? relativePath;
|
|
53
|
-
},
|
|
54
|
-
async listMedia() {
|
|
55
|
-
return [...dataUrls.keys()].map((name) => ({
|
|
56
|
-
name,
|
|
57
|
-
mimeType: mimeTypes.get(name) ?? 'application/octet-stream',
|
|
58
|
-
size: 0,
|
|
59
|
-
}));
|
|
60
|
-
},
|
|
61
|
-
async addMedia() {
|
|
62
|
-
throw new Error('Read-only');
|
|
63
|
-
},
|
|
64
|
-
async removeMedia() {
|
|
65
|
-
throw new Error('Read-only');
|
|
66
|
-
},
|
|
67
|
-
dispose() { },
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Hook that manages a hidden div for frame capture.
|
|
72
|
-
*/
|
|
73
|
-
export function useFrameCapture() {
|
|
74
|
-
const containerRef = useRef(null);
|
|
75
|
-
const rootRef = useRef(null);
|
|
76
|
-
const dimensionsRef = useRef({ width: 1920, height: 1080 });
|
|
77
|
-
const init = useCallback(async (doc, renderOptions, captionMode) => {
|
|
78
|
-
// Clean up any existing container.
|
|
79
|
-
// Defer unmount to avoid "synchronously unmount a root while React
|
|
80
|
-
// was already rendering" when init() is called from a React handler.
|
|
81
|
-
if (rootRef.current || containerRef.current) {
|
|
82
|
-
const oldRoot = rootRef.current;
|
|
83
|
-
const oldContainer = containerRef.current;
|
|
84
|
-
rootRef.current = null;
|
|
85
|
-
containerRef.current = null;
|
|
86
|
-
await new Promise((resolve) => {
|
|
87
|
-
setTimeout(() => {
|
|
88
|
-
if (oldRoot)
|
|
89
|
-
oldRoot.unmount();
|
|
90
|
-
if (oldContainer)
|
|
91
|
-
oldContainer.remove();
|
|
92
|
-
resolve();
|
|
93
|
-
}, 0);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
const width = renderOptions.width ?? 1920;
|
|
97
|
-
const height = renderOptions.height ?? 1080;
|
|
98
|
-
dimensionsRef.current = { width, height };
|
|
99
|
-
// Create a hidden container
|
|
100
|
-
const container = document.createElement('div');
|
|
101
|
-
container.style.cssText =
|
|
102
|
-
`position:fixed;left:0;top:0;width:${width}px;height:${height}px;` +
|
|
103
|
-
'opacity:0;pointer-events:none;z-index:-1;overflow:hidden;';
|
|
104
|
-
document.body.appendChild(container);
|
|
105
|
-
containerRef.current = container;
|
|
106
|
-
// Create render root
|
|
107
|
-
const renderRoot = document.createElement('div');
|
|
108
|
-
renderRoot.id = 'squisq-capture-root';
|
|
109
|
-
renderRoot.style.cssText = `width:${width}px;height:${height}px;`;
|
|
110
|
-
container.appendChild(renderRoot);
|
|
111
|
-
// Build media provider from images
|
|
112
|
-
const mediaProvider = renderOptions.images
|
|
113
|
-
? createInlineProvider(renderOptions.images)
|
|
114
|
-
: null;
|
|
115
|
-
// Mount DocPlayer in renderMode via React
|
|
116
|
-
const root = createRoot(renderRoot);
|
|
117
|
-
rootRef.current = root;
|
|
118
|
-
// Derive caption props from captionMode
|
|
119
|
-
const captionsEnabled = captionMode !== undefined && captionMode !== 'off';
|
|
120
|
-
const captionStyle = captionMode === 'social' ? 'social' : 'standard';
|
|
121
|
-
const playerElement = createElement(DocPlayer, {
|
|
122
|
-
script: doc,
|
|
123
|
-
basePath: '.',
|
|
124
|
-
renderMode: true,
|
|
125
|
-
showControls: false,
|
|
126
|
-
autoPlay: false,
|
|
127
|
-
forceViewport: { width, height, name: 'export' },
|
|
128
|
-
captionsEnabled,
|
|
129
|
-
captionStyle,
|
|
130
|
-
});
|
|
131
|
-
// Defer rendering to the next microtask to avoid "synchronously unmount
|
|
132
|
-
// a root while React was already rendering" when init() is called during
|
|
133
|
-
// a React render cycle (e.g., from startExport in VideoExportModal).
|
|
134
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
135
|
-
if (mediaProvider) {
|
|
136
|
-
root.render(createElement(MediaContext.Provider, { value: mediaProvider }, playerElement));
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
root.render(playerElement);
|
|
140
|
-
}
|
|
141
|
-
// Wait for the render API to appear on window
|
|
142
|
-
return new Promise((resolve, reject) => {
|
|
143
|
-
const timeout = setTimeout(() => {
|
|
144
|
-
const w = window;
|
|
145
|
-
const hasSeek = typeof w.seekTo === 'function';
|
|
146
|
-
const hasDur = typeof w.getDuration === 'function';
|
|
147
|
-
const rootEl = containerRef.current?.querySelector('#squisq-capture-root');
|
|
148
|
-
const hasPlayer = rootEl ? rootEl.querySelector('.doc-player') !== null : false;
|
|
149
|
-
reject(new Error(`Render API did not initialize within 15s. ` +
|
|
150
|
-
`seekTo=${hasSeek}, getDuration=${hasDur}, player=${hasPlayer}, root=${!!rootEl}`));
|
|
151
|
-
}, 15000);
|
|
152
|
-
const checkApi = () => {
|
|
153
|
-
const w = window;
|
|
154
|
-
if (typeof w.getDuration === 'function' && typeof w.seekTo === 'function') {
|
|
155
|
-
clearTimeout(timeout);
|
|
156
|
-
const duration = w.getDuration();
|
|
157
|
-
resolve(duration);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
requestAnimationFrame(checkApi);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
// Give React time to mount and run useEffects
|
|
164
|
-
setTimeout(checkApi, 500);
|
|
165
|
-
});
|
|
166
|
-
}, []);
|
|
167
|
-
const captureFrame = useCallback(async (time) => {
|
|
168
|
-
const container = containerRef.current;
|
|
169
|
-
const w = window;
|
|
170
|
-
if (!container || typeof w.seekTo !== 'function') {
|
|
171
|
-
throw new Error('Frame capture not initialized — call init() first');
|
|
172
|
-
}
|
|
173
|
-
const { width, height } = dimensionsRef.current;
|
|
174
|
-
// Seek the player to the target time
|
|
175
|
-
await w.seekTo(time);
|
|
176
|
-
// Wait for the DOM to update after seek
|
|
177
|
-
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
178
|
-
const root = container.querySelector('#squisq-capture-root');
|
|
179
|
-
if (!root) {
|
|
180
|
-
throw new Error('Capture root element not found');
|
|
181
|
-
}
|
|
182
|
-
// Render the DOM to a canvas via html2canvas.
|
|
183
|
-
// We're in the same document (no iframe), so COEP doesn't block cloning.
|
|
184
|
-
const canvas = await html2canvas(root, {
|
|
185
|
-
width,
|
|
186
|
-
height,
|
|
187
|
-
scale: 1,
|
|
188
|
-
useCORS: true,
|
|
189
|
-
allowTaint: true,
|
|
190
|
-
backgroundColor: '#000000',
|
|
191
|
-
logging: false,
|
|
192
|
-
});
|
|
193
|
-
// Convert to ImageBitmap (transferable to worker — zero-copy)
|
|
194
|
-
const bitmap = await createImageBitmap(canvas);
|
|
195
|
-
return bitmap;
|
|
196
|
-
}, []);
|
|
197
|
-
const destroy = useCallback(() => {
|
|
198
|
-
if (rootRef.current) {
|
|
199
|
-
rootRef.current.unmount();
|
|
200
|
-
rootRef.current = null;
|
|
201
|
-
}
|
|
202
|
-
if (containerRef.current) {
|
|
203
|
-
containerRef.current.remove();
|
|
204
|
-
containerRef.current = null;
|
|
205
|
-
}
|
|
206
|
-
}, []);
|
|
207
|
-
// Return a stable object to prevent useEffect cleanup loops
|
|
208
|
-
// in consumers that depend on the handle reference.
|
|
209
|
-
return useMemo(() => ({ init, captureFrame, destroy }), [init, captureFrame, destroy]);
|
|
210
|
-
}
|
|
211
|
-
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,eAAe,EAAE,SAAS;YAC1B,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QAEH,8DAA8D;QAC9D,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC1B,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACzB,CAAC;QACD,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;YACzB,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YAC9B,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;QAC9B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,4DAA4D;IAC5D,oDAAoD;IACpD,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useVideoExport — Main orchestration hook for browser video export.
|
|
3
|
-
*
|
|
4
|
-
* Coordinates frame capture (hidden iframe + html2canvas) with
|
|
5
|
-
* main-thread WebCodecs encoding via mp4-muxer. Manages the full
|
|
6
|
-
* lifecycle: prepare → capture + encode → download.
|
|
7
|
-
*
|
|
8
|
-
* Encoding runs on the main thread because frame capture via html2canvas
|
|
9
|
-
* (~100-200ms per frame) is the bottleneck, not encoding (~1ms per frame
|
|
10
|
-
* with hardware-accelerated WebCodecs). Worker offloading would add
|
|
11
|
-
* complexity with minimal benefit.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* const { state, progress, phase, startExport, cancel, downloadUrl } = useVideoExport();
|
|
15
|
-
* <button onClick={() => startExport(doc, options)}>Export</button>
|
|
16
|
-
*/
|
|
17
|
-
import type { Doc } from '@bendyline/squisq/schemas';
|
|
18
|
-
import type { MediaProvider } from '@bendyline/squisq/schemas';
|
|
19
|
-
import type { VideoQuality, VideoOrientation } from '@bendyline/squisq-video';
|
|
20
|
-
import type { CaptionMode } from '@bendyline/squisq-react';
|
|
21
|
-
export type VideoExportState = 'idle' | 'preparing' | 'capturing' | 'encoding' | 'complete' | 'error';
|
|
22
|
-
export interface VideoExportConfig {
|
|
23
|
-
/** Encoding quality preset (default: 'normal') */
|
|
24
|
-
quality?: VideoQuality;
|
|
25
|
-
/** Frames per second (default: 30) */
|
|
26
|
-
fps?: number;
|
|
27
|
-
/** Viewport orientation (default: 'landscape') */
|
|
28
|
-
orientation?: VideoOrientation;
|
|
29
|
-
/**
|
|
30
|
-
* Map of relative image paths to binary data.
|
|
31
|
-
* Used to embed images into the render HTML.
|
|
32
|
-
*/
|
|
33
|
-
images?: Map<string, ArrayBuffer>;
|
|
34
|
-
/**
|
|
35
|
-
* Map of audio segment names to binary data.
|
|
36
|
-
* Used to embed audio into the render HTML.
|
|
37
|
-
*/
|
|
38
|
-
audio?: Map<string, ArrayBuffer>;
|
|
39
|
-
/** MediaProvider to resolve media URLs (alternative to passing images directly) */
|
|
40
|
-
mediaProvider?: MediaProvider;
|
|
41
|
-
/** Caption mode for the exported video (default: 'off') */
|
|
42
|
-
captionMode?: CaptionMode;
|
|
43
|
-
/** Player IIFE bundle (unused in browser export, kept for CLI/Playwright path) */
|
|
44
|
-
playerScript?: string;
|
|
45
|
-
}
|
|
46
|
-
export interface VideoExportResult {
|
|
47
|
-
/** Current export state */
|
|
48
|
-
state: VideoExportState;
|
|
49
|
-
/** 0–100 progress percentage */
|
|
50
|
-
progress: number;
|
|
51
|
-
/** Human-readable description of the current phase */
|
|
52
|
-
phase: string;
|
|
53
|
-
/** Video duration detected from the doc (seconds) */
|
|
54
|
-
duration: number;
|
|
55
|
-
/** Encoder backend ('webcodecs' when WebCodecs H.264 active, 'ffmpeg-wasm' when worker fallback active, null when idle) */
|
|
56
|
-
backend: 'webcodecs' | 'ffmpeg-wasm' | null;
|
|
57
|
-
/** Blob download URL (populated when state === 'complete') */
|
|
58
|
-
downloadUrl: string | null;
|
|
59
|
-
/** File size in bytes (populated when state === 'complete') */
|
|
60
|
-
fileSize: number;
|
|
61
|
-
/** Error message (populated when state === 'error') */
|
|
62
|
-
error: string | null;
|
|
63
|
-
/** Seconds elapsed since export started */
|
|
64
|
-
elapsed: number;
|
|
65
|
-
/** Estimated seconds remaining (0 when idle or complete) */
|
|
66
|
-
estimatedRemaining: number;
|
|
67
|
-
/** Start a new export */
|
|
68
|
-
startExport: (doc: Doc, config: VideoExportConfig) => Promise<void>;
|
|
69
|
-
/** Cancel an in-progress export */
|
|
70
|
-
cancel: () => void;
|
|
71
|
-
/** Reset state back to idle (e.g., after complete or error) */
|
|
72
|
-
reset: () => void;
|
|
73
|
-
}
|
|
74
|
-
export declare function useVideoExport(): VideoExportResult;
|
|
75
|
-
//# sourceMappingURL=useVideoExport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useVideoExport.d.ts","sourceRoot":"","sources":["../../src/hooks/useVideoExport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAY3D,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,WAAW,GACX,WAAW,GACX,UAAU,GACV,UAAU,GACV,OAAO,CAAC;AAEZ,MAAM,WA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IAAI,CAAC;CACnB;AAID,wBAAgB,cAAc,IAAI,iBAAiB,CAsRlD"}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useVideoExport — Main orchestration hook for browser video export.
|
|
3
|
-
*
|
|
4
|
-
* Coordinates frame capture (hidden iframe + html2canvas) with
|
|
5
|
-
* main-thread WebCodecs encoding via mp4-muxer. Manages the full
|
|
6
|
-
* lifecycle: prepare → capture + encode → download.
|
|
7
|
-
*
|
|
8
|
-
* Encoding runs on the main thread because frame capture via html2canvas
|
|
9
|
-
* (~100-200ms per frame) is the bottleneck, not encoding (~1ms per frame
|
|
10
|
-
* with hardware-accelerated WebCodecs). Worker offloading would add
|
|
11
|
-
* complexity with minimal benefit.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* const { state, progress, phase, startExport, cancel, downloadUrl } = useVideoExport();
|
|
15
|
-
* <button onClick={() => startExport(doc, options)}>Export</button>
|
|
16
|
-
*/
|
|
17
|
-
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
18
|
-
import { resolveDimensions } from '@bendyline/squisq-video';
|
|
19
|
-
import { createEncoder, supportsWebCodecs, supportsWebCodecsH264, } from '../mainThreadEncoder.js';
|
|
20
|
-
import { createWorkerEncoder } from '../workerEncoder.js';
|
|
21
|
-
import { useFrameCapture } from './useFrameCapture.js';
|
|
22
|
-
// ── Hook ───────────────────────────────────────────────────────────
|
|
23
|
-
export function useVideoExport() {
|
|
24
|
-
const [state, setState] = useState('idle');
|
|
25
|
-
const [progress, setProgress] = useState(0);
|
|
26
|
-
const [phase, setPhase] = useState('');
|
|
27
|
-
const [duration, setDuration] = useState(0);
|
|
28
|
-
const [backend, setBackend] = useState(null);
|
|
29
|
-
const [downloadUrl, setDownloadUrl] = useState(null);
|
|
30
|
-
const [fileSize, setFileSize] = useState(0);
|
|
31
|
-
const [error, setError] = useState(null);
|
|
32
|
-
const [elapsed, setElapsed] = useState(0);
|
|
33
|
-
const [estimatedRemaining, setEstimatedRemaining] = useState(0);
|
|
34
|
-
const encoderRef = useRef(null);
|
|
35
|
-
const cancelledRef = useRef(false);
|
|
36
|
-
const downloadUrlRef = useRef(null);
|
|
37
|
-
const startTimeRef = useRef(0);
|
|
38
|
-
const elapsedTimerRef = useRef(null);
|
|
39
|
-
const frameCapture = useFrameCapture();
|
|
40
|
-
// Clean up on unmount
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
return () => {
|
|
43
|
-
if (elapsedTimerRef.current)
|
|
44
|
-
clearInterval(elapsedTimerRef.current);
|
|
45
|
-
if (downloadUrlRef.current) {
|
|
46
|
-
URL.revokeObjectURL(downloadUrlRef.current);
|
|
47
|
-
}
|
|
48
|
-
if (encoderRef.current) {
|
|
49
|
-
encoderRef.current.close();
|
|
50
|
-
}
|
|
51
|
-
frameCapture.destroy();
|
|
52
|
-
};
|
|
53
|
-
}, [frameCapture]);
|
|
54
|
-
const reset = useCallback(() => {
|
|
55
|
-
if (downloadUrlRef.current) {
|
|
56
|
-
URL.revokeObjectURL(downloadUrlRef.current);
|
|
57
|
-
downloadUrlRef.current = null;
|
|
58
|
-
}
|
|
59
|
-
if (encoderRef.current) {
|
|
60
|
-
encoderRef.current.close();
|
|
61
|
-
encoderRef.current = null;
|
|
62
|
-
}
|
|
63
|
-
frameCapture.destroy();
|
|
64
|
-
setState('idle');
|
|
65
|
-
setProgress(0);
|
|
66
|
-
setPhase('');
|
|
67
|
-
setDuration(0);
|
|
68
|
-
setBackend(null);
|
|
69
|
-
setDownloadUrl(null);
|
|
70
|
-
setFileSize(0);
|
|
71
|
-
setError(null);
|
|
72
|
-
setElapsed(0);
|
|
73
|
-
setEstimatedRemaining(0);
|
|
74
|
-
if (elapsedTimerRef.current)
|
|
75
|
-
clearInterval(elapsedTimerRef.current);
|
|
76
|
-
cancelledRef.current = false;
|
|
77
|
-
}, [frameCapture]);
|
|
78
|
-
const cancel = useCallback(() => {
|
|
79
|
-
cancelledRef.current = true;
|
|
80
|
-
if (elapsedTimerRef.current)
|
|
81
|
-
clearInterval(elapsedTimerRef.current);
|
|
82
|
-
if (encoderRef.current) {
|
|
83
|
-
encoderRef.current.close();
|
|
84
|
-
encoderRef.current = null;
|
|
85
|
-
}
|
|
86
|
-
frameCapture.destroy();
|
|
87
|
-
setState('idle');
|
|
88
|
-
setProgress(0);
|
|
89
|
-
setPhase('Cancelled');
|
|
90
|
-
}, [frameCapture]);
|
|
91
|
-
const startExport = useCallback(async (doc, config) => {
|
|
92
|
-
// Clear previous state
|
|
93
|
-
cancelledRef.current = false;
|
|
94
|
-
if (downloadUrlRef.current) {
|
|
95
|
-
URL.revokeObjectURL(downloadUrlRef.current);
|
|
96
|
-
downloadUrlRef.current = null;
|
|
97
|
-
}
|
|
98
|
-
setDownloadUrl(null);
|
|
99
|
-
setFileSize(0);
|
|
100
|
-
setError(null);
|
|
101
|
-
const quality = config.quality ?? 'normal';
|
|
102
|
-
const fps = config.fps ?? 30;
|
|
103
|
-
const orientation = config.orientation ?? 'landscape';
|
|
104
|
-
const { width, height } = resolveDimensions({ orientation });
|
|
105
|
-
try {
|
|
106
|
-
// ── Check browser support ─────────────────────────────────
|
|
107
|
-
const webCodecsAvailable = supportsWebCodecs();
|
|
108
|
-
const sharedArrayBufferAvailable = typeof SharedArrayBuffer !== 'undefined';
|
|
109
|
-
if (!webCodecsAvailable && !sharedArrayBufferAvailable) {
|
|
110
|
-
throw new Error('No video encoder available. WebCodecs requires Chrome 94+ / Edge 94+, ' +
|
|
111
|
-
'and the ffmpeg.wasm fallback requires SharedArrayBuffer ' +
|
|
112
|
-
'(Cross-Origin-Isolation headers).');
|
|
113
|
-
}
|
|
114
|
-
// ── Step 1: Prepare ───────────────────────────────────────
|
|
115
|
-
setState('preparing');
|
|
116
|
-
setPhase('Loading document…');
|
|
117
|
-
setProgress(0);
|
|
118
|
-
setElapsed(0);
|
|
119
|
-
setEstimatedRemaining(0);
|
|
120
|
-
// Start elapsed timer
|
|
121
|
-
startTimeRef.current = performance.now();
|
|
122
|
-
if (elapsedTimerRef.current)
|
|
123
|
-
clearInterval(elapsedTimerRef.current);
|
|
124
|
-
elapsedTimerRef.current = setInterval(() => {
|
|
125
|
-
setElapsed(Math.floor((performance.now() - startTimeRef.current) / 1000));
|
|
126
|
-
}, 1000);
|
|
127
|
-
// Collect images from MediaProvider if provided and images not passed directly
|
|
128
|
-
let images = config.images;
|
|
129
|
-
if (!images && config.mediaProvider) {
|
|
130
|
-
images = new Map();
|
|
131
|
-
const entries = await config.mediaProvider.listMedia();
|
|
132
|
-
for (const entry of entries) {
|
|
133
|
-
const url = await config.mediaProvider.resolveUrl(entry.name);
|
|
134
|
-
const res = await fetch(url);
|
|
135
|
-
if (res.ok) {
|
|
136
|
-
const data = await res.arrayBuffer();
|
|
137
|
-
images.set(entry.name, data);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const docDuration = await frameCapture.init(doc, { images, audio: config.audio, width, height }, config.captionMode);
|
|
142
|
-
if (cancelledRef.current)
|
|
143
|
-
return;
|
|
144
|
-
setDuration(docDuration);
|
|
145
|
-
if (docDuration <= 0) {
|
|
146
|
-
throw new Error('Document has zero duration — nothing to export');
|
|
147
|
-
}
|
|
148
|
-
// ── Step 2: Create encoder ────────────────────────────────
|
|
149
|
-
setPhase('Starting encoder…');
|
|
150
|
-
setProgress(5);
|
|
151
|
-
// Prefer main-thread WebCodecs (fast), but probe whether H.264
|
|
152
|
-
// is actually supported. Linux Chromium has VideoEncoder but
|
|
153
|
-
// no proprietary H.264 codec — fall back to the worker, which
|
|
154
|
-
// loads ffmpeg.wasm in that case.
|
|
155
|
-
const canUseWebCodecs = webCodecsAvailable && (await supportsWebCodecsH264({ width, height, fps, quality }));
|
|
156
|
-
let encoder;
|
|
157
|
-
if (canUseWebCodecs) {
|
|
158
|
-
encoder = createEncoder({ width, height, fps, quality });
|
|
159
|
-
setBackend('webcodecs');
|
|
160
|
-
}
|
|
161
|
-
else if (sharedArrayBufferAvailable) {
|
|
162
|
-
const workerEncoder = createWorkerEncoder({ width, height, fps, quality });
|
|
163
|
-
encoder = workerEncoder;
|
|
164
|
-
const selectedBackend = await workerEncoder.ready;
|
|
165
|
-
setBackend(selectedBackend);
|
|
166
|
-
setPhase(selectedBackend === 'ffmpeg-wasm'
|
|
167
|
-
? 'Starting encoder (ffmpeg.wasm)…'
|
|
168
|
-
: 'Starting encoder…');
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
throw new Error('WebCodecs H.264 is unavailable in this browser and the ffmpeg.wasm ' +
|
|
172
|
-
'fallback requires SharedArrayBuffer (Cross-Origin-Isolation headers).');
|
|
173
|
-
}
|
|
174
|
-
encoderRef.current = encoder;
|
|
175
|
-
if (cancelledRef.current)
|
|
176
|
-
return;
|
|
177
|
-
// ── Step 3: Capture frames and encode ─────────────────────
|
|
178
|
-
setState('capturing');
|
|
179
|
-
const totalFrames = Math.ceil(docDuration * fps);
|
|
180
|
-
const captureStartTime = performance.now();
|
|
181
|
-
// Throttle UI updates to every ~10 frames to avoid excessive re-renders.
|
|
182
|
-
// Each setState between awaits triggers a separate render cycle.
|
|
183
|
-
const UI_UPDATE_INTERVAL = 10;
|
|
184
|
-
for (let i = 0; i < totalFrames; i++) {
|
|
185
|
-
if (cancelledRef.current)
|
|
186
|
-
return;
|
|
187
|
-
const time = i / fps;
|
|
188
|
-
// Update UI periodically (not every frame)
|
|
189
|
-
if (i % UI_UPDATE_INTERVAL === 0 || i === totalFrames - 1) {
|
|
190
|
-
const captureProgress = Math.round((i / totalFrames) * 90);
|
|
191
|
-
setProgress(5 + captureProgress);
|
|
192
|
-
setPhase(`Capturing frame ${i + 1}/${totalFrames} (${time.toFixed(1)}s)`);
|
|
193
|
-
if (i > 0) {
|
|
194
|
-
const elapsedCapture = (performance.now() - captureStartTime) / 1000;
|
|
195
|
-
const avgPerFrame = elapsedCapture / i;
|
|
196
|
-
const remaining = Math.round(avgPerFrame * (totalFrames - i));
|
|
197
|
-
setEstimatedRemaining(remaining);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const bitmap = await frameCapture.captureFrame(time);
|
|
201
|
-
if (cancelledRef.current) {
|
|
202
|
-
bitmap.close();
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
// Encode immediately — WebCodecs is fast and async internally
|
|
206
|
-
encoder.encodeFrame(bitmap, i);
|
|
207
|
-
}
|
|
208
|
-
if (cancelledRef.current)
|
|
209
|
-
return;
|
|
210
|
-
// ── Step 4: Finalize MP4 ──────────────────────────────────
|
|
211
|
-
setState('encoding');
|
|
212
|
-
setPhase('Finalizing video…');
|
|
213
|
-
setProgress(95);
|
|
214
|
-
const mp4Buffer = await encoder.finalize();
|
|
215
|
-
encoderRef.current = null;
|
|
216
|
-
if (cancelledRef.current)
|
|
217
|
-
return;
|
|
218
|
-
// ── Step 5: Create download URL ───────────────────────────
|
|
219
|
-
const blob = new Blob([mp4Buffer], { type: 'video/mp4' });
|
|
220
|
-
const url = URL.createObjectURL(blob);
|
|
221
|
-
downloadUrlRef.current = url;
|
|
222
|
-
setDownloadUrl(url);
|
|
223
|
-
setFileSize(mp4Buffer.byteLength);
|
|
224
|
-
setState('complete');
|
|
225
|
-
setProgress(100);
|
|
226
|
-
setPhase('Export complete');
|
|
227
|
-
setEstimatedRemaining(0);
|
|
228
|
-
if (elapsedTimerRef.current)
|
|
229
|
-
clearInterval(elapsedTimerRef.current);
|
|
230
|
-
// Clean up
|
|
231
|
-
frameCapture.destroy();
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
if (elapsedTimerRef.current)
|
|
235
|
-
clearInterval(elapsedTimerRef.current);
|
|
236
|
-
if (cancelledRef.current)
|
|
237
|
-
return;
|
|
238
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
239
|
-
setState('error');
|
|
240
|
-
setError(message);
|
|
241
|
-
setPhase('Export failed');
|
|
242
|
-
// Clean up on error
|
|
243
|
-
if (encoderRef.current) {
|
|
244
|
-
encoderRef.current.close();
|
|
245
|
-
encoderRef.current = null;
|
|
246
|
-
}
|
|
247
|
-
frameCapture.destroy();
|
|
248
|
-
}
|
|
249
|
-
}, [frameCapture]);
|
|
250
|
-
return {
|
|
251
|
-
state,
|
|
252
|
-
progress,
|
|
253
|
-
phase,
|
|
254
|
-
duration,
|
|
255
|
-
backend,
|
|
256
|
-
downloadUrl,
|
|
257
|
-
fileSize,
|
|
258
|
-
error,
|
|
259
|
-
elapsed,
|
|
260
|
-
estimatedRemaining,
|
|
261
|
-
startExport,
|
|
262
|
-
cancel,
|
|
263
|
-
reset,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=useVideoExport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useVideoExport.js","sourceRoot":"","sources":["../../src/hooks/useVideoExport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAkEvD,sEAAsE;AAEtE,MAAM,UAAU,cAAc;IAC5B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAmB,MAAM,CAAC,CAAC;IAC7D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,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B,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGrE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,YAAY,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Main-thread WebCodecs encoder.
|
|
3
|
-
*
|
|
4
|
-
* Encodes video frames to MP4 using the WebCodecs API and mp4-muxer,
|
|
5
|
-
* running directly on the main thread. This is simpler and avoids
|
|
6
|
-
* worker module-resolution issues with bundlers. Since frame capture
|
|
7
|
-
* via html2canvas (~100-200ms per frame) is the bottleneck — not
|
|
8
|
-
* encoding (~1ms per frame with hardware-accelerated WebCodecs) —
|
|
9
|
-
* worker offloading provides minimal benefit.
|
|
10
|
-
*
|
|
11
|
-
* Requirements: Chrome 94+ / Edge 94+ (WebCodecs support).
|
|
12
|
-
*/
|
|
13
|
-
export interface EncoderConfig {
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
fps: number;
|
|
17
|
-
quality: 'draft' | 'normal' | 'high';
|
|
18
|
-
}
|
|
19
|
-
export interface MainThreadEncoder {
|
|
20
|
-
/** Encode a single frame. The bitmap is closed after encoding. */
|
|
21
|
-
encodeFrame(bitmap: ImageBitmap, frameIndex: number): void;
|
|
22
|
-
/** Flush pending frames and finalize the MP4. Returns the MP4 ArrayBuffer. */
|
|
23
|
-
finalize(): Promise<ArrayBuffer>;
|
|
24
|
-
/** Close the encoder without producing output (e.g., on cancel). */
|
|
25
|
-
close(): void;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Check whether the browser supports WebCodecs video encoding.
|
|
29
|
-
*/
|
|
30
|
-
export declare function supportsWebCodecs(): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Probe whether the WebCodecs encoder actually supports the H.264 profile
|
|
33
|
-
* we use. The `VideoEncoder` global can exist while the specific codec is
|
|
34
|
-
* unavailable — this is the case on Linux Chromium, which ships without
|
|
35
|
-
* the proprietary H.264 encoder.
|
|
36
|
-
*/
|
|
37
|
-
export declare function supportsWebCodecsH264(config: EncoderConfig): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* Create a main-thread WebCodecs encoder.
|
|
40
|
-
*
|
|
41
|
-
* Throws if WebCodecs is not available.
|
|
42
|
-
*/
|
|
43
|
-
export declare function createEncoder(config: EncoderConfig): MainThreadEncoder;
|
|
44
|
-
//# sourceMappingURL=mainThreadEncoder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mainThreadEncoder.d.ts","sourceRoot":"","sources":["../src/mainThreadEncoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3D,8EAA8E;IAC9E,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IACjC,oEAAoE;IACpE,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAcnF;AAeD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,iBAAiB,CAuEtE"}
|