unified-video-framework 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/.github/workflows/ci.yml +253 -0
- package/ANDROID_TV_IMPLEMENTATION.md +313 -0
- package/COMPLETION_STATUS.md +165 -0
- package/CONTRIBUTING.md +376 -0
- package/FINAL_STATUS_REPORT.md +170 -0
- package/FRAMEWORK_REVIEW.md +247 -0
- package/IMPROVEMENTS_SUMMARY.md +168 -0
- package/LICENSE +21 -0
- package/NATIVE_APP_INTEGRATION_GUIDE.md +903 -0
- package/PAYWALL_RENTAL_FLOW.md +499 -0
- package/PLATFORM_SETUP_GUIDE.md +1636 -0
- package/README.md +315 -0
- package/RUN_LOCALLY.md +151 -0
- package/apps/demo/cast-sender-min.html +173 -0
- package/apps/demo/custom-player.html +883 -0
- package/apps/demo/demo.html +990 -0
- package/apps/demo/enhanced-player.html +3556 -0
- package/apps/demo/index.html +159 -0
- package/apps/rental-api/.env.example +24 -0
- package/apps/rental-api/README.md +23 -0
- package/apps/rental-api/migrations/001_init.sql +35 -0
- package/apps/rental-api/migrations/002_videos.sql +10 -0
- package/apps/rental-api/migrations/003_add_gateway_subref.sql +4 -0
- package/apps/rental-api/migrations/004_update_gateways.sql +4 -0
- package/apps/rental-api/migrations/005_seed_demo_video.sql +5 -0
- package/apps/rental-api/package-lock.json +2045 -0
- package/apps/rental-api/package.json +33 -0
- package/apps/rental-api/scripts/run-migration.js +42 -0
- package/apps/rental-api/scripts/update-video-currency.js +21 -0
- package/apps/rental-api/scripts/update-video-price.js +19 -0
- package/apps/rental-api/src/config.ts +14 -0
- package/apps/rental-api/src/db.ts +10 -0
- package/apps/rental-api/src/routes/cashfree.ts +167 -0
- package/apps/rental-api/src/routes/pesapal.ts +92 -0
- package/apps/rental-api/src/routes/rentals.ts +242 -0
- package/apps/rental-api/src/routes/webhooks.ts +73 -0
- package/apps/rental-api/src/server.ts +41 -0
- package/apps/rental-api/src/services/entitlements.ts +45 -0
- package/apps/rental-api/src/services/payments.ts +22 -0
- package/apps/rental-api/tsconfig.json +17 -0
- package/check-urls.ps1 +74 -0
- package/comparison-report.md +181 -0
- package/docs/PAYWALL.md +95 -0
- package/docs/PLAYER_UI_VISIBILITY.md +431 -0
- package/docs/README.md +7 -0
- package/docs/SYSTEM_ARCHITECTURE.md +612 -0
- package/docs/VDOCIPHER_CLONE_REQUIREMENTS.md +403 -0
- package/examples/android/JavaSampleApp/MainActivity.java +641 -0
- package/examples/android/JavaSampleApp/activity_main.xml +226 -0
- package/examples/android/SampleApp/MainActivity.kt +430 -0
- package/examples/ios/SampleApp/ViewController.swift +337 -0
- package/examples/ios/SwiftUISampleApp/ContentView.swift +304 -0
- package/iOS_IMPLEMENTATION_OPTIONS.md +470 -0
- package/ios/UnifiedVideoPlayer/UnifiedVideoPlayer.podspec +33 -0
- package/jest.config.js +33 -0
- package/jitpack.yml +5 -0
- package/lerna.json +35 -0
- package/package.json +69 -0
- package/packages/PLATFORM_STATUS.md +163 -0
- package/packages/android/build.gradle +135 -0
- package/packages/android/src/main/AndroidManifest.xml +36 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/PlayerConfiguration.java +221 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/UnifiedVideoPlayer.java +1037 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/UnifiedVideoPlayer.kt +707 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/analytics/AnalyticsProvider.java +9 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/cast/CastManager.java +141 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/cast/CastOptionsProvider.java +29 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/overlay/WatermarkOverlayView.java +88 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/pip/PipActionReceiver.java +33 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/services/PlaybackService.java +110 -0
- package/packages/android/src/main/java/com/unifiedvideo/player/services/PlayerHolder.java +19 -0
- package/packages/core/package.json +34 -0
- package/packages/core/src/BasePlayer.ts +250 -0
- package/packages/core/src/VideoPlayer.ts +237 -0
- package/packages/core/src/VideoPlayerFactory.ts +145 -0
- package/packages/core/src/index.ts +20 -0
- package/packages/core/src/interfaces/IVideoPlayer.ts +184 -0
- package/packages/core/src/interfaces.ts +240 -0
- package/packages/core/src/utils/EventEmitter.ts +66 -0
- package/packages/core/src/utils/PlatformDetector.ts +300 -0
- package/packages/core/tsconfig.json +20 -0
- package/packages/enact/package.json +51 -0
- package/packages/enact/src/VideoPlayer.js +365 -0
- package/packages/enact/src/adapters/TizenAdapter.js +354 -0
- package/packages/enact/src/index.js +82 -0
- package/packages/ios/BUILD_INSTRUCTIONS.md +108 -0
- package/packages/ios/FIX_EMBED_ISSUE.md +142 -0
- package/packages/ios/GETTING_STARTED.md +100 -0
- package/packages/ios/Package.swift +35 -0
- package/packages/ios/README.md +84 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/Analytics/AnalyticsEmitter.swift +26 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/DRM/FairPlayDRMManager.swift +102 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/Info.plist +24 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/Remote/RemoteCommandCenter.swift +109 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/UnifiedVideoPlayer.swift +811 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/UnifiedVideoPlayerView.swift +640 -0
- package/packages/ios/Sources/UnifiedVideoPlayer/Utilities/Color+Hex.swift +36 -0
- package/packages/ios/UnifiedVideoPlayer.podspec +27 -0
- package/packages/ios/UnifiedVideoPlayer.xcodeproj/project.pbxproj +385 -0
- package/packages/ios/build_framework.sh +55 -0
- package/packages/react-native/android/src/main/java/com/unifiedvideo/UnifiedVideoPlayerModule.kt +482 -0
- package/packages/react-native/ios/UnifiedVideoPlayer.swift +436 -0
- package/packages/react-native/package.json +51 -0
- package/packages/react-native/src/ReactNativePlayer.tsx +423 -0
- package/packages/react-native/src/VideoPlayer.tsx +224 -0
- package/packages/react-native/src/index.ts +28 -0
- package/packages/react-native/src/utils/EventEmitter.ts +66 -0
- package/packages/react-native/tsconfig.json +31 -0
- package/packages/roku/components/UnifiedVideoPlayer.brs +400 -0
- package/packages/roku/package.json +44 -0
- package/packages/roku/source/VideoPlayer.brs +231 -0
- package/packages/roku/source/main.brs +28 -0
- package/packages/web/GETTING_STARTED.md +292 -0
- package/packages/web/jest.config.js +28 -0
- package/packages/web/jest.setup.ts +110 -0
- package/packages/web/package.json +50 -0
- package/packages/web/src/SecureVideoPlayer.ts +1164 -0
- package/packages/web/src/WebPlayer.ts +3110 -0
- package/packages/web/src/__tests__/WebPlayer.test.ts +314 -0
- package/packages/web/src/index.ts +14 -0
- package/packages/web/src/paywall/PaywallController.ts +215 -0
- package/packages/web/src/react/WebPlayerView.tsx +177 -0
- package/packages/web/tsconfig.json +23 -0
- package/packages/web/webpack.config.js +45 -0
- package/server.js +131 -0
- package/server.py +84 -0
- package/test-urls.ps1 +97 -0
- package/test-video-urls.ps1 +87 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
# VdoCipher Clone - System Architecture
|
|
2
|
+
|
|
3
|
+
## High-Level Architecture Overview
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
┌─────────────────────────────────────────────────────────────────────┐
|
|
7
|
+
│ Client Applications │
|
|
8
|
+
├──────────────┬──────────────┬──────────────┬───────────────────────┤
|
|
9
|
+
│ Web │ iOS/Android │ Smart TV │ OTT Devices │
|
|
10
|
+
│ (React) │ (Native) │ (Tizen/webOS)│ (Roku/FireTV) │
|
|
11
|
+
└──────┬───────┴──────┬───────┴──────┬───────┴──────┬────────────────┘
|
|
12
|
+
│ │ │ │
|
|
13
|
+
└──────────────┴──────────────┴──────────────┘
|
|
14
|
+
│
|
|
15
|
+
┌────────▼────────┐
|
|
16
|
+
│ CDN Layer │
|
|
17
|
+
│ (CloudFront) │
|
|
18
|
+
└────────┬────────┘
|
|
19
|
+
│
|
|
20
|
+
┌────────────────────┼────────────────────┐
|
|
21
|
+
│ │ │
|
|
22
|
+
┌───────▼────────┐ ┌────────▼────────┐ ┌───────▼────────┐
|
|
23
|
+
│ API Gateway │ │ Video Delivery │ │ DRM License │
|
|
24
|
+
│ (Kong/AWS) │ │ (HLS/DASH) │ │ Server │
|
|
25
|
+
└───────┬────────┘ └────────┬────────┘ └───────┬────────┘
|
|
26
|
+
│ │ │
|
|
27
|
+
┌───────▼────────────────────▼────────────────────▼────────┐
|
|
28
|
+
│ Microservices Layer │
|
|
29
|
+
├────────────┬───────────┬──────────┬───────────┬─────────┤
|
|
30
|
+
│ Auth │ Video │ Analytics│ Billing │ Admin │
|
|
31
|
+
│ Service │ Processing│ Service │ Service │ Service │
|
|
32
|
+
└────────────┴───────────┴──────────┴───────────┴─────────┘
|
|
33
|
+
│
|
|
34
|
+
┌────────────────────────────▼──────────────────────────────┐
|
|
35
|
+
│ Data Layer │
|
|
36
|
+
├──────────────┬──────────────┬──────────────┬─────────────┤
|
|
37
|
+
│ PostgreSQL │ Redis │ ClickHouse │ S3 │
|
|
38
|
+
│ (Metadata) │ (Cache) │ (Analytics) │ (Storage) │
|
|
39
|
+
└──────────────┴──────────────┴──────────────┴─────────────┘
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Component Architecture
|
|
43
|
+
|
|
44
|
+
### 1. Client SDKs Architecture
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Core Player Interface
|
|
48
|
+
interface VdoCipherPlayer {
|
|
49
|
+
// Initialization
|
|
50
|
+
init(config: PlayerConfig): Promise<void>;
|
|
51
|
+
|
|
52
|
+
// Playback Control
|
|
53
|
+
load(videoId: string, otp: string): Promise<void>;
|
|
54
|
+
play(): void;
|
|
55
|
+
pause(): void;
|
|
56
|
+
seek(time: number): void;
|
|
57
|
+
|
|
58
|
+
// DRM
|
|
59
|
+
configureDRM(license: DRMConfig): void;
|
|
60
|
+
|
|
61
|
+
// Analytics
|
|
62
|
+
trackEvent(event: AnalyticsEvent): void;
|
|
63
|
+
|
|
64
|
+
// Watermarking
|
|
65
|
+
setWatermark(config: WatermarkConfig): void;
|
|
66
|
+
|
|
67
|
+
// Events
|
|
68
|
+
on(event: string, handler: Function): void;
|
|
69
|
+
off(event: string, handler: Function): void;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 2. Backend Services Architecture
|
|
74
|
+
|
|
75
|
+
#### 2.1 Authentication Service
|
|
76
|
+
```yaml
|
|
77
|
+
Service: auth-service
|
|
78
|
+
Technology: Node.js + Express
|
|
79
|
+
Database: PostgreSQL + Redis
|
|
80
|
+
Features:
|
|
81
|
+
- JWT token generation
|
|
82
|
+
- OAuth 2.0 support
|
|
83
|
+
- SSO integration
|
|
84
|
+
- API key management
|
|
85
|
+
- Session management
|
|
86
|
+
|
|
87
|
+
Endpoints:
|
|
88
|
+
POST /auth/login
|
|
89
|
+
POST /auth/refresh
|
|
90
|
+
POST /auth/logout
|
|
91
|
+
GET /auth/verify
|
|
92
|
+
POST /auth/otp/generate
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### 2.2 Video Processing Service
|
|
96
|
+
```yaml
|
|
97
|
+
Service: video-processor
|
|
98
|
+
Technology: Python + FFmpeg + Celery
|
|
99
|
+
Storage: S3 + CloudFront
|
|
100
|
+
Queue: RabbitMQ
|
|
101
|
+
|
|
102
|
+
Pipeline:
|
|
103
|
+
1. Upload Handler
|
|
104
|
+
- Chunked upload support
|
|
105
|
+
- Resume capability
|
|
106
|
+
- Virus scanning
|
|
107
|
+
|
|
108
|
+
2. Transcoding Pipeline
|
|
109
|
+
- Multi-resolution encoding
|
|
110
|
+
- Adaptive bitrate variants
|
|
111
|
+
- Thumbnail generation
|
|
112
|
+
- Subtitle extraction
|
|
113
|
+
|
|
114
|
+
3. DRM Packaging
|
|
115
|
+
- Widevine encryption
|
|
116
|
+
- FairPlay packaging
|
|
117
|
+
- PlayReady support
|
|
118
|
+
|
|
119
|
+
4. CDN Distribution
|
|
120
|
+
- S3 upload
|
|
121
|
+
- CloudFront invalidation
|
|
122
|
+
- Multi-region replication
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### 2.3 DRM License Service
|
|
126
|
+
```yaml
|
|
127
|
+
Service: drm-license-server
|
|
128
|
+
Technology: Node.js + Express
|
|
129
|
+
Providers:
|
|
130
|
+
- Widevine (Google)
|
|
131
|
+
- FairPlay (Apple)
|
|
132
|
+
- PlayReady (Microsoft)
|
|
133
|
+
|
|
134
|
+
Flow:
|
|
135
|
+
1. Client requests license with token
|
|
136
|
+
2. Validate token and permissions
|
|
137
|
+
3. Check device limits
|
|
138
|
+
4. Generate license with restrictions
|
|
139
|
+
5. Return encrypted license
|
|
140
|
+
6. Log license issuance
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### 2.4 Analytics Service
|
|
144
|
+
```yaml
|
|
145
|
+
Service: analytics-engine
|
|
146
|
+
Technology: Node.js + Kafka + ClickHouse
|
|
147
|
+
Processing: Apache Spark
|
|
148
|
+
|
|
149
|
+
Data Pipeline:
|
|
150
|
+
1. Event Collection
|
|
151
|
+
- Client SDK events
|
|
152
|
+
- Server-side events
|
|
153
|
+
- CDN logs
|
|
154
|
+
|
|
155
|
+
2. Real-time Processing
|
|
156
|
+
- Kafka streams
|
|
157
|
+
- Event aggregation
|
|
158
|
+
- Anomaly detection
|
|
159
|
+
|
|
160
|
+
3. Storage
|
|
161
|
+
- ClickHouse for time-series
|
|
162
|
+
- PostgreSQL for metadata
|
|
163
|
+
- S3 for raw logs
|
|
164
|
+
|
|
165
|
+
4. Reporting
|
|
166
|
+
- Real-time dashboards
|
|
167
|
+
- Historical analysis
|
|
168
|
+
- Custom reports
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 3. Database Schema
|
|
172
|
+
|
|
173
|
+
#### 3.1 Core Tables
|
|
174
|
+
```sql
|
|
175
|
+
-- Users table
|
|
176
|
+
CREATE TABLE users (
|
|
177
|
+
id UUID PRIMARY KEY,
|
|
178
|
+
email VARCHAR(255) UNIQUE NOT NULL,
|
|
179
|
+
password_hash VARCHAR(255),
|
|
180
|
+
role VARCHAR(50),
|
|
181
|
+
subscription_id UUID,
|
|
182
|
+
created_at TIMESTAMP,
|
|
183
|
+
updated_at TIMESTAMP
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
-- Videos table
|
|
187
|
+
CREATE TABLE videos (
|
|
188
|
+
id UUID PRIMARY KEY,
|
|
189
|
+
title VARCHAR(500),
|
|
190
|
+
description TEXT,
|
|
191
|
+
duration INTEGER,
|
|
192
|
+
status VARCHAR(50), -- processing, ready, error
|
|
193
|
+
drm_enabled BOOLEAN,
|
|
194
|
+
watermark_config JSONB,
|
|
195
|
+
metadata JSONB,
|
|
196
|
+
created_by UUID REFERENCES users(id),
|
|
197
|
+
created_at TIMESTAMP,
|
|
198
|
+
updated_at TIMESTAMP
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
-- Video Variants table
|
|
202
|
+
CREATE TABLE video_variants (
|
|
203
|
+
id UUID PRIMARY KEY,
|
|
204
|
+
video_id UUID REFERENCES videos(id),
|
|
205
|
+
resolution VARCHAR(20), -- 240p, 480p, 720p, 1080p
|
|
206
|
+
bitrate INTEGER,
|
|
207
|
+
codec VARCHAR(50),
|
|
208
|
+
file_url TEXT,
|
|
209
|
+
file_size BIGINT,
|
|
210
|
+
created_at TIMESTAMP
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
-- Playback Sessions table
|
|
214
|
+
CREATE TABLE playback_sessions (
|
|
215
|
+
id UUID PRIMARY KEY,
|
|
216
|
+
video_id UUID REFERENCES videos(id),
|
|
217
|
+
user_id UUID REFERENCES users(id),
|
|
218
|
+
otp VARCHAR(100),
|
|
219
|
+
ip_address INET,
|
|
220
|
+
user_agent TEXT,
|
|
221
|
+
started_at TIMESTAMP,
|
|
222
|
+
ended_at TIMESTAMP,
|
|
223
|
+
watch_duration INTEGER,
|
|
224
|
+
events JSONB
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
-- DRM Licenses table
|
|
228
|
+
CREATE TABLE drm_licenses (
|
|
229
|
+
id UUID PRIMARY KEY,
|
|
230
|
+
video_id UUID REFERENCES videos(id),
|
|
231
|
+
user_id UUID REFERENCES users(id),
|
|
232
|
+
device_id VARCHAR(255),
|
|
233
|
+
license_type VARCHAR(50), -- widevine, fairplay, playready
|
|
234
|
+
issued_at TIMESTAMP,
|
|
235
|
+
expires_at TIMESTAMP,
|
|
236
|
+
restrictions JSONB
|
|
237
|
+
);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### 4. Security Architecture
|
|
241
|
+
|
|
242
|
+
#### 4.1 Video Security Layers
|
|
243
|
+
```
|
|
244
|
+
┌─────────────────────────────────────────┐
|
|
245
|
+
│ Application Layer │
|
|
246
|
+
│ - JWT Authentication │
|
|
247
|
+
│ - API Rate Limiting │
|
|
248
|
+
│ - CORS Policies │
|
|
249
|
+
├─────────────────────────────────────────┤
|
|
250
|
+
│ Content Protection │
|
|
251
|
+
│ - DRM Encryption │
|
|
252
|
+
│ - Dynamic Watermarking │
|
|
253
|
+
│ - Screen Recording Block │
|
|
254
|
+
├─────────────────────────────────────────┤
|
|
255
|
+
│ Network Security │
|
|
256
|
+
│ - HTTPS/TLS 1.3 │
|
|
257
|
+
│ - Signed URLs │
|
|
258
|
+
│ - IP Whitelisting │
|
|
259
|
+
├─────────────────────────────────────────┤
|
|
260
|
+
│ Infrastructure Security │
|
|
261
|
+
│ - VPC Isolation │
|
|
262
|
+
│ - Security Groups │
|
|
263
|
+
│ - WAF Rules │
|
|
264
|
+
└─────────────────────────────────────────┘
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### 4.2 Token-Based Access Flow
|
|
268
|
+
```
|
|
269
|
+
Client API Gateway Auth Service Video Service
|
|
270
|
+
│ │ │ │
|
|
271
|
+
├──Login Request───────▶│ │ │
|
|
272
|
+
│ ├──Validate─────────────▶│ │
|
|
273
|
+
│ │ ├─Generate JWT/OTP────▶│
|
|
274
|
+
│◀──JWT + OTP───────────┤◀──────────────────────┤ │
|
|
275
|
+
│ │ │ │
|
|
276
|
+
├──Play Video + OTP────▶│ │ │
|
|
277
|
+
│ ├──Verify OTP───────────────────────────────▶│
|
|
278
|
+
│ │ │ ├─Generate Signed URL
|
|
279
|
+
│◀──Video URL───────────┤◀──────────────────────────────────────────┤
|
|
280
|
+
│ │ │ │
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### 5. Watermarking Implementation
|
|
284
|
+
|
|
285
|
+
#### 5.1 Client-Side Watermarking
|
|
286
|
+
```javascript
|
|
287
|
+
class DynamicWatermark {
|
|
288
|
+
constructor(player, config) {
|
|
289
|
+
this.player = player;
|
|
290
|
+
this.config = config;
|
|
291
|
+
this.canvas = document.createElement('canvas');
|
|
292
|
+
this.ctx = this.canvas.getContext('2d');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
render() {
|
|
296
|
+
// Position calculation
|
|
297
|
+
const position = this.calculatePosition();
|
|
298
|
+
|
|
299
|
+
// Draw watermark
|
|
300
|
+
this.ctx.fillStyle = `rgba(255,255,255,${this.config.opacity})`;
|
|
301
|
+
this.ctx.font = `${this.config.fontSize}px Arial`;
|
|
302
|
+
this.ctx.fillText(this.config.text, position.x, position.y);
|
|
303
|
+
|
|
304
|
+
// Apply to video
|
|
305
|
+
this.overlay();
|
|
306
|
+
|
|
307
|
+
// Schedule next position change
|
|
308
|
+
if (this.config.moving) {
|
|
309
|
+
setTimeout(() => this.render(), this.config.interval);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
calculatePosition() {
|
|
314
|
+
// Random or fixed position based on config
|
|
315
|
+
if (this.config.random) {
|
|
316
|
+
return {
|
|
317
|
+
x: Math.random() * this.canvas.width,
|
|
318
|
+
y: Math.random() * this.canvas.height
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
return this.config.position;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
#### 5.2 Server-Side Watermarking
|
|
327
|
+
```python
|
|
328
|
+
import ffmpeg
|
|
329
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
330
|
+
|
|
331
|
+
class ServerWatermark:
|
|
332
|
+
def add_watermark(self, video_path, watermark_text, user_info):
|
|
333
|
+
"""Add forensic watermark to video"""
|
|
334
|
+
|
|
335
|
+
# Create watermark image
|
|
336
|
+
watermark = self.create_watermark_image(
|
|
337
|
+
text=f"{watermark_text}\n{user_info['email']}\n{user_info['ip']}",
|
|
338
|
+
size=(300, 100),
|
|
339
|
+
opacity=0.3
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
# Apply watermark using FFmpeg
|
|
343
|
+
output = ffmpeg.input(video_path).overlay(
|
|
344
|
+
ffmpeg.input(watermark),
|
|
345
|
+
x='random(0,W-w)', # Random X position
|
|
346
|
+
y='random(0,H-h)', # Random Y position
|
|
347
|
+
enable=f'lt(mod(t,10),5)' # Show for 5 seconds every 10 seconds
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
return output.output('watermarked.mp4').run()
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### 6. Analytics Architecture
|
|
354
|
+
|
|
355
|
+
#### 6.1 Event Collection Schema
|
|
356
|
+
```typescript
|
|
357
|
+
interface VideoAnalyticsEvent {
|
|
358
|
+
// Event metadata
|
|
359
|
+
eventId: string;
|
|
360
|
+
timestamp: number;
|
|
361
|
+
sessionId: string;
|
|
362
|
+
|
|
363
|
+
// User info
|
|
364
|
+
userId: string;
|
|
365
|
+
deviceId: string;
|
|
366
|
+
|
|
367
|
+
// Video info
|
|
368
|
+
videoId: string;
|
|
369
|
+
videoTitle: string;
|
|
370
|
+
|
|
371
|
+
// Event details
|
|
372
|
+
eventType: 'play' | 'pause' | 'seek' | 'end' | 'error' | 'quality_change';
|
|
373
|
+
eventData: {
|
|
374
|
+
currentTime?: number;
|
|
375
|
+
duration?: number;
|
|
376
|
+
seekFrom?: number;
|
|
377
|
+
seekTo?: number;
|
|
378
|
+
quality?: string;
|
|
379
|
+
bandwidth?: number;
|
|
380
|
+
bufferLength?: number;
|
|
381
|
+
droppedFrames?: number;
|
|
382
|
+
errorCode?: string;
|
|
383
|
+
errorMessage?: string;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// Context
|
|
387
|
+
context: {
|
|
388
|
+
userAgent: string;
|
|
389
|
+
platform: string;
|
|
390
|
+
browser?: string;
|
|
391
|
+
os: string;
|
|
392
|
+
ip: string;
|
|
393
|
+
country?: string;
|
|
394
|
+
isp?: string;
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
#### 6.2 Real-time Analytics Pipeline
|
|
400
|
+
```yaml
|
|
401
|
+
Pipeline:
|
|
402
|
+
1. Event Ingestion:
|
|
403
|
+
- SDK sends events to API
|
|
404
|
+
- API Gateway validates
|
|
405
|
+
- Push to Kafka topic
|
|
406
|
+
|
|
407
|
+
2. Stream Processing:
|
|
408
|
+
- Kafka Streams aggregation
|
|
409
|
+
- Calculate metrics:
|
|
410
|
+
* Concurrent viewers
|
|
411
|
+
* Average watch time
|
|
412
|
+
* Buffer ratio
|
|
413
|
+
* Error rate
|
|
414
|
+
|
|
415
|
+
3. Storage:
|
|
416
|
+
- ClickHouse for time-series
|
|
417
|
+
- Redis for real-time counters
|
|
418
|
+
- S3 for raw events
|
|
419
|
+
|
|
420
|
+
4. Visualization:
|
|
421
|
+
- WebSocket for real-time updates
|
|
422
|
+
- Grafana dashboards
|
|
423
|
+
- Custom React dashboard
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### 7. Infrastructure as Code
|
|
427
|
+
|
|
428
|
+
#### 7.1 Kubernetes Deployment
|
|
429
|
+
```yaml
|
|
430
|
+
apiVersion: apps/v1
|
|
431
|
+
kind: Deployment
|
|
432
|
+
metadata:
|
|
433
|
+
name: video-api-deployment
|
|
434
|
+
spec:
|
|
435
|
+
replicas: 3
|
|
436
|
+
selector:
|
|
437
|
+
matchLabels:
|
|
438
|
+
app: video-api
|
|
439
|
+
template:
|
|
440
|
+
metadata:
|
|
441
|
+
labels:
|
|
442
|
+
app: video-api
|
|
443
|
+
spec:
|
|
444
|
+
containers:
|
|
445
|
+
- name: api
|
|
446
|
+
image: vdocipher-clone/api:latest
|
|
447
|
+
ports:
|
|
448
|
+
- containerPort: 3000
|
|
449
|
+
env:
|
|
450
|
+
- name: DATABASE_URL
|
|
451
|
+
valueFrom:
|
|
452
|
+
secretKeyRef:
|
|
453
|
+
name: db-secret
|
|
454
|
+
key: url
|
|
455
|
+
- name: REDIS_URL
|
|
456
|
+
valueFrom:
|
|
457
|
+
secretKeyRef:
|
|
458
|
+
name: redis-secret
|
|
459
|
+
key: url
|
|
460
|
+
resources:
|
|
461
|
+
requests:
|
|
462
|
+
memory: "256Mi"
|
|
463
|
+
cpu: "250m"
|
|
464
|
+
limits:
|
|
465
|
+
memory: "512Mi"
|
|
466
|
+
cpu: "500m"
|
|
467
|
+
---
|
|
468
|
+
apiVersion: v1
|
|
469
|
+
kind: Service
|
|
470
|
+
metadata:
|
|
471
|
+
name: video-api-service
|
|
472
|
+
spec:
|
|
473
|
+
selector:
|
|
474
|
+
app: video-api
|
|
475
|
+
ports:
|
|
476
|
+
- protocol: TCP
|
|
477
|
+
port: 80
|
|
478
|
+
targetPort: 3000
|
|
479
|
+
type: LoadBalancer
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
#### 7.2 Auto-scaling Configuration
|
|
483
|
+
```yaml
|
|
484
|
+
apiVersion: autoscaling/v2
|
|
485
|
+
kind: HorizontalPodAutoscaler
|
|
486
|
+
metadata:
|
|
487
|
+
name: video-api-hpa
|
|
488
|
+
spec:
|
|
489
|
+
scaleTargetRef:
|
|
490
|
+
apiVersion: apps/v1
|
|
491
|
+
kind: Deployment
|
|
492
|
+
name: video-api-deployment
|
|
493
|
+
minReplicas: 3
|
|
494
|
+
maxReplicas: 20
|
|
495
|
+
metrics:
|
|
496
|
+
- type: Resource
|
|
497
|
+
resource:
|
|
498
|
+
name: cpu
|
|
499
|
+
target:
|
|
500
|
+
type: Utilization
|
|
501
|
+
averageUtilization: 70
|
|
502
|
+
- type: Resource
|
|
503
|
+
resource:
|
|
504
|
+
name: memory
|
|
505
|
+
target:
|
|
506
|
+
type: Utilization
|
|
507
|
+
averageUtilization: 80
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### 8. Monitoring & Observability
|
|
511
|
+
|
|
512
|
+
#### 8.1 Metrics Collection
|
|
513
|
+
```yaml
|
|
514
|
+
Metrics:
|
|
515
|
+
Application:
|
|
516
|
+
- API response times
|
|
517
|
+
- Request throughput
|
|
518
|
+
- Error rates
|
|
519
|
+
- Active sessions
|
|
520
|
+
|
|
521
|
+
Video Streaming:
|
|
522
|
+
- Buffering ratio
|
|
523
|
+
- Startup time
|
|
524
|
+
- Bitrate switches
|
|
525
|
+
- CDN cache hit ratio
|
|
526
|
+
|
|
527
|
+
Infrastructure:
|
|
528
|
+
- CPU/Memory usage
|
|
529
|
+
- Network I/O
|
|
530
|
+
- Disk usage
|
|
531
|
+
- Database connections
|
|
532
|
+
|
|
533
|
+
Business:
|
|
534
|
+
- User engagement
|
|
535
|
+
- Video completion rate
|
|
536
|
+
- Revenue metrics
|
|
537
|
+
- License issuance
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### 8.2 Alerting Rules
|
|
541
|
+
```yaml
|
|
542
|
+
Alerts:
|
|
543
|
+
Critical:
|
|
544
|
+
- API error rate > 5%
|
|
545
|
+
- Database connection pool exhausted
|
|
546
|
+
- DRM license server down
|
|
547
|
+
- CDN origin errors > 1%
|
|
548
|
+
|
|
549
|
+
Warning:
|
|
550
|
+
- API p95 latency > 500ms
|
|
551
|
+
- Buffering ratio > 2%
|
|
552
|
+
- Disk usage > 80%
|
|
553
|
+
- Concurrent viewers > 80% capacity
|
|
554
|
+
|
|
555
|
+
Info:
|
|
556
|
+
- New user registration
|
|
557
|
+
- Large video upload completed
|
|
558
|
+
- Scheduled maintenance reminder
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
## Deployment Strategy
|
|
562
|
+
|
|
563
|
+
### Phase 1: Development Environment
|
|
564
|
+
- Docker Compose setup
|
|
565
|
+
- Local development tools
|
|
566
|
+
- Mock services for testing
|
|
567
|
+
|
|
568
|
+
### Phase 2: Staging Environment
|
|
569
|
+
- Kubernetes cluster (EKS/GKE)
|
|
570
|
+
- Full service deployment
|
|
571
|
+
- Load testing setup
|
|
572
|
+
- Security scanning
|
|
573
|
+
|
|
574
|
+
### Phase 3: Production Deployment
|
|
575
|
+
- Multi-region setup
|
|
576
|
+
- Blue-green deployment
|
|
577
|
+
- Database replication
|
|
578
|
+
- CDN configuration
|
|
579
|
+
- Monitoring setup
|
|
580
|
+
|
|
581
|
+
### Phase 4: Scaling & Optimization
|
|
582
|
+
- Auto-scaling policies
|
|
583
|
+
- Performance tuning
|
|
584
|
+
- Cost optimization
|
|
585
|
+
- Disaster recovery
|
|
586
|
+
|
|
587
|
+
## Technology Stack Summary
|
|
588
|
+
|
|
589
|
+
### Frontend
|
|
590
|
+
- **Web Player**: Video.js/Shaka Player + Custom UI
|
|
591
|
+
- **Admin Dashboard**: React + TypeScript + Material-UI
|
|
592
|
+
- **Mobile SDKs**: Swift (iOS), Kotlin/Java (Android)
|
|
593
|
+
- **TV Apps**: JavaScript (Tizen/webOS), BrightScript (Roku)
|
|
594
|
+
|
|
595
|
+
### Backend
|
|
596
|
+
- **API Layer**: Node.js + Express + GraphQL
|
|
597
|
+
- **Microservices**: Node.js, Python, Go
|
|
598
|
+
- **Message Queue**: Kafka, RabbitMQ
|
|
599
|
+
- **Cache**: Redis, Memcached
|
|
600
|
+
|
|
601
|
+
### Data
|
|
602
|
+
- **Primary DB**: PostgreSQL
|
|
603
|
+
- **Analytics DB**: ClickHouse
|
|
604
|
+
- **Search**: Elasticsearch
|
|
605
|
+
- **Object Storage**: AWS S3
|
|
606
|
+
|
|
607
|
+
### Infrastructure
|
|
608
|
+
- **Container**: Docker
|
|
609
|
+
- **Orchestration**: Kubernetes
|
|
610
|
+
- **CI/CD**: GitLab CI / GitHub Actions
|
|
611
|
+
- **Monitoring**: Prometheus + Grafana
|
|
612
|
+
- **Logging**: ELK Stack
|