@twick/browser-render 0.15.8 → 0.15.10

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 CHANGED
@@ -144,6 +144,45 @@ export default defineConfig({
144
144
  ### FFmpeg audio/video muxing (optional)
145
145
 
146
146
  When `settings.includeAudio` is enabled, `@twick/browser-render` will render audio in the browser and (by default) try to mux it into the final MP4 using `@ffmpeg/ffmpeg`.
147
+
148
+ #### Automatic Setup with Vite Plugin (Recommended)
149
+
150
+ For Vite projects, use the provided plugin to automatically copy FFmpeg files:
151
+
152
+ ```ts
153
+ // vite.config.ts
154
+ import { defineConfig } from 'vite';
155
+ import { twickBrowserRenderPlugin } from '@twick/browser-render/vite-plugin-ffmpeg';
156
+
157
+ export default defineConfig({
158
+ plugins: [
159
+ twickBrowserRenderPlugin(),
160
+ // ... your other plugins
161
+ ],
162
+ });
163
+ ```
164
+
165
+ The plugin automatically copies `ffmpeg-core.js` and `ffmpeg-core.wasm` from `node_modules/@ffmpeg/core/dist` to your `public/ffmpeg/` directory.
166
+
167
+ #### Create React App / non-Vite
168
+
169
+ For CRA or any project without Vite, run the copy script before `start` and `build`:
170
+
171
+ ```json
172
+ {
173
+ "scripts": {
174
+ "prestart": "node node_modules/@twick/browser-render/scripts/copy-public-assets.js",
175
+ "prebuild": "node node_modules/@twick/browser-render/scripts/copy-public-assets.js",
176
+ "start": "react-scripts start",
177
+ "build": "react-scripts build"
178
+ }
179
+ }
180
+ ```
181
+
182
+ The script copies FFmpeg core files, `mp4-wasm.wasm`, and `audio-worker.js` to your `public/` directory. No extra dependencies required.
183
+
184
+ #### Manual Setup
185
+
147
186
  To match the setup used in `@twick/examples`, you should:
148
187
 
149
188
  1. Install the FFmpeg packages:
@@ -170,6 +209,8 @@ cp node_modules/@ffmpeg/core/dist/ffmpeg-core.wasm public/ffmpeg/
170
209
  In the browser, the muxer loads these files from `${window.location.origin}/ffmpeg`, so the URLs must match that structure.
171
210
  If FFmpeg cannot be loaded, the renderer will fall back to returning a video-only file and (optionally) downloading `audio.wav` separately when `downloadAudioSeparately` is true.
172
211
 
212
+ **Note**: For Vite projects, you can use the `twickBrowserRenderPlugin()` Vite plugin to automatically copy these files. See the plugin documentation at `@twick/browser-render/vite-plugin-ffmpeg`.
213
+
173
214
  ## Limitations
174
215
 
175
216
  - **Audio**: Audio rendering and FFmpeg-based muxing run entirely in the browser and are still considered experimental. If FFmpeg assets are not available, only video will be muxed and audio may be downloaded as a separate file.
package/dist/index.d.mts CHANGED
@@ -110,6 +110,50 @@ declare const renderTwickVideoInBrowser: (config: BrowserRenderConfig) => Promis
110
110
  */
111
111
  declare const downloadVideoBlob: (videoBlob: Blob, filename?: string) => void;
112
112
 
113
+ /**
114
+ * Browser-based video normalization using FFmpeg.wasm (main thread)
115
+ * Compatible with Next.js 15
116
+ *
117
+ * This helper converts "problematic" videos (e.g. WhatsApp exports) into a
118
+ * very standard H.264 + AAC, 30fps, yuv420p MP4 that behaves well with
119
+ * WebCodecs and <video> playback, reducing the chance of frozen-first-frame
120
+ * issues during browser rendering.
121
+ *
122
+ * FFmpeg core files must be served from the app's public folder, e.g.:
123
+ * twick-web/public/ffmpeg/ffmpeg-core.js, ffmpeg-core.wasm
124
+ */
125
+ /** Normalization options */
126
+ interface NormalizeVideoOptions {
127
+ /** Target width in pixels (default: 720). Height is derived to preserve aspect ratio. */
128
+ width?: number;
129
+ /** Target frames per second (default: 30). */
130
+ fps?: number;
131
+ }
132
+ /** Result of normalization */
133
+ interface NormalizeVideoResult {
134
+ /** Normalized video Blob (MP4, H.264 + AAC). */
135
+ blob: Blob;
136
+ /** Size in bytes of the normalized video. */
137
+ size: number;
138
+ /** Optional debug information (durations, etc.). */
139
+ debug?: {
140
+ loadMs: number;
141
+ writeMs: number;
142
+ execMs: number;
143
+ readMs: number;
144
+ totalMs: number;
145
+ };
146
+ }
147
+ /**
148
+ * Normalize a video Blob into a browser- and WebCodecs-friendly MP4.
149
+ *
150
+ * Typical usage:
151
+ * - Call this after file upload (e.g. from an <input type="file" />)
152
+ * - Upload the returned Blob to your storage (S3, etc.)
153
+ * - Use that URL in your Twick project instead of the raw source
154
+ */
155
+ declare function normalizeVideoBlob(input: Blob, options?: NormalizeVideoOptions): Promise<NormalizeVideoResult>;
156
+
113
157
  interface UseBrowserRendererOptions {
114
158
  /**
115
159
  * Custom Project object
@@ -222,4 +266,4 @@ interface UseBrowserRendererReturn {
222
266
  */
223
267
  declare const useBrowserRenderer: (options?: UseBrowserRendererOptions) => UseBrowserRendererReturn;
224
268
 
225
- export { type BrowserRenderConfig, type UseBrowserRendererOptions, type UseBrowserRendererReturn, renderTwickVideoInBrowser as default, downloadVideoBlob, renderTwickVideoInBrowser, useBrowserRenderer };
269
+ export { type BrowserRenderConfig, type NormalizeVideoOptions, type NormalizeVideoResult, type UseBrowserRendererOptions, type UseBrowserRendererReturn, renderTwickVideoInBrowser as default, downloadVideoBlob, normalizeVideoBlob, renderTwickVideoInBrowser, useBrowserRenderer };
package/dist/index.d.ts CHANGED
@@ -110,6 +110,50 @@ declare const renderTwickVideoInBrowser: (config: BrowserRenderConfig) => Promis
110
110
  */
111
111
  declare const downloadVideoBlob: (videoBlob: Blob, filename?: string) => void;
112
112
 
113
+ /**
114
+ * Browser-based video normalization using FFmpeg.wasm (main thread)
115
+ * Compatible with Next.js 15
116
+ *
117
+ * This helper converts "problematic" videos (e.g. WhatsApp exports) into a
118
+ * very standard H.264 + AAC, 30fps, yuv420p MP4 that behaves well with
119
+ * WebCodecs and <video> playback, reducing the chance of frozen-first-frame
120
+ * issues during browser rendering.
121
+ *
122
+ * FFmpeg core files must be served from the app's public folder, e.g.:
123
+ * twick-web/public/ffmpeg/ffmpeg-core.js, ffmpeg-core.wasm
124
+ */
125
+ /** Normalization options */
126
+ interface NormalizeVideoOptions {
127
+ /** Target width in pixels (default: 720). Height is derived to preserve aspect ratio. */
128
+ width?: number;
129
+ /** Target frames per second (default: 30). */
130
+ fps?: number;
131
+ }
132
+ /** Result of normalization */
133
+ interface NormalizeVideoResult {
134
+ /** Normalized video Blob (MP4, H.264 + AAC). */
135
+ blob: Blob;
136
+ /** Size in bytes of the normalized video. */
137
+ size: number;
138
+ /** Optional debug information (durations, etc.). */
139
+ debug?: {
140
+ loadMs: number;
141
+ writeMs: number;
142
+ execMs: number;
143
+ readMs: number;
144
+ totalMs: number;
145
+ };
146
+ }
147
+ /**
148
+ * Normalize a video Blob into a browser- and WebCodecs-friendly MP4.
149
+ *
150
+ * Typical usage:
151
+ * - Call this after file upload (e.g. from an <input type="file" />)
152
+ * - Upload the returned Blob to your storage (S3, etc.)
153
+ * - Use that URL in your Twick project instead of the raw source
154
+ */
155
+ declare function normalizeVideoBlob(input: Blob, options?: NormalizeVideoOptions): Promise<NormalizeVideoResult>;
156
+
113
157
  interface UseBrowserRendererOptions {
114
158
  /**
115
159
  * Custom Project object
@@ -222,4 +266,4 @@ interface UseBrowserRendererReturn {
222
266
  */
223
267
  declare const useBrowserRenderer: (options?: UseBrowserRendererOptions) => UseBrowserRendererReturn;
224
268
 
225
- export { type BrowserRenderConfig, type UseBrowserRendererOptions, type UseBrowserRendererReturn, renderTwickVideoInBrowser as default, downloadVideoBlob, renderTwickVideoInBrowser, useBrowserRenderer };
269
+ export { type BrowserRenderConfig, type NormalizeVideoOptions, type NormalizeVideoResult, type UseBrowserRendererOptions, type UseBrowserRendererReturn, renderTwickVideoInBrowser as default, downloadVideoBlob, normalizeVideoBlob, renderTwickVideoInBrowser, useBrowserRenderer };