@vidtreo/recorder 0.0.1

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 ADDED
@@ -0,0 +1,229 @@
1
+ # @vidtreo/recorder
2
+
3
+ Video transcoding package using mediabunny. Transcodes videos to MP4 format with configurable settings, optimized for Bun runtime.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vidtreo/recorder
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Usage
14
+
15
+ ```typescript
16
+ import { transcodeVideo } from '@vidtreo/recorder';
17
+
18
+ // Transcode from a Blob
19
+ const videoBlob = new Blob([videoData], { type: 'video/mp4' });
20
+ const result = await transcodeVideo(videoBlob);
21
+ console.log(result.buffer); // ArrayBuffer with transcoded video
22
+ console.log(result.blob); // Blob with transcoded video
23
+
24
+ // Transcode from a File
25
+ const fileInput = document.querySelector('input[type="file"]');
26
+ const file = fileInput.files[0];
27
+ const result = await transcodeVideo(file);
28
+
29
+ // Transcode from a file path (Bun only)
30
+ const result = await transcodeVideo('/path/to/video.mp4');
31
+ ```
32
+
33
+ ### Custom Configuration
34
+
35
+ ```typescript
36
+ import { transcodeVideo, DEFAULT_TRANSCODE_CONFIG } from '@vidtreo/recorder';
37
+
38
+ // Use custom configuration
39
+ const result = await transcodeVideo(videoBlob, {
40
+ width: 1920,
41
+ height: 1080,
42
+ fps: 60,
43
+ bitrate: 2000000, // 2Mbps
44
+ packetCount: 2000,
45
+ });
46
+
47
+ // Partial configuration (merges with defaults)
48
+ const result = await transcodeVideo(videoBlob, {
49
+ width: 640,
50
+ height: 480,
51
+ });
52
+ ```
53
+
54
+ ## Configuration
55
+
56
+ The default configuration is:
57
+
58
+ ```typescript
59
+ {
60
+ format: 'mp4', // Always MP4 output
61
+ fps: 30, // 30 frames per second
62
+ width: 1280, // 1280 pixels
63
+ height: 720, // 720 pixels
64
+ bitrate: 500000, // 500kbps
65
+ audioCodec: 'aac', // AAC audio codec
66
+ preset: 'medium', // Medium quality preset
67
+ packetCount: 1200, // Maximum packet count for video track
68
+ }
69
+ ```
70
+
71
+ ### Configuration Options
72
+
73
+ - `format`: Output format (always `'mp4'`)
74
+ - `fps`: Target frame rate in frames per second
75
+ - `width`: Target video width in pixels
76
+ - `height`: Target video height in pixels
77
+ - `bitrate`: Target video bitrate in bits per second
78
+ - `audioCodec`: Audio codec to use (always `'aac'`)
79
+ - `preset`: Quality preset (always `'medium'`)
80
+ - `packetCount`: Maximum packet count for video track metadata (optimization hint)
81
+
82
+ ## API Reference
83
+
84
+ ### `transcodeVideo(input, config?)`
85
+
86
+ Transcodes a video file to MP4 format.
87
+
88
+ **Parameters:**
89
+ - `input`: `Blob | File | string` - Input video source (Blob, File, or file path string)
90
+ - `config`: `Partial<TranscodeConfig>` - Optional configuration object (merges with defaults)
91
+
92
+ **Returns:** `Promise<TranscodeResult>`
93
+
94
+ **Throws:** `Error` if transcoding fails or input is invalid
95
+
96
+ ### `TranscodeResult`
97
+
98
+ ```typescript
99
+ interface TranscodeResult {
100
+ buffer: ArrayBuffer; // Transcoded video as ArrayBuffer
101
+ blob: Blob; // Transcoded video as Blob
102
+ }
103
+ ```
104
+
105
+ ### `DEFAULT_TRANSCODE_CONFIG`
106
+
107
+ Default configuration object. Can be imported and used as a base for custom configurations.
108
+
109
+ ## Supported Input Formats
110
+
111
+ The package supports all formats supported by mediabunny:
112
+ - MP4 (.mp4, .m4v)
113
+ - WebM (.webm)
114
+ - QuickTime (.mov)
115
+ - Matroska (.mkv)
116
+ - OGG (.ogv)
117
+ - And more...
118
+
119
+ ## Bun Optimizations
120
+
121
+ This package leverages Bun's native capabilities:
122
+ - Uses `Bun.file()` for efficient file reading when file paths are provided
123
+ - Optimized for Bun's runtime and test runner
124
+ - Native ArrayBuffer handling
125
+
126
+ ## Examples
127
+
128
+ ### Transcode and Save to File (Bun)
129
+
130
+ ```typescript
131
+ import { transcodeVideo } from '@vidtreo/recorder';
132
+ import { writeFile } from 'fs/promises';
133
+
134
+ const result = await transcodeVideo('/path/to/input.mp4');
135
+ await Bun.write('/path/to/output.mp4', result.buffer);
136
+ ```
137
+
138
+ ### Transcode with Progress Tracking
139
+
140
+ ```typescript
141
+ import { transcodeVideo } from '@vidtreo/recorder';
142
+
143
+ console.log('Starting transcoding...');
144
+ const result = await transcodeVideo(videoBlob);
145
+ console.log('Transcoding complete!');
146
+ console.log(`Output size: ${result.buffer.byteLength} bytes`);
147
+ ```
148
+
149
+ ## Web Component
150
+
151
+ This package also includes a standalone web component (`<vidtreo-recorder>`) that can be used in any HTML page without requiring a build step or framework.
152
+
153
+ ### Building the Web Component
154
+
155
+ To build the web component, run:
156
+
157
+ ```bash
158
+ bun run build:wc
159
+ ```
160
+
161
+ This will create two files in `dist/wc/`:
162
+ - `vidtreo-recorder.js` - The web component JavaScript bundle
163
+ - `vidtreo-recorder.css` - The Tailwind CSS stylesheet
164
+
165
+ ### Web Component Usage
166
+
167
+ #### Basic Usage
168
+
169
+ Include both the CSS and JS files in your HTML:
170
+
171
+ ```html
172
+ <!DOCTYPE html>
173
+ <html lang="en">
174
+ <head>
175
+ <meta charset="UTF-8">
176
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
177
+ <title>My App</title>
178
+ <!-- Include the CSS file -->
179
+ <link rel="stylesheet" href="./dist/wc/vidtreo-recorder.css">
180
+ </head>
181
+ <body>
182
+ <!-- Use the web component -->
183
+ <vidtreo-recorder></vidtreo-recorder>
184
+
185
+ <!-- Include the JS file -->
186
+ <script src="./dist/wc/vidtreo-recorder.js"></script>
187
+ </body>
188
+ </html>
189
+ ```
190
+
191
+ #### CDN Usage
192
+
193
+ After uploading the files to your CDN, reference them:
194
+
195
+ ```html
196
+ <link rel="stylesheet" href="https://your-cdn.com/vidtreo-recorder.css">
197
+ <script src="https://your-cdn.com/vidtreo-recorder.js"></script>
198
+
199
+ <vidtreo-recorder></vidtreo-recorder>
200
+ ```
201
+
202
+ ### Web Component Features
203
+
204
+ - Drag and drop video file upload
205
+ - Click to upload video files
206
+ - Real-time transcoding progress
207
+ - Download transcoded MP4 files
208
+ - Play transcoded videos in a new window
209
+ - Error handling and validation
210
+
211
+ ### Web Component Development
212
+
213
+ To develop the web component with hot reload:
214
+
215
+ ```bash
216
+ bun run dev:wc
217
+ ```
218
+
219
+ ### Web Component File Structure
220
+
221
+ - `src/components/vidtreo-recorder.wc.ts` - Web component source code
222
+ - `src/styles/tailwind.css` - Tailwind CSS source
223
+ - `vite.wc.config.ts` - Vite configuration for web component build
224
+ - `dist/wc/` - Build output directory
225
+
226
+ ## License
227
+
228
+ MIT
229
+