@video-editor/protocol 0.0.1-beta.26 → 0.0.1-beta.28
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 +93 -2
- package/dist/index.d.ts +46 -0
- package/dist/index.js +2455 -2347
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
# @video-editor/
|
|
1
|
+
# @video-editor/protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Video editor protocol management, validation, and resource utilities.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Protocol Management**: Create and manage video editor protocols with undo/redo
|
|
8
|
+
- **Validation**: JSON Schema validation for all segment types
|
|
9
|
+
- **Resource Management**: OPFS-based caching for video/audio resources
|
|
10
|
+
- **Waveform Extraction**: Extract and cache audio waveforms for visualization
|
|
11
|
+
- **Thumbnail Generation**: Extract video thumbnails with caching
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @video-editor/protocol
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### Audio Waveform Extraction
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { extractWaveform, peaksToSvgPath } from '@video-editor/protocol'
|
|
25
|
+
|
|
26
|
+
// Extract waveform from audio URL
|
|
27
|
+
const waveform = await extractWaveform('/audio.mp3', { samples: 1000 })
|
|
28
|
+
|
|
29
|
+
// Generate SVG path for rendering
|
|
30
|
+
const svgPath = peaksToSvgPath(waveform.peaks, 800, 100)
|
|
31
|
+
|
|
32
|
+
console.log(waveform.peaks) // number[] - normalized 0-1
|
|
33
|
+
console.log(waveform.duration) // number - seconds
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Protocol Management
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { createVideoProtocolManager } from '@video-editor/protocol'
|
|
40
|
+
import type { IVideoProtocol } from '@video-editor/protocol'
|
|
41
|
+
|
|
42
|
+
const protocol: IVideoProtocol = { /* ... */ }
|
|
43
|
+
const manager = createVideoProtocolManager(protocol)
|
|
44
|
+
|
|
45
|
+
// Add segment
|
|
46
|
+
manager.addSegment({
|
|
47
|
+
id: 'audio-1',
|
|
48
|
+
segmentType: 'audio',
|
|
49
|
+
url: '/audio.mp3',
|
|
50
|
+
startTime: 0,
|
|
51
|
+
endTime: 3000,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Undo/Redo
|
|
55
|
+
manager.undo()
|
|
56
|
+
manager.redo()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Resource Caching
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { createResourceManager } from '@video-editor/protocol'
|
|
63
|
+
|
|
64
|
+
const resourceManager = createResourceManager()
|
|
65
|
+
|
|
66
|
+
// Add resource to OPFS cache
|
|
67
|
+
await resourceManager.add('/video-editor-res/audio.mp3', audioBlob)
|
|
68
|
+
|
|
69
|
+
// Read from cache
|
|
70
|
+
const cached = await resourceManager.read('/video-editor-res/audio.mp3')
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
See [WAVEFORM.md](../../WAVEFORM.md) for detailed waveform API documentation.
|
|
76
|
+
|
|
77
|
+
## Exports
|
|
78
|
+
|
|
79
|
+
### Waveform
|
|
80
|
+
- `extractWaveform(url, options)` - Extract waveform from URL
|
|
81
|
+
- `extractWaveformFromBuffer(buffer, cacheKey, options)` - Extract from ArrayBuffer
|
|
82
|
+
- `clearWaveformCache(url?)` - Clear waveform cache
|
|
83
|
+
- `peaksToSvgPath(peaks, width, height)` - Generate SVG path
|
|
84
|
+
- `peaksToBars(peaks, width)` - Generate bar data
|
|
85
|
+
|
|
86
|
+
### Protocol
|
|
87
|
+
- `createVideoProtocolManager(protocol)` - Create protocol manager
|
|
88
|
+
- `createValidator()` - Create protocol validator
|
|
89
|
+
- `parse(protocolString)` - Parse and validate protocol JSON
|
|
90
|
+
|
|
91
|
+
### Resources
|
|
92
|
+
- `createResourceManager(dir?)` - Create resource manager
|
|
93
|
+
- `generateThumbnails(url, options)` - Generate video thumbnails
|
|
94
|
+
- `getMp4Meta(url)` - Extract MP4 metadata
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ import { SegmentUnion } from '@video-editor/shared';
|
|
|
20
20
|
import { TrackTypeMapSegment } from '@video-editor/shared';
|
|
21
21
|
import { TrackUnion } from '@video-editor/shared';
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Clear waveform cache for a specific URL or all
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearWaveformCache(url?: string): void;
|
|
27
|
+
|
|
23
28
|
export declare function createResourceManager(opts?: {
|
|
24
29
|
dir?: string;
|
|
25
30
|
}): {
|
|
@@ -469,6 +474,17 @@ export declare const DUPLICATE_SEGMENT_ID = "duplicate segment id";
|
|
|
469
474
|
|
|
470
475
|
export declare const DUPLICATE_TRACK_ID = "duplicate track id";
|
|
471
476
|
|
|
477
|
+
/**
|
|
478
|
+
* Extract waveform peaks from an audio URL
|
|
479
|
+
* Will try to read from OPFS cache first, then fall back to fetch
|
|
480
|
+
*/
|
|
481
|
+
export declare function extractWaveform(url: string, options?: WaveformOptions): Promise<WaveformData>;
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Extract waveform from an ArrayBuffer directly (no fetch needed)
|
|
485
|
+
*/
|
|
486
|
+
export declare function extractWaveformFromBuffer(arrayBuffer: ArrayBuffer, cacheKey: string, options?: Omit<WaveformOptions, 'resourceDir'>): Promise<WaveformData>;
|
|
487
|
+
|
|
472
488
|
export declare function fileTo(type: IResType): typeof fileToImage | typeof fileToMP4 | (() => Promise<void>) | (() => Promise<void>) | (() => Promise<void>);
|
|
473
489
|
|
|
474
490
|
declare function fileToImage(file: OPFSToolFile): Promise<HTMLImageElement | undefined>;
|
|
@@ -556,6 +572,19 @@ declare type parseFn = (videoProtocolStr: string) => object;
|
|
|
556
572
|
|
|
557
573
|
declare type PartialByKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
558
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Generate waveform bars data for canvas/div rendering
|
|
577
|
+
*/
|
|
578
|
+
export declare function peaksToBars(peaks: number[], containerWidth: number): Array<{
|
|
579
|
+
x: number;
|
|
580
|
+
height: number;
|
|
581
|
+
}>;
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Create a simple waveform SVG path from peaks
|
|
585
|
+
*/
|
|
586
|
+
export declare function peaksToSvgPath(peaks: number[], width: number, height: number): string;
|
|
587
|
+
|
|
559
588
|
export { SegmentUnion }
|
|
560
589
|
|
|
561
590
|
declare interface Thumbnail {
|
|
@@ -569,4 +598,21 @@ export { TrackUnion }
|
|
|
569
598
|
|
|
570
599
|
export declare function vFetch(url: string, init?: RequestInit): Promise<Response>;
|
|
571
600
|
|
|
601
|
+
/**
|
|
602
|
+
* Extract waveform peaks from audio for visualization
|
|
603
|
+
*/
|
|
604
|
+
export declare interface WaveformData {
|
|
605
|
+
peaks: number[];
|
|
606
|
+
duration: number;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export declare interface WaveformOptions {
|
|
610
|
+
/** Number of samples to extract (default: 100) */
|
|
611
|
+
samples?: number;
|
|
612
|
+
/** Channel to use: 0 = left, 1 = right, 'mix' = average (default: 'mix') */
|
|
613
|
+
channel?: number | 'mix';
|
|
614
|
+
/** Resource directory for OPFS cache (default: DEFAULT_RESOURCE_DIR) */
|
|
615
|
+
resourceDir?: string;
|
|
616
|
+
}
|
|
617
|
+
|
|
572
618
|
export { }
|