mes-engine 0.0.2 → 1.0.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/.mocharc.json +7 -0
- package/README.md +94 -85
- package/dist/index.js +243 -24
- package/dist/index.js.map +1 -1
- package/dist/{types → src}/core/VideoEngine.d.ts +2 -1
- package/dist/{types → src}/core/types.d.ts +12 -0
- package/dist/src/engines/FFmpegEngine.d.ts +7 -0
- package/dist/{types/engines/FFmpegEngine.d.ts → src/engines/GStreamerEngine.d.ts} +2 -1
- package/dist/src/index.d.ts +12 -0
- package/dist/{types → src}/processor.d.ts +5 -5
- package/dist/{types → src}/storage/FileSystemStorage.d.ts +1 -1
- package/dist/{types → src}/streaming/StreamManager.d.ts +1 -1
- package/dist/tests/video-processor.test.d.ts +1 -0
- package/docs/API.md +109 -0
- package/docs/HLS.md +54 -0
- package/docs/README.md +172 -169
- package/docs/caching.md +62 -0
- package/docs/engines.md +62 -58
- package/docs/storage.md +57 -0
- package/examples/full-demo/backend/.env +6 -0
- package/examples/full-demo/backend/package-lock.json +1783 -0
- package/examples/full-demo/backend/package.json +22 -0
- package/examples/full-demo/backend/src/routes/video.js +92 -0
- package/examples/full-demo/backend/src/server.js +43 -0
- package/examples/full-demo/backend/src/services/videoProcessor.js +85 -0
- package/examples/full-demo/frontend/index.html +13 -0
- package/examples/full-demo/frontend/package-lock.json +5791 -0
- package/examples/full-demo/frontend/package.json +32 -0
- package/examples/full-demo/frontend/postcss.config.js +6 -0
- package/examples/full-demo/frontend/src/App.jsx +113 -0
- package/examples/full-demo/frontend/src/components/ProcessingStatus.jsx +71 -0
- package/examples/full-demo/frontend/src/components/VideoPlayer.jsx +87 -0
- package/examples/full-demo/frontend/src/components/VideoUploader.jsx +62 -0
- package/examples/full-demo/frontend/src/index.css +3 -0
- package/examples/full-demo/frontend/src/main.jsx +10 -0
- package/examples/full-demo/frontend/src/services/api.js +30 -0
- package/examples/full-demo/frontend/tailwind.config.js +10 -0
- package/examples/full-demo/frontend/vite.config.js +16 -0
- package/examples/simple-usage/README.md +31 -0
- package/examples/simple-usage/index.ts +68 -0
- package/examples/simple-usage/package-lock.json +592 -0
- package/examples/simple-usage/package.json +15 -0
- package/package.json +69 -48
- package/rollup.config.js +3 -1
- package/src/bandwidth.ts +1 -1
- package/src/core/VideoEngine.ts +29 -4
- package/src/core/events.ts +9 -1
- package/src/core/types.ts +38 -3
- package/src/engines/FFmpegEngine.ts +173 -32
- package/src/engines/GStreamerEngine.ts +24 -1
- package/src/index.ts +13 -13
- package/src/processor.ts +119 -35
- package/src/storage/FileSystemStorage.ts +2 -4
- package/src/storage/StorageProvider.ts +7 -2
- package/src/streaming/StreamManager.ts +4 -5
- package/tests/video-processor.test.ts +32 -12
- package/tsconfig.json +19 -5
- package/tsconfig.test.json +17 -4
- package/dist/types/index.d.ts +0 -10
- package/dist/{types → src}/bandwidth.d.ts +0 -0
- package/dist/{types → src}/cache/ExternalCache.d.ts +0 -0
- package/dist/{types → src}/cache/LRU.d.ts +2 -2
- /package/dist/{types → src}/cache/cacheStrategy.d.ts +0 -0
- /package/dist/{types → src}/cache/internalCache.d.ts +0 -0
- /package/dist/{types → src}/core/events.d.ts +0 -0
- /package/dist/{types → src}/storage/StorageProvider.d.ts +0 -0
package/docs/README.md
CHANGED
|
@@ -1,170 +1,173 @@
|
|
|
1
|
-
# Video Processing Framework Documentation
|
|
2
|
-
|
|
3
|
-
Comprehensive documentation for the mes-engine video processing framework.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
1. [Getting Started](#getting-started)
|
|
8
|
-
2. [Core Concepts](#core-concepts)
|
|
9
|
-
3. [Components](#components)
|
|
10
|
-
4. [
|
|
11
|
-
5. [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
# Video Processing Framework Documentation
|
|
2
|
+
|
|
3
|
+
Comprehensive documentation for the mes-engine video processing framework.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Getting Started](#getting-started)
|
|
8
|
+
2. [Core Concepts](#core-concepts)
|
|
9
|
+
3. [Components](#components)
|
|
10
|
+
4. [HLS & Adaptive Streaming](./HLS.md)
|
|
11
|
+
5. [Storage Providers](./storage.md)
|
|
12
|
+
6. [Caching Strategies](./caching.md)
|
|
13
|
+
7. [Advanced Usage](#advanced-usage)
|
|
14
|
+
8. [API Reference](./API.md)
|
|
15
|
+
|
|
16
|
+
## Getting Started
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
```bash
|
|
20
|
+
npm install mes-engine
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Engine Requirements
|
|
24
|
+
|
|
25
|
+
#### FFmpeg Engine
|
|
26
|
+
```bash
|
|
27
|
+
npm install ffmpeg-static
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### GStreamer Engine
|
|
31
|
+
Requires GStreamer to be installed on your system:
|
|
32
|
+
- Ubuntu/Debian: `apt-get install gstreamer1.0-tools`
|
|
33
|
+
- MacOS: `brew install gstreamer`
|
|
34
|
+
- Windows: Download from GStreamer website
|
|
35
|
+
|
|
36
|
+
### Basic Configuration
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { VideoProcessor, FFmpegEngine, FileSystemStorage } from 'mes-engine';
|
|
40
|
+
|
|
41
|
+
const config = {
|
|
42
|
+
chunkSize: 10, // seconds
|
|
43
|
+
cacheDir: './cache',
|
|
44
|
+
maxCacheSize: 1024 * 1024 * 1024, // 1GB
|
|
45
|
+
defaultQualities: [
|
|
46
|
+
{ height: 1080, bitrate: '4000k' },
|
|
47
|
+
{ height: 720, bitrate: '2500k' },
|
|
48
|
+
{ height: 480, bitrate: '1000k' }
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const processor = new VideoProcessor(
|
|
53
|
+
new FFmpegEngine(),
|
|
54
|
+
new FileSystemStorage(),
|
|
55
|
+
config
|
|
56
|
+
);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Core Concepts
|
|
60
|
+
|
|
61
|
+
### Video Processing Flow
|
|
62
|
+
|
|
63
|
+
1. **Input**: Raw video file
|
|
64
|
+
2. **Chunking**: Video split into segments
|
|
65
|
+
3. **Transcoding**: Multiple quality versions
|
|
66
|
+
4. **Storage**: Chunks saved to storage provider
|
|
67
|
+
5. **Streaming**: Adaptive delivery
|
|
68
|
+
|
|
69
|
+
### Events System
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
processor.on(VideoEvent.CHUNK_PROCESSED, (data) => {
|
|
73
|
+
console.log(`Chunk ${data.chunkNumber} processed at ${data.quality}p`);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
processor.on(VideoEvent.PROCESSING_COMPLETE, (manifest) => {
|
|
77
|
+
console.log('Processing complete:', manifest);
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Components
|
|
82
|
+
|
|
83
|
+
### Processing Engines
|
|
84
|
+
|
|
85
|
+
- **FFmpegEngine**: Standard video processing
|
|
86
|
+
- **GStreamerEngine**: High-performance alternative
|
|
87
|
+
- **Custom Engines**: Extend `VideoEngine` class
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
class CustomEngine extends VideoEngine {
|
|
91
|
+
async processChunk(
|
|
92
|
+
inputPath: string,
|
|
93
|
+
outputPath: string,
|
|
94
|
+
startTime: number,
|
|
95
|
+
quality: QualityLevel
|
|
96
|
+
): Promise<void> {
|
|
97
|
+
// Implementation
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async getDuration(inputPath: string): Promise<number> {
|
|
101
|
+
// Implementation
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Storage Providers
|
|
107
|
+
|
|
108
|
+
- **FileSystemStorage**: Local file system storage
|
|
109
|
+
- **Custom Storage**: Implement `StorageProvider`
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
class CustomStorage extends StorageProvider {
|
|
113
|
+
async saveChunk(chunkPath: string, data: Buffer): Promise<void> {
|
|
114
|
+
// Implementation
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async getChunk(chunkPath: string): Promise<Buffer> {
|
|
118
|
+
// Implementation
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async deleteChunk(chunkPath: string): Promise<void> {
|
|
122
|
+
// Implementation
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Caching Strategies
|
|
128
|
+
|
|
129
|
+
- **InternalCache**: Memory-based LRU cache
|
|
130
|
+
- **ExternalCache**: Remote cache service
|
|
131
|
+
- **Custom Cache**: Extend `CacheStrategy`
|
|
132
|
+
|
|
133
|
+
## Advanced Usage
|
|
134
|
+
|
|
135
|
+
### Custom Quality Levels
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
const customQualities = [
|
|
139
|
+
{ height: 2160, bitrate: '8000k' }, // 4K
|
|
140
|
+
{ height: 1440, bitrate: '6000k' }, // 2K
|
|
141
|
+
{ height: 1080, bitrate: '4000k' }, // Full HD
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
const manifest = await processor.processVideo('input.mp4', {
|
|
145
|
+
qualities: customQualities
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Bandwidth-Aware Streaming
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { BandwidthDetector } from 'mes-engine';
|
|
153
|
+
|
|
154
|
+
const detector = new BandwidthDetector();
|
|
155
|
+
detector.addSample(bytesTransferred, durationMs);
|
|
156
|
+
const estimatedBandwidth = detector.getEstimatedBandwidth();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## API Reference
|
|
160
|
+
|
|
161
|
+
See [API.md](./API.md) for detailed API documentation.
|
|
162
|
+
|
|
163
|
+
## Testing
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npm run test # Run all tests
|
|
167
|
+
npm run test:watch # Watch mode
|
|
168
|
+
npm run test:coverage # Coverage report
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Contributing
|
|
172
|
+
|
|
170
173
|
See [CONTRIBUTING.md](../CONTRIBUTING.md) for contribution guidelines.
|
package/docs/caching.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Caching Strategies
|
|
2
|
+
|
|
3
|
+
Intelligent caching is built into `mes-engine` to reduce storage latency and improve streaming performance.
|
|
4
|
+
|
|
5
|
+
## Cache Options
|
|
6
|
+
|
|
7
|
+
The `CacheOptions` interface defines how the cache behaves:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
interface CacheOptions {
|
|
11
|
+
maxSize: number; // Maximum size of the cache in bytes
|
|
12
|
+
ttl: number; // Time To Live in seconds
|
|
13
|
+
preloadNextChunk: boolean; // Whether to automatically fetch the next chunk
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Supported Strategies
|
|
18
|
+
|
|
19
|
+
### `InternalCache`
|
|
20
|
+
A memory-based cache using a Least Recently Used (LRU) eviction policy. It is highly effective for hot content.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { InternalCache, FileSystemStorage } from 'mes-engine';
|
|
24
|
+
|
|
25
|
+
const storage = new FileSystemStorage();
|
|
26
|
+
const cache = new InternalCache({
|
|
27
|
+
maxSize: 1024 * 1024 * 500, // 500MB
|
|
28
|
+
ttl: 3600,
|
|
29
|
+
preloadNextChunk: true
|
|
30
|
+
}, storage);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Key Features
|
|
34
|
+
|
|
35
|
+
### Next-Chunk Preloading
|
|
36
|
+
When `preloadNextChunk` is enabled, the `InternalCache` will automatically attempt to fetch the next sequential chunk (e.g., `chunk_1` if `chunk_0` was requested) and store it in memory. This significantly reduces buffer times for sequential playback.
|
|
37
|
+
|
|
38
|
+
## Custom Caching
|
|
39
|
+
|
|
40
|
+
You can implement your own strategy (e.g., using Redis) by extending the `CacheStrategy` class:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { CacheStrategy } from 'mes-engine';
|
|
44
|
+
|
|
45
|
+
class RedisCache extends CacheStrategy {
|
|
46
|
+
async set(key: string, value: Buffer): Promise<void> {
|
|
47
|
+
// Redis SETEX
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async get(key: string): Promise<Buffer | null> {
|
|
51
|
+
// Redis GET
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async preload(key: string): Promise<void> {
|
|
55
|
+
// Custom preloading logic
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async clear(): Promise<void> {
|
|
59
|
+
// Redis FLUSHDB
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
package/docs/engines.md
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
|
-
# Engines Support
|
|
2
|
-
|
|
3
|
-
## FFmpegEngine
|
|
4
|
-
The `FFmpegEngine` uses `ffmpeg` for video processing. You will need to install an FFmpeg binary to use this engine.
|
|
5
|
-
|
|
6
|
-
### Installation of FFmpeg
|
|
7
|
-
To use the `FFmpegEngine`, you must install FFmpeg or use `ffmpeg-static` to include the FFmpeg binary. You can install `ffmpeg-static` by running:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install ffmpeg-static
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Alternatively, you can use any other FFmpeg binary that is compatible with your system.
|
|
14
|
-
|
|
15
|
-
### Example Usage:
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { FFmpegEngine } from 'mes-engine';
|
|
19
|
-
|
|
20
|
-
// Create an FFmpeg engine instance
|
|
21
|
-
const engine = new FFmpegEngine();
|
|
22
|
-
|
|
23
|
-
// Use it to process video chunks
|
|
24
|
-
engine.processChunk('input.mp4', 'output.mp4', 0, { height: 720, bitrate: '2000k' })
|
|
25
|
-
.then(() => {
|
|
26
|
-
console.log('Chunk processed successfully');
|
|
27
|
-
})
|
|
28
|
-
.catch(error => {
|
|
29
|
-
console.error('Error processing chunk:', error);
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Custom Engines
|
|
34
|
-
You can implement your own video processing engine by extending the `VideoEngine` class. Here’s an example of how to create a custom engine:
|
|
35
|
-
|
|
36
|
-
### Example Custom Engine:
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
import { VideoEngine } from 'mes-engine';
|
|
40
|
-
|
|
41
|
-
class CustomVideoEngine extends VideoEngine {
|
|
42
|
-
async processChunk(inputPath: string, outputPath: string, startTime: number, quality: any): Promise<void> {
|
|
43
|
-
// Implement custom video processing logic here
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getDuration(inputPath: string): Promise<number> {
|
|
47
|
-
// Implement custom duration calculation logic here
|
|
48
|
-
return 120; // Example
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
# Engines Support
|
|
2
|
+
|
|
3
|
+
## FFmpegEngine
|
|
4
|
+
The `FFmpegEngine` uses `ffmpeg` for video processing. You will need to install an FFmpeg binary to use this engine.
|
|
5
|
+
|
|
6
|
+
### Installation of FFmpeg
|
|
7
|
+
To use the `FFmpegEngine`, you must install FFmpeg or use `ffmpeg-static` to include the FFmpeg binary. You can install `ffmpeg-static` by running:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install ffmpeg-static
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Alternatively, you can use any other FFmpeg binary that is compatible with your system.
|
|
14
|
+
|
|
15
|
+
### Example Usage:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { FFmpegEngine } from 'mes-engine';
|
|
19
|
+
|
|
20
|
+
// Create an FFmpeg engine instance
|
|
21
|
+
const engine = new FFmpegEngine();
|
|
22
|
+
|
|
23
|
+
// Use it to process video chunks
|
|
24
|
+
engine.processChunk('input.mp4', 'output.mp4', 0, { height: 720, bitrate: '2000k' })
|
|
25
|
+
.then(() => {
|
|
26
|
+
console.log('Chunk processed successfully');
|
|
27
|
+
})
|
|
28
|
+
.catch(error => {
|
|
29
|
+
console.error('Error processing chunk:', error);
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Custom Engines
|
|
34
|
+
You can implement your own video processing engine by extending the `VideoEngine` class. Here’s an example of how to create a custom engine:
|
|
35
|
+
|
|
36
|
+
### Example Custom Engine:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { VideoEngine } from 'mes-engine';
|
|
40
|
+
|
|
41
|
+
class CustomVideoEngine extends VideoEngine {
|
|
42
|
+
async processChunk(inputPath: string, outputPath: string, startTime: number, quality: any): Promise<void> {
|
|
43
|
+
// Implement custom video processing logic here
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getDuration(inputPath: string): Promise<number> {
|
|
47
|
+
// Implement custom duration calculation logic here
|
|
48
|
+
return 120; // Example
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async extractScreenshot(inputPath: string, outputPath: string, time: number): Promise<void> {
|
|
52
|
+
// Implement custom screenshot extraction logic here
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For more details on implementing custom engines, see the [VideoEngine class](../src/core/VideoEngine.ts) in the codebase.
|
|
58
|
+
|
|
59
|
+
## Other Supported Engines
|
|
60
|
+
You can extend this framework with any other video processing engine that implements the `VideoEngine` interface.
|
|
61
|
+
|
|
62
|
+
For more details, check the [source code](https://github.com/Bum-Ho12/mes-engine) and adapt it as needed for your requirements.
|
package/docs/storage.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Storage Providers
|
|
2
|
+
|
|
3
|
+
`mes-engine` uses an abstract storage layer to remain independent of where your video chunks are actually stored.
|
|
4
|
+
|
|
5
|
+
## Base Class: `StorageProvider`
|
|
6
|
+
|
|
7
|
+
All storage providers must extend the `StorageProvider` abstract class and implement its three core methods:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
export abstract class StorageProvider {
|
|
11
|
+
abstract saveChunk(chunkPath: string, data: Buffer): Promise<void>;
|
|
12
|
+
abstract getChunk(chunkPath: string): Promise<Buffer>;
|
|
13
|
+
abstract deleteChunk(chunkPath: string): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Built-in Providers
|
|
18
|
+
|
|
19
|
+
### `FileSystemStorage`
|
|
20
|
+
The default provider for local development and on-premise deployments. It saves chunks directly to the server's disk.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { FileSystemStorage } from 'mes-engine';
|
|
24
|
+
|
|
25
|
+
const storage = new FileSystemStorage();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Creating a Custom Provider
|
|
29
|
+
|
|
30
|
+
You can easily create a provider for S3, Azure Blob Storage, or any other service by extending `StorageProvider`.
|
|
31
|
+
|
|
32
|
+
### Example: S3 Storage Provider
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { StorageProvider } from 'mes-engine';
|
|
36
|
+
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
|
|
37
|
+
|
|
38
|
+
class S3Storage extends StorageProvider {
|
|
39
|
+
private client = new S3Client({});
|
|
40
|
+
|
|
41
|
+
async saveChunk(chunkPath: string, data: Buffer): Promise<void> {
|
|
42
|
+
await this.client.send(new PutObjectCommand({
|
|
43
|
+
Bucket: 'my-videos',
|
|
44
|
+
Key: chunkPath,
|
|
45
|
+
Body: data
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getChunk(chunkPath: string): Promise<Buffer> {
|
|
50
|
+
// Implement S3 GetObject and return Buffer
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async deleteChunk(chunkPath: string): Promise<void> {
|
|
54
|
+
// Implement S3 DeleteObject
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|