framewebworker 0.1.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/LICENSE +21 -0
- package/README.md +224 -0
- package/dist/index.cjs +572 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +144 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +568 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +120 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +119 -0
- package/dist/react/index.d.ts +119 -0
- package/dist/react/index.js +117 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 nareshipme
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# FrameWorker
|
|
2
|
+
|
|
3
|
+
**Browser-native video rendering and clip export.** Trim, caption, and export MP4 Blobs entirely in the browser — no server, no upload, no backend.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/frameworker)
|
|
6
|
+
[](https://github.com/nareshipme/frameworker/actions)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Trim** any video to a time range
|
|
12
|
+
- **Overlay captions** with built-in style presets (`hormozi`, `modern`, `minimal`, `bold`)
|
|
13
|
+
- **Stitch** multiple clips into one
|
|
14
|
+
- **Pluggable renderer backend** (default: ffmpeg.wasm)
|
|
15
|
+
- **Framework-agnostic core** + React hooks (`frameworker/react`)
|
|
16
|
+
- **TypeScript-first** with full type exports
|
|
17
|
+
- Respects `AbortSignal` for cancellation, reports progress 0–1
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install frameworker @ffmpeg/ffmpeg @ffmpeg/util
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> `@ffmpeg/ffmpeg` and `@ffmpeg/util` are optional peer dependencies required only by the default ffmpeg.wasm backend. If you supply your own backend you don't need them.
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { createFrameWorker } from 'frameworker';
|
|
31
|
+
|
|
32
|
+
const fw = createFrameWorker();
|
|
33
|
+
|
|
34
|
+
const blob = await fw.render({
|
|
35
|
+
source: 'https://example.com/my-video.mp4',
|
|
36
|
+
startTime: 5,
|
|
37
|
+
endTime: 15,
|
|
38
|
+
captions: {
|
|
39
|
+
segments: [
|
|
40
|
+
{ text: 'Hello world', startTime: 0, endTime: 3 },
|
|
41
|
+
{ text: 'This is FrameWorker', startTime: 3, endTime: 5 },
|
|
42
|
+
],
|
|
43
|
+
style: { preset: 'hormozi' },
|
|
44
|
+
},
|
|
45
|
+
}, {
|
|
46
|
+
width: 1280,
|
|
47
|
+
height: 720,
|
|
48
|
+
fps: 30,
|
|
49
|
+
onProgress: (p) => console.log(`${Math.round(p * 100)}%`),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const url = URL.createObjectURL(blob);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## React Example
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { createFrameWorker } from 'frameworker';
|
|
59
|
+
import { useRender } from 'frameworker/react';
|
|
60
|
+
|
|
61
|
+
const fw = createFrameWorker();
|
|
62
|
+
|
|
63
|
+
export function ExportButton({ videoFile }: { videoFile: File }) {
|
|
64
|
+
const { render, isRendering, progress, url, error } = useRender(fw);
|
|
65
|
+
|
|
66
|
+
const handleExport = async () => {
|
|
67
|
+
await render({
|
|
68
|
+
source: videoFile,
|
|
69
|
+
startTime: 0,
|
|
70
|
+
endTime: 30,
|
|
71
|
+
captions: {
|
|
72
|
+
segments: [{ text: 'My Clip', startTime: 0, endTime: 5 }],
|
|
73
|
+
style: { preset: 'modern' },
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div>
|
|
80
|
+
<button onClick={handleExport} disabled={isRendering}>
|
|
81
|
+
{isRendering ? `Exporting… ${Math.round(progress * 100)}%` : 'Export MP4'}
|
|
82
|
+
</button>
|
|
83
|
+
{error && <p style={{ color: 'red' }}>{error.message}</p>}
|
|
84
|
+
{url && <a href={url} download="clip.mp4">Download</a>}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Stitch Multiple Clips
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const blob = await fw.stitch([
|
|
94
|
+
{ source: fileA, startTime: 0, endTime: 10 },
|
|
95
|
+
{ source: fileB, startTime: 5, endTime: 20 },
|
|
96
|
+
{ source: fileC },
|
|
97
|
+
], { width: 1920, height: 1080 });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Caption Style Presets
|
|
101
|
+
|
|
102
|
+
| Preset | Description |
|
|
103
|
+
|--------|-------------|
|
|
104
|
+
| `hormozi` | Chunky Impact font, gold word highlight, black stroke — viral short-form style |
|
|
105
|
+
| `modern` | Clean Inter font, semi-transparent pill background |
|
|
106
|
+
| `minimal` | Thin sans-serif, text shadow only, no background |
|
|
107
|
+
| `bold` | Yellow-on-black, heavy stroke, uppercase — high contrast |
|
|
108
|
+
|
|
109
|
+
Override any property:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
captions: {
|
|
113
|
+
segments: [...],
|
|
114
|
+
style: {
|
|
115
|
+
preset: 'hormozi',
|
|
116
|
+
fontSize: 80,
|
|
117
|
+
color: '#00FF00',
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## BYOB: Bring Your Own Backend
|
|
123
|
+
|
|
124
|
+
Implement the `RendererBackend` interface to use any encoder:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import type { RendererBackend, FrameData, EncodeOptions } from 'frameworker';
|
|
128
|
+
|
|
129
|
+
const myBackend: RendererBackend = {
|
|
130
|
+
name: 'my-encoder',
|
|
131
|
+
async init() {
|
|
132
|
+
// load WASM, warm up workers, etc.
|
|
133
|
+
},
|
|
134
|
+
async encode(frames: FrameData[], opts: EncodeOptions): Promise<Blob> {
|
|
135
|
+
// frames is FrameData[] with .imageData (ImageData), .timestamp, .width, .height
|
|
136
|
+
// return a video Blob
|
|
137
|
+
},
|
|
138
|
+
async concat(blobs: Blob[], opts: EncodeOptions): Promise<Blob> {
|
|
139
|
+
// concatenate multiple video Blobs
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const fw = createFrameWorker({ backend: myBackend });
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## API Reference
|
|
147
|
+
|
|
148
|
+
### `createFrameWorker(config?)`
|
|
149
|
+
|
|
150
|
+
| Option | Type | Default | Description |
|
|
151
|
+
|--------|------|---------|-------------|
|
|
152
|
+
| `backend` | `RendererBackend` | ffmpeg.wasm | Encoder backend |
|
|
153
|
+
| `fps` | `number` | `30` | Default frame rate |
|
|
154
|
+
| `width` | `number` | `1280` | Default output width |
|
|
155
|
+
| `height` | `number` | `720` | Default output height |
|
|
156
|
+
|
|
157
|
+
Returns a `FrameWorker` object:
|
|
158
|
+
|
|
159
|
+
| Method | Signature | Description |
|
|
160
|
+
|--------|-----------|-------------|
|
|
161
|
+
| `render` | `(clip, opts?) => Promise<Blob>` | Render one clip |
|
|
162
|
+
| `renderToUrl` | `(clip, opts?) => Promise<string>` | Render + create object URL |
|
|
163
|
+
| `stitch` | `(clips[], opts?) => Promise<Blob>` | Render + concat clips |
|
|
164
|
+
| `stitchToUrl` | `(clips[], opts?) => Promise<string>` | Stitch + create object URL |
|
|
165
|
+
|
|
166
|
+
### `ClipInput`
|
|
167
|
+
|
|
168
|
+
| Field | Type | Description |
|
|
169
|
+
|-------|------|-------------|
|
|
170
|
+
| `source` | `string \| File \| Blob \| HTMLVideoElement` | Video source |
|
|
171
|
+
| `startTime` | `number` | Trim start (seconds, default: 0) |
|
|
172
|
+
| `endTime` | `number` | Trim end (seconds, default: duration) |
|
|
173
|
+
| `captions` | `CaptionOptions` | Caption segments + style |
|
|
174
|
+
| `crop` | `CropOptions` | Crop region (0–1 fractions) |
|
|
175
|
+
| `aspectRatio` | `AspectRatio` | `'16:9' \| '9:16' \| '1:1' \| '4:3' \| '3:4' \| 'original'` |
|
|
176
|
+
| `volume` | `number` | Volume multiplier 0–2 |
|
|
177
|
+
|
|
178
|
+
### `RenderOptions`
|
|
179
|
+
|
|
180
|
+
| Field | Type | Description |
|
|
181
|
+
|-------|------|-------------|
|
|
182
|
+
| `width` | `number` | Output width in pixels |
|
|
183
|
+
| `height` | `number` | Output height in pixels |
|
|
184
|
+
| `fps` | `number` | Frames per second |
|
|
185
|
+
| `mimeType` | `string` | Output MIME type |
|
|
186
|
+
| `quality` | `number` | Quality 0–1 (non-ffmpeg backends) |
|
|
187
|
+
| `onProgress` | `(p: number) => void` | Progress callback 0–1 |
|
|
188
|
+
| `signal` | `AbortSignal` | Cancellation signal |
|
|
189
|
+
|
|
190
|
+
### React Hooks (`frameworker/react`)
|
|
191
|
+
|
|
192
|
+
#### `useRender(frameWorker)`
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
const { progress, isRendering, error, blob, url, render, cancel, reset } = useRender(fw);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### `useStitch(frameWorker)`
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const { progress, isRendering, error, blob, url, stitch, cancel, reset } = useStitch(fw);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Both hooks expose:
|
|
205
|
+
- `progress` — number 0–1
|
|
206
|
+
- `isRendering` — boolean
|
|
207
|
+
- `error` — `Error | null`
|
|
208
|
+
- `blob` — the output `Blob | null`
|
|
209
|
+
- `url` — `string | null` (object URL, auto-revoked on next render)
|
|
210
|
+
- `cancel()` — abort the current render
|
|
211
|
+
- `reset()` — clear state and revoke URL
|
|
212
|
+
|
|
213
|
+
## Browser Requirements
|
|
214
|
+
|
|
215
|
+
- Chrome/Edge 94+ or Firefox 90+ (OffscreenCanvas, WASM)
|
|
216
|
+
- COOP/COEP headers required for ffmpeg.wasm SharedArrayBuffer:
|
|
217
|
+
```
|
|
218
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
219
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT © nareshipme
|