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.
Files changed (66) hide show
  1. package/.mocharc.json +7 -0
  2. package/README.md +94 -85
  3. package/dist/index.js +243 -24
  4. package/dist/index.js.map +1 -1
  5. package/dist/{types → src}/core/VideoEngine.d.ts +2 -1
  6. package/dist/{types → src}/core/types.d.ts +12 -0
  7. package/dist/src/engines/FFmpegEngine.d.ts +7 -0
  8. package/dist/{types/engines/FFmpegEngine.d.ts → src/engines/GStreamerEngine.d.ts} +2 -1
  9. package/dist/src/index.d.ts +12 -0
  10. package/dist/{types → src}/processor.d.ts +5 -5
  11. package/dist/{types → src}/storage/FileSystemStorage.d.ts +1 -1
  12. package/dist/{types → src}/streaming/StreamManager.d.ts +1 -1
  13. package/dist/tests/video-processor.test.d.ts +1 -0
  14. package/docs/API.md +109 -0
  15. package/docs/HLS.md +54 -0
  16. package/docs/README.md +172 -169
  17. package/docs/caching.md +62 -0
  18. package/docs/engines.md +62 -58
  19. package/docs/storage.md +57 -0
  20. package/examples/full-demo/backend/.env +6 -0
  21. package/examples/full-demo/backend/package-lock.json +1783 -0
  22. package/examples/full-demo/backend/package.json +22 -0
  23. package/examples/full-demo/backend/src/routes/video.js +92 -0
  24. package/examples/full-demo/backend/src/server.js +43 -0
  25. package/examples/full-demo/backend/src/services/videoProcessor.js +85 -0
  26. package/examples/full-demo/frontend/index.html +13 -0
  27. package/examples/full-demo/frontend/package-lock.json +5791 -0
  28. package/examples/full-demo/frontend/package.json +32 -0
  29. package/examples/full-demo/frontend/postcss.config.js +6 -0
  30. package/examples/full-demo/frontend/src/App.jsx +113 -0
  31. package/examples/full-demo/frontend/src/components/ProcessingStatus.jsx +71 -0
  32. package/examples/full-demo/frontend/src/components/VideoPlayer.jsx +87 -0
  33. package/examples/full-demo/frontend/src/components/VideoUploader.jsx +62 -0
  34. package/examples/full-demo/frontend/src/index.css +3 -0
  35. package/examples/full-demo/frontend/src/main.jsx +10 -0
  36. package/examples/full-demo/frontend/src/services/api.js +30 -0
  37. package/examples/full-demo/frontend/tailwind.config.js +10 -0
  38. package/examples/full-demo/frontend/vite.config.js +16 -0
  39. package/examples/simple-usage/README.md +31 -0
  40. package/examples/simple-usage/index.ts +68 -0
  41. package/examples/simple-usage/package-lock.json +592 -0
  42. package/examples/simple-usage/package.json +15 -0
  43. package/package.json +69 -48
  44. package/rollup.config.js +3 -1
  45. package/src/bandwidth.ts +1 -1
  46. package/src/core/VideoEngine.ts +29 -4
  47. package/src/core/events.ts +9 -1
  48. package/src/core/types.ts +38 -3
  49. package/src/engines/FFmpegEngine.ts +173 -32
  50. package/src/engines/GStreamerEngine.ts +24 -1
  51. package/src/index.ts +13 -13
  52. package/src/processor.ts +119 -35
  53. package/src/storage/FileSystemStorage.ts +2 -4
  54. package/src/storage/StorageProvider.ts +7 -2
  55. package/src/streaming/StreamManager.ts +4 -5
  56. package/tests/video-processor.test.ts +32 -12
  57. package/tsconfig.json +19 -5
  58. package/tsconfig.test.json +17 -4
  59. package/dist/types/index.d.ts +0 -10
  60. package/dist/{types → src}/bandwidth.d.ts +0 -0
  61. package/dist/{types → src}/cache/ExternalCache.d.ts +0 -0
  62. package/dist/{types → src}/cache/LRU.d.ts +2 -2
  63. /package/dist/{types → src}/cache/cacheStrategy.d.ts +0 -0
  64. /package/dist/{types → src}/cache/internalCache.d.ts +0 -0
  65. /package/dist/{types → src}/core/events.d.ts +0 -0
  66. /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. [Advanced Usage](#advanced-usage)
11
- 5. [API Reference](#api-reference)
12
-
13
- ## Getting Started
14
-
15
- ### Installation
16
- ```bash
17
- npm install mes-engine
18
- ```
19
-
20
- ### Engine Requirements
21
-
22
- #### FFmpeg Engine
23
- ```bash
24
- npm install ffmpeg-static
25
- ```
26
-
27
- #### GStreamer Engine
28
- Requires GStreamer to be installed on your system:
29
- - Ubuntu/Debian: `apt-get install gstreamer1.0-tools`
30
- - MacOS: `brew install gstreamer`
31
- - Windows: Download from GStreamer website
32
-
33
- ### Basic Configuration
34
-
35
- ```typescript
36
- import { VideoProcessor, FFmpegEngine, FileSystemStorage } from 'mes-engine';
37
-
38
- const config = {
39
- chunkSize: 10, // seconds
40
- cacheDir: './cache',
41
- maxCacheSize: 1000, // MB
42
- defaultQualities: [
43
- { height: 1080, bitrate: '4000k' },
44
- { height: 720, bitrate: '2500k' },
45
- { height: 480, bitrate: '1000k' }
46
- ]
47
- };
48
-
49
- const processor = new VideoProcessor({
50
- engine: new FFmpegEngine(),
51
- storage: new FileSystemStorage(),
52
- config
53
- });
54
- ```
55
-
56
- ## Core Concepts
57
-
58
- ### Video Processing Flow
59
-
60
- 1. **Input**: Raw video file
61
- 2. **Chunking**: Video split into segments
62
- 3. **Transcoding**: Multiple quality versions
63
- 4. **Storage**: Chunks saved to storage provider
64
- 5. **Streaming**: Adaptive delivery
65
-
66
- ### Events System
67
-
68
- ```typescript
69
- processor.on(VideoEvent.CHUNK_PROCESSED, (data) => {
70
- console.log(`Chunk ${data.chunkNumber} processed at ${data.quality}p`);
71
- });
72
-
73
- processor.on(VideoEvent.PROCESSING_COMPLETE, (manifest) => {
74
- console.log('Processing complete:', manifest);
75
- });
76
- ```
77
-
78
- ## Components
79
-
80
- ### Processing Engines
81
-
82
- - **FFmpegEngine**: Standard video processing
83
- - **GStreamerEngine**: High-performance alternative
84
- - **Custom Engines**: Extend `VideoEngine` class
85
-
86
- ```typescript
87
- class CustomEngine extends VideoEngine {
88
- async processChunk(
89
- inputPath: string,
90
- outputPath: string,
91
- startTime: number,
92
- quality: QualityLevel
93
- ): Promise<void> {
94
- // Implementation
95
- }
96
-
97
- async getDuration(inputPath: string): Promise<number> {
98
- // Implementation
99
- }
100
- }
101
- ```
102
-
103
- ### Storage Providers
104
-
105
- - **FileSystemStorage**: Local file system storage
106
- - **Custom Storage**: Implement `StorageProvider`
107
-
108
- ```typescript
109
- class CustomStorage extends StorageProvider {
110
- async saveChunk(chunkPath: string, data: Buffer): Promise<void> {
111
- // Implementation
112
- }
113
-
114
- async getChunk(chunkPath: string): Promise<Buffer> {
115
- // Implementation
116
- }
117
-
118
- async deleteChunk(chunkPath: string): Promise<void> {
119
- // Implementation
120
- }
121
- }
122
- ```
123
-
124
- ### Caching Strategies
125
-
126
- - **InternalCache**: Memory-based LRU cache
127
- - **ExternalCache**: Remote cache service
128
- - **Custom Cache**: Extend `CacheStrategy`
129
-
130
- ## Advanced Usage
131
-
132
- ### Custom Quality Levels
133
-
134
- ```typescript
135
- const customQualities = [
136
- { height: 2160, bitrate: '8000k' }, // 4K
137
- { height: 1440, bitrate: '6000k' }, // 2K
138
- { height: 1080, bitrate: '4000k' }, // Full HD
139
- ];
140
-
141
- const manifest = await processor.processVideo('input.mp4', {
142
- qualities: customQualities
143
- });
144
- ```
145
-
146
- ### Bandwidth-Aware Streaming
147
-
148
- ```typescript
149
- import { BandwidthDetector } from 'mes-engine';
150
-
151
- const detector = new BandwidthDetector();
152
- detector.addSample(bytesTransferred, durationMs);
153
- const estimatedBandwidth = detector.getEstimatedBandwidth();
154
- ```
155
-
156
- ## API Reference
157
-
158
- See [API.md](./API.md) for detailed API documentation.
159
-
160
- ## Testing
161
-
162
- ```bash
163
- npm run test # Run all tests
164
- npm run test:watch # Watch mode
165
- npm run test:coverage # Coverage report
166
- ```
167
-
168
- ## Contributing
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.
@@ -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
- For more details on implementing custom engines, see the [VideoEngine class](../src/core/VideoEngine.ts) in the codebase.
54
-
55
- ## Other Supported Engines
56
- You can extend this framework with any other video processing engine that implements the `VideoEngine` interface.
57
-
58
- For more details, check the [source code](https://github.com/Bum-Ho12/mes-engine) and adapt it as needed for your requirements.
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.
@@ -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
+ ```
@@ -0,0 +1,6 @@
1
+ PORT=3001
2
+ UPLOAD_DIR=./uploads
3
+ PROCESSED_DIR=./processed
4
+ MAX_FILE_SIZE=524288000
5
+ CACHE_SIZE=104857600
6
+ CACHE_TTL=3600