@twick/browser-render 0.15.7 → 0.15.9

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
@@ -46,19 +46,21 @@ a.click();
46
46
  import { useBrowserRenderer } from '@twick/browser-render';
47
47
 
48
48
  function VideoRenderer() {
49
- const { render, progress, isRendering, videoBlob, download } = useBrowserRenderer({
50
- width: 1920,
51
- height: 1080,
52
- fps: 30,
53
- autoDownload: false
54
- });
49
+ const { render, progress, isRendering, videoBlob, download, error, reset } =
50
+ useBrowserRenderer({
51
+ width: 720,
52
+ height: 1280,
53
+ fps: 30,
54
+ includeAudio: true, // enable audio rendering + FFmpeg mux
55
+ autoDownload: true, // auto-download final MP4
56
+ });
55
57
 
56
58
  const handleRender = async () => {
57
59
  await render({
58
60
  input: {
59
- properties: { width: 1920, height: 1080, fps: 30 },
60
- tracks: [/* ... */]
61
- }
61
+ properties: { width: 720, height: 1280, fps: 30 },
62
+ tracks: [/* ... */],
63
+ },
62
64
  });
63
65
  };
64
66
 
@@ -69,6 +71,12 @@ function VideoRenderer() {
69
71
  </button>
70
72
  {isRendering && <progress value={progress} max={1} />}
71
73
  {videoBlob && <button onClick={download}>Download</button>}
74
+ {error && (
75
+ <div>
76
+ <p>{error.message}</p>
77
+ <button onClick={reset}>Clear error</button>
78
+ </div>
79
+ )}
72
80
  </div>
73
81
  );
74
82
  }
@@ -92,6 +100,9 @@ function VideoRenderer() {
92
100
  fps?: number; // Frames per second (default: 30)
93
101
  quality?: 'low' | 'medium' | 'high';
94
102
  range?: [number, number]; // [start, end] in seconds
103
+ includeAudio?: boolean; // Enable audio rendering and muxing (default: false)
104
+ downloadAudioSeparately?: boolean; // Also download audio.wav when muxing fails
105
+ onAudioReady?: (audioBlob: Blob) => void; // Callback when raw audio is ready
95
106
  onProgress?: (progress: number) => void;
96
107
  onComplete?: (videoBlob: Blob) => void;
97
108
  onError?: (error: Error) => void;
@@ -130,9 +141,38 @@ export default defineConfig({
130
141
  });
131
142
  ```
132
143
 
144
+ ### FFmpeg audio/video muxing (optional)
145
+
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
+ To match the setup used in `@twick/examples`, you should:
148
+
149
+ 1. Install the FFmpeg packages:
150
+
151
+ ```bash
152
+ npm install @ffmpeg/ffmpeg @ffmpeg/util @ffmpeg/core
153
+ ```
154
+
155
+ 2. Expose the FFmpeg core files from your app’s `public` folder so they are available at:
156
+
157
+ ```text
158
+ /public/ffmpeg/ffmpeg-core.js
159
+ /public/ffmpeg/ffmpeg-core.wasm
160
+ ```
161
+
162
+ For example, you can copy them from `node_modules/@ffmpeg/core/dist`:
163
+
164
+ ```bash
165
+ mkdir -p public/ffmpeg
166
+ cp node_modules/@ffmpeg/core/dist/ffmpeg-core.js public/ffmpeg/
167
+ cp node_modules/@ffmpeg/core/dist/ffmpeg-core.wasm public/ffmpeg/
168
+ ```
169
+
170
+ In the browser, the muxer loads these files from `${window.location.origin}/ffmpeg`, so the URLs must match that structure.
171
+ 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
+
133
173
  ## Limitations
134
174
 
135
- - **Audio**: Audio processing is not yet implemented. Only video encoding is supported.
175
+ - **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.
136
176
  - **Browser Support**: Requires WebCodecs API (Chrome 94+, Edge 94+)
137
177
 
138
178
  ## License