mediaflow-proxy 2.4.2__tar.gz → 2.4.4__tar.gz
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.
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/.gitignore +5 -1
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/PKG-INFO +205 -4
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/README.md +201 -1
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/configs.py +21 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/drm/decrypter.py +65 -7
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/base.py +2 -2
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/dlhd.py +316 -94
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/filelions.py +1 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/gupload.py +1 -1
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/streamwish.py +1 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/handlers.py +367 -39
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/main.py +48 -20
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/mpd_processor.py +209 -37
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/__init__.py +18 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/audio_transcoder.py +351 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/codec_utils.py +515 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/container_probe.py +614 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/ebml_parser.py +1228 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/hls_manifest.py +151 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/media_source.py +236 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/mkv_demuxer.py +469 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/mp4_muxer.py +1376 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/mp4_parser.py +834 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/pyav_demuxer.py +608 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/transcode_handler.py +1121 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/transcode_pipeline.py +1268 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/ts_muxer.py +1728 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/remuxer/video_transcoder.py +403 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/routes/__init__.py +43 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/acestream.py +94 -5
- mediaflow_proxy-2.4.4/mediaflow_proxy/routes/extractor.py +258 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/playlist_builder.py +42 -47
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/proxy.py +256 -5
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/telegram.py +311 -10
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/xtream.py +169 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/schemas.py +8 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/index.html +9 -1
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/url_generator.html +337 -14
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/acestream.py +44 -64
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/base_prebuffer.py +66 -66
- mediaflow_proxy-2.4.4/mediaflow_proxy/utils/cache_utils.py +257 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/dash_prebuffer.py +24 -4
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/extractor_helpers.py +11 -2
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/http_utils.py +23 -5
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/m3u8_processor.py +36 -21
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/mpd_utils.py +120 -20
- mediaflow_proxy-2.4.4/mediaflow_proxy/utils/rate_limit_handlers.py +204 -0
- mediaflow_proxy-2.4.4/mediaflow_proxy/utils/redis_utils.py +861 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/stream_transformers.py +9 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/telegram.py +334 -39
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/pyproject.toml +5 -4
- mediaflow_proxy-2.4.2/mediaflow_proxy/routes/__init__.py +0 -17
- mediaflow_proxy-2.4.2/mediaflow_proxy/routes/extractor.py +0 -99
- mediaflow_proxy-2.4.2/mediaflow_proxy/utils/cache_utils.py +0 -653
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/LICENSE +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/__init__.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/const.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/drm/__init__.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/F16Px.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/__init__.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/doodstream.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/factory.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/fastream.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/filemoon.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/livetv.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/lulustream.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/maxstream.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/mixdrop.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/okru.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/sportsonline.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/streamtape.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/supervideo.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/turbovidplay.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/uqload.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/vavoo.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/vidmoly.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/vidoza.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/vixcloud.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/extractors/voe.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/middleware.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/routes/speedtest.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/__init__.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/models.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/providers/all_debrid.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/providers/base.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/providers/real_debrid.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/speedtest/service.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/logo.png +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/playlist_builder.html +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/speedtest.html +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/static/speedtest.js +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/__init__.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/aes.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/aesgcm.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/base64_utils.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/codec.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/compat.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/constanttime.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/crypto_utils.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/cryptomath.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/deprecations.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/hls_prebuffer.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/hls_utils.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/http_client.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/packed.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/python_aes.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/python_aesgcm.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/rijndael.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/tlshashlib.py +0 -0
- {mediaflow_proxy-2.4.2 → mediaflow_proxy-2.4.4}/mediaflow_proxy/utils/tlshmac.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mediaflow-proxy
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.4
|
|
4
4
|
Summary: A high-performance proxy server for streaming media, supporting HTTP(S), HLS, and MPEG-DASH with real-time DRM decryption.
|
|
5
5
|
Project-URL: Homepage, https://github.com/mhdzumair/mediaflow-proxy
|
|
6
6
|
Project-URL: Repository, https://github.com/mhdzumair/mediaflow-proxy
|
|
@@ -13,15 +13,15 @@ Classifier: Development Status :: 4 - Beta
|
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: License :: OSI Approved :: MIT License
|
|
15
15
|
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.10
|
|
22
21
|
Requires-Dist: aiofiles
|
|
23
22
|
Requires-Dist: aiohttp
|
|
24
23
|
Requires-Dist: aiohttp-socks
|
|
24
|
+
Requires-Dist: av>=14.0.0
|
|
25
25
|
Requires-Dist: beautifulsoup4
|
|
26
26
|
Requires-Dist: cryptg>=0.4.0
|
|
27
27
|
Requires-Dist: curl-cffi
|
|
@@ -31,6 +31,7 @@ Requires-Dist: lxml
|
|
|
31
31
|
Requires-Dist: psutil
|
|
32
32
|
Requires-Dist: pycryptodome
|
|
33
33
|
Requires-Dist: pydantic-settings
|
|
34
|
+
Requires-Dist: redis[hiredis]>=5.0.0
|
|
34
35
|
Requires-Dist: telethon>=1.42.0
|
|
35
36
|
Requires-Dist: tenacity
|
|
36
37
|
Requires-Dist: tqdm
|
|
@@ -96,6 +97,15 @@ MediaFlow Proxy is a powerful and flexible solution for proxifying various types
|
|
|
96
97
|
- Optional IP-based access control for encrypted URLs
|
|
97
98
|
- URL expiration support for encrypted URLs
|
|
98
99
|
|
|
100
|
+
### On-the-fly Transcoding
|
|
101
|
+
- **Universal video/audio transcoding** to browser-compatible fMP4 (H.264 + AAC)
|
|
102
|
+
- **GPU hardware acceleration** (NVIDIA NVENC, Apple VideoToolbox, Intel VAAPI/QSV) with automatic CPU fallback
|
|
103
|
+
- Supports **any input container** (MKV, MP4, TS, WebM, FLV, etc.) and codec (HEVC, VP8/VP9, MPEG-2, MPEG-4, AC3, EAC3, Vorbis, Opus, etc.)
|
|
104
|
+
- **On-the-fly streaming** -- no full-file buffering; pipe-based demuxing for MKV/TS/WebM and moov-atom probing for MP4
|
|
105
|
+
- **Smart format detection** -- filename extension hints + magic byte sniffing to avoid wasteful probe attempts
|
|
106
|
+
- Available on **all proxy endpoints**: `/proxy/stream`, Telegram, Acestream, and Xtream Codes
|
|
107
|
+
- Triggered by `&transcode=true` query parameter with optional `&start=<seconds>` for seeking
|
|
108
|
+
|
|
99
109
|
### Additional Features
|
|
100
110
|
- Built-in speed test for RealDebrid and AllDebrid services
|
|
101
111
|
- Custom header injection and modification
|
|
@@ -217,6 +227,50 @@ Set the following environment variables:
|
|
|
217
227
|
- `DASH_SEGMENT_CACHE_TTL`: Optional. TTL in seconds for cached DASH segments. Default: `60`. Longer values help with slow network playback.
|
|
218
228
|
- `FORWARDED_ALLOW_IPS`: Optional. Controls which IP addresses are trusted to provide forwarded headers (X-Forwarded-For, X-Forwarded-Proto, etc.) when MediaFlow Proxy is deployed behind reverse proxies or load balancers. Default: `127.0.0.1`. See [Forwarded Headers Configuration](#forwarded-headers-configuration) for detailed usage.
|
|
219
229
|
|
|
230
|
+
### Redis Configuration (Optional)
|
|
231
|
+
|
|
232
|
+
Redis enables cross-worker coordination for rate limiting and caching. This is **recommended** when running with multiple workers (`--workers N`) to prevent CDN rate-limiting issues (e.g., Vidoza 509 errors).
|
|
233
|
+
|
|
234
|
+
- `REDIS_URL`: Optional. Redis connection URL. Default: `None` (disabled). Example: `redis://localhost:6379` or `redis://user:pass@host:6379/0`.
|
|
235
|
+
|
|
236
|
+
**When to use Redis:**
|
|
237
|
+
- Running multiple uvicorn workers (`--workers 4` or more)
|
|
238
|
+
- Streaming from rate-limited CDNs like Vidoza
|
|
239
|
+
- Need shared caching across workers (extractor results, HEAD responses, segments)
|
|
240
|
+
|
|
241
|
+
**Features enabled by Redis:**
|
|
242
|
+
- **Rate limiting**: Prevents rapid-fire requests that trigger CDN 509 errors
|
|
243
|
+
- **HEAD cache**: Serves repeated HEAD probes (e.g., ExoPlayer) without upstream connections
|
|
244
|
+
- **Stream gate**: Serializes initial connections to rate-limited URLs
|
|
245
|
+
- **Extractor cache**: Shares extraction results across all workers
|
|
246
|
+
- **Segment cache**: Shares downloaded segments across workers
|
|
247
|
+
|
|
248
|
+
**Docker Compose example with Redis:**
|
|
249
|
+
```yaml
|
|
250
|
+
services:
|
|
251
|
+
redis:
|
|
252
|
+
image: redis:7-alpine
|
|
253
|
+
restart: unless-stopped
|
|
254
|
+
healthcheck:
|
|
255
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
256
|
+
interval: 10s
|
|
257
|
+
timeout: 5s
|
|
258
|
+
retries: 5
|
|
259
|
+
|
|
260
|
+
mediaflow-proxy:
|
|
261
|
+
image: mhdzumair/mediaflow-proxy:latest
|
|
262
|
+
ports:
|
|
263
|
+
- "8888:8888"
|
|
264
|
+
environment:
|
|
265
|
+
- API_PASSWORD=your_password
|
|
266
|
+
- REDIS_URL=redis://redis:6379
|
|
267
|
+
depends_on:
|
|
268
|
+
redis:
|
|
269
|
+
condition: service_healthy
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**Note**: If Redis is not configured, MediaFlow Proxy works normally but rate limiting features are disabled. This is fine for single-worker deployments or CDNs that don't rate-limit aggressively.
|
|
273
|
+
|
|
220
274
|
### Acestream Configuration
|
|
221
275
|
|
|
222
276
|
MediaFlow Proxy can act as a proxy for Acestream P2P streams, converting them to HLS or MPEG-TS format that any media player can consume.
|
|
@@ -243,6 +297,8 @@ MediaFlow Proxy can act as a proxy for Acestream P2P streams, converting them to
|
|
|
243
297
|
|-----------|-------------|
|
|
244
298
|
| `id` | Acestream content ID (alternative to infohash) |
|
|
245
299
|
| `infohash` | Acestream infohash (40-char hex from magnet link) |
|
|
300
|
+
| `transcode` | Set to `true` to transcode to browser-compatible fMP4 (H.264 + AAC) |
|
|
301
|
+
| `start` | Seek start time in seconds (used with `transcode=true`) |
|
|
246
302
|
|
|
247
303
|
**Example URLs:**
|
|
248
304
|
```
|
|
@@ -252,6 +308,9 @@ https://your-mediaflow/proxy/acestream/stream?id=YOUR_CONTENT_ID&api_password=yo
|
|
|
252
308
|
# MPEG-TS stream (infohash from magnet)
|
|
253
309
|
https://your-mediaflow/proxy/acestream/stream?infohash=b04372b9543d763bd2dbd2a1842d9723fd080076&api_password=your_password
|
|
254
310
|
|
|
311
|
+
# Transcode to browser-compatible fMP4
|
|
312
|
+
https://your-mediaflow/proxy/acestream/stream?id=YOUR_CONTENT_ID&transcode=true&api_password=your_password
|
|
313
|
+
|
|
255
314
|
# HLS manifest (alternative)
|
|
256
315
|
https://your-mediaflow/proxy/acestream/manifest.m3u8?id=YOUR_CONTENT_ID&api_password=your_password
|
|
257
316
|
```
|
|
@@ -324,6 +383,9 @@ TELEGRAM_SESSION_STRING=your_session_string_here
|
|
|
324
383
|
|----------|-------------|
|
|
325
384
|
| `/proxy/telegram/stream` | Stream media from t.me link or file_id |
|
|
326
385
|
| `/proxy/telegram/stream/{filename}` | Stream with custom filename |
|
|
386
|
+
| `/proxy/telegram/transcode/playlist.m3u8` | HLS transcode playlist (recommended for browser playback and smooth seeking) |
|
|
387
|
+
| `/proxy/telegram/transcode/init.mp4` | fMP4 init segment for Telegram transcode playlist |
|
|
388
|
+
| `/proxy/telegram/transcode/segment.m4s` | fMP4 media segment for Telegram transcode playlist |
|
|
327
389
|
| `/proxy/telegram/info` | Get media metadata |
|
|
328
390
|
| `/proxy/telegram/status` | Session status and health check |
|
|
329
391
|
|
|
@@ -336,6 +398,8 @@ TELEGRAM_SESSION_STRING=your_session_string_here
|
|
|
336
398
|
| `message_id` | Message ID within the chat (use with `chat_id`) |
|
|
337
399
|
| `file_id` | Bot API file_id (use with `file_size`) |
|
|
338
400
|
| `file_size` | File size in bytes (required when using `file_id`) |
|
|
401
|
+
| `transcode` | Set to `true` for direct transcode mode on `/proxy/telegram/stream` (URL Generator defaults to `/proxy/telegram/transcode/playlist.m3u8` when no start time is set) |
|
|
402
|
+
| `start` | Seek start time in seconds (direct transcode mode only, used with `transcode=true`) |
|
|
339
403
|
|
|
340
404
|
#### Supported Input Formats
|
|
341
405
|
|
|
@@ -1069,11 +1133,65 @@ Ideal for users who want a reliable, plug-and-play solution without the technica
|
|
|
1069
1133
|
4. `/proxy/mpd/playlist.m3u8`: Generate HLS playlists from MPD
|
|
1070
1134
|
5. `/proxy/mpd/segment.mp4`: Process and decrypt media segments
|
|
1071
1135
|
6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
|
|
1072
|
-
7. `/extractor/video
|
|
1136
|
+
7. `/extractor/video`: Extract direct video stream URLs from supported hosts (see below)
|
|
1073
1137
|
8. `/playlist/builder`: Build and customize playlists from multiple sources
|
|
1138
|
+
9. `/proxy/transcode/playlist.m3u8`: Generate HLS VOD playlist for generic stream transcode
|
|
1139
|
+
10. `/proxy/transcode/init.mp4`: fMP4 init segment for generic transcode playlist
|
|
1140
|
+
11. `/proxy/transcode/segment.m4s`: fMP4 media segment for generic transcode playlist
|
|
1141
|
+
12. `/proxy/telegram/transcode/playlist.m3u8`: Generate HLS VOD playlist for Telegram transcode
|
|
1142
|
+
13. `/proxy/telegram/transcode/init.mp4`: fMP4 init segment for Telegram transcode playlist
|
|
1143
|
+
14. `/proxy/telegram/transcode/segment.m4s`: fMP4 media segment for Telegram transcode playlist
|
|
1074
1144
|
|
|
1075
1145
|
Once the server is running, for more details on the available endpoints and their parameters, visit the Swagger UI at `http://localhost:8888/docs`.
|
|
1076
1146
|
|
|
1147
|
+
### Video Extractor Endpoint
|
|
1148
|
+
|
|
1149
|
+
The extractor endpoint extracts direct video stream URLs from various video hosting services. It supports an optional file extension in the URL for better player compatibility.
|
|
1150
|
+
|
|
1151
|
+
#### Endpoints
|
|
1152
|
+
|
|
1153
|
+
| Endpoint | Description |
|
|
1154
|
+
|----------|-------------|
|
|
1155
|
+
| `/extractor/video` | Base endpoint (generic, backward compatible) |
|
|
1156
|
+
| `/extractor/video.m3u8` | HLS streams - helps ExoPlayer detect HLS |
|
|
1157
|
+
| `/extractor/video.mp4` | MP4 streams |
|
|
1158
|
+
| `/extractor/video.mkv` | MKV streams |
|
|
1159
|
+
| `/extractor/video.ts` | MPEG-TS streams |
|
|
1160
|
+
| `/extractor/video.webm` | WebM streams |
|
|
1161
|
+
| `/extractor/video.avi` | AVI streams |
|
|
1162
|
+
|
|
1163
|
+
#### Why Use Extensions?
|
|
1164
|
+
|
|
1165
|
+
Some video players (notably Android's ExoPlayer used in Stremio) determine the media source type from the URL before making any HTTP requests. Without the correct extension:
|
|
1166
|
+
|
|
1167
|
+
- ExoPlayer sees `/extractor/video?...` → Uses `ProgressiveMediaSource`
|
|
1168
|
+
- ExoPlayer sees `/extractor/video.m3u8?...` → Uses `HlsMediaSource` ✓
|
|
1169
|
+
|
|
1170
|
+
For HLS streams, using the `.m3u8` extension ensures the player uses the correct HLS playback pipeline.
|
|
1171
|
+
|
|
1172
|
+
#### Parameters
|
|
1173
|
+
|
|
1174
|
+
| Parameter | Required | Description |
|
|
1175
|
+
|-----------|----------|-------------|
|
|
1176
|
+
| `host` | Yes | Extractor host name (e.g., `TurboVidPlay`, `Vidoza`) |
|
|
1177
|
+
| `d` | Yes | Destination URL (the video page URL to extract) |
|
|
1178
|
+
| `api_password` | Yes* | API password (*if configured) |
|
|
1179
|
+
| `redirect_stream` | No | If `true`, returns 302 redirect to the proxied stream URL |
|
|
1180
|
+
|
|
1181
|
+
#### Example Usage
|
|
1182
|
+
|
|
1183
|
+
**Get extraction result as JSON:**
|
|
1184
|
+
```
|
|
1185
|
+
GET /extractor/video?host=Vidoza&d=https://videzz.net/example.html&api_password=your_password
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
**Redirect directly to stream (for players):**
|
|
1189
|
+
```
|
|
1190
|
+
GET /extractor/video.m3u8?host=TurboVidPlay&d=https://turbovidhls.com/t/abc123&api_password=your_password&redirect_stream=true
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
This redirects to the proxied HLS manifest URL, and because the request URL contains `.m3u8`, players like ExoPlayer will correctly use HLS playback.
|
|
1194
|
+
|
|
1077
1195
|
### Xtream Codes (XC) API Proxy
|
|
1078
1196
|
|
|
1079
1197
|
MediaFlow Proxy can act as a stateless pass-through proxy for Xtream Codes API, allowing you to proxy streams from XC-compatible IPTV providers through MediaFlow. This is particularly useful for:
|
|
@@ -1254,6 +1372,44 @@ Apply stream content transformations for specific hosting providers.
|
|
|
1254
1372
|
- **Example:** `&transformer=ts_stream&x_headers=content-length,content-range` for streams with PNG wrappers.
|
|
1255
1373
|
- **Note:** This parameter is automatically set when using extractors for supported hosts.
|
|
1256
1374
|
|
|
1375
|
+
**`/proxy/transcode/playlist.m3u8` and `/proxy/telegram/transcode/playlist.m3u8` (recommended)**
|
|
1376
|
+
Use HLS transcode playlists for smooth browser playback and robust seeking with fMP4 segments.
|
|
1377
|
+
- **Usage:** Open the playlist endpoint directly with `d` (or Telegram params), optional `api_password`, and optional `h_*` headers.
|
|
1378
|
+
- **Effect:** Generates an HLS VOD playlist that references `init.mp4` + `segment.m4s` endpoints with browser-compatible H.264/AAC output.
|
|
1379
|
+
- **URL Generator behavior:** When transcode is enabled and no start time is provided, URL Generator outputs these playlist URLs by default.
|
|
1380
|
+
|
|
1381
|
+
**`&transcode=true` (direct mode)**
|
|
1382
|
+
Transcode the stream directly to browser-compatible fragmented MP4 (fMP4) with H.264 video and AAC audio.
|
|
1383
|
+
- **Usage:** Add `&transcode=true` to `/proxy/stream`, `/proxy/telegram/stream`, `/proxy/acestream/stream`, or Xtream Codes live/movie/series stream URLs.
|
|
1384
|
+
- **Effect:** Re-encodes unsupported video codecs (HEVC, VP8/VP9, MPEG-2, MPEG-4, etc.) to H.264 and unsupported audio codecs (AC3, EAC3, Vorbis, Opus, FLAC, DTS, etc.) to AAC. Browser-compatible codecs (H.264 video, AAC audio) are passed through without re-encoding.
|
|
1385
|
+
- **GPU Acceleration:** Automatically uses GPU encoding when available (NVIDIA NVENC, Apple VideoToolbox, Intel VAAPI/QSV). Falls back to CPU (libx264) otherwise.
|
|
1386
|
+
- **On-the-fly:** Streaming is real-time with pipe-based demuxing. For MP4 inputs, the moov atom is probed and rewritten for immediate playback without downloading the full file.
|
|
1387
|
+
|
|
1388
|
+
**`&start=120`**
|
|
1389
|
+
Seek to a specific time position before starting transcoded playback.
|
|
1390
|
+
- **Usage:** Add `&start=120` (value in seconds) alongside `&transcode=true` in direct transcode mode
|
|
1391
|
+
- **Effect:** Starts transcoding from the specified time offset. For indexed containers (MKV cues, MP4 moov), this seeks to the nearest keyframe. For non-indexed formats (TS), this is a byte-estimate seek.
|
|
1392
|
+
- **Supported Endpoints:** `/proxy/stream`, `/proxy/telegram/stream`, `/proxy/acestream/stream`, Xtream Codes live/movie/series endpoints
|
|
1393
|
+
- **Note:** `start` is not used by `/proxy/transcode/playlist.m3u8` or `/proxy/telegram/transcode/playlist.m3u8` endpoints.
|
|
1394
|
+
- **Example:** `&transcode=true&start=300` starts playback from 5 minutes into the stream
|
|
1395
|
+
|
|
1396
|
+
**`&ratelimit=vidoza`**
|
|
1397
|
+
Apply host-specific rate limiting to prevent CDN 509 (Bandwidth Limit Exceeded) errors. Requires Redis to be configured.
|
|
1398
|
+
- **Usage:** Add `&ratelimit=handler_id` to the `/proxy/stream` URL
|
|
1399
|
+
- **Effect:** Limits the frequency of upstream connections to avoid triggering rate limits on aggressive CDNs.
|
|
1400
|
+
- **Auto-detection:** If not specified, rate limiting is automatically applied for known hosts (e.g., Vidoza).
|
|
1401
|
+
- **Available Handlers:**
|
|
1402
|
+
- `vidoza` - 5-second cooldown between connections, HEAD caching, stream gating (auto-detected for vidoza.net)
|
|
1403
|
+
- `aggressive` - 3-second cooldown, suitable for other rate-limited hosts
|
|
1404
|
+
- `none` - Explicitly disable rate limiting (use when auto-detection is unwanted)
|
|
1405
|
+
- **How it works:** When a rate-limited stream is requested:
|
|
1406
|
+
1. HEAD responses are cached to serve repeated probes without upstream connections
|
|
1407
|
+
2. A cooldown period prevents rapid-fire GET requests
|
|
1408
|
+
3. If another request arrives during cooldown, returns `503 Service Unavailable` with `Retry-After` header
|
|
1409
|
+
4. Players automatically retry after the cooldown, resulting in smooth playback
|
|
1410
|
+
- **Requires:** `REDIS_URL` must be configured for rate limiting to function. Without Redis, rate limiting is disabled.
|
|
1411
|
+
- **Example:** `&ratelimit=vidoza` for Vidoza streams, or `&ratelimit=none` to disable auto-detection.
|
|
1412
|
+
|
|
1257
1413
|
**`&rp_content-type=video/mp2t`**
|
|
1258
1414
|
Set response headers that propagate to HLS/DASH segments.
|
|
1259
1415
|
- **Usage:** Add `&rp_header-name=value` to the proxy URL (rp_ prefix)
|
|
@@ -1347,6 +1503,51 @@ mpv "http://localhost:8888/proxy/acestream/manifest.m3u8?id=your_content_id&star
|
|
|
1347
1503
|
|
|
1348
1504
|
**Note:** The `start_offset` parameter is particularly useful for live streams where the prebuffer system cannot prefetch segments when sitting at the live edge. By starting slightly behind (e.g., `-18` seconds), there are future segments available for prebuffering, resulting in smoother playback. This works for both native HLS and DASH/MPD streams converted to HLS.
|
|
1349
1505
|
|
|
1506
|
+
#### Transcode Stream for Browser Playback
|
|
1507
|
+
|
|
1508
|
+
```bash
|
|
1509
|
+
# Recommended: HLS transcode playlist for generic streams
|
|
1510
|
+
mpv "http://localhost:8888/proxy/transcode/playlist.m3u8?d=https://example.com/video.mkv&api_password=your_password"
|
|
1511
|
+
|
|
1512
|
+
# Recommended: HLS transcode playlist for Telegram streams
|
|
1513
|
+
mpv "http://localhost:8888/proxy/telegram/transcode/playlist.m3u8?d=https://t.me/channelname/123&api_password=your_password"
|
|
1514
|
+
|
|
1515
|
+
# Direct transcode mode with explicit seek start (start at 5 minutes)
|
|
1516
|
+
mpv "http://localhost:8888/proxy/stream?d=https://example.com/video.mp4&transcode=true&start=300&api_password=your_password"
|
|
1517
|
+
|
|
1518
|
+
# Acestream transcode (direct mode)
|
|
1519
|
+
mpv "http://localhost:8888/proxy/acestream/stream?id=YOUR_CONTENT_ID&transcode=true&api_password=your_password"
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
**Note:** Transcoding uses GPU hardware acceleration when available (NVIDIA, Apple VideoToolbox, Intel). Browser-compatible codecs (H.264 video, AAC audio) are passed through without re-encoding to minimize resource usage.
|
|
1523
|
+
|
|
1524
|
+
#### Transcode Performance Benchmarks
|
|
1525
|
+
|
|
1526
|
+
Benchmark results for on-the-fly HEVC (H.265) to H.264 transcoding. Source: 4K (3840x2160) 30-second clip at 24fps with EAC3 5.1 audio, from a real movie file.
|
|
1527
|
+
|
|
1528
|
+
**MediaFlow Proxy (on-the-fly streaming via PyAV pipeline):**
|
|
1529
|
+
|
|
1530
|
+
| Source | Encoder | Wall Clock | Video Frames | Effective FPS | Output |
|
|
1531
|
+
|--------|---------|-----------|--------------|---------------|--------|
|
|
1532
|
+
| 4K HEVC MKV (EAC3) | VideoToolbox (GPU) | **11.7s** | 722 | **61.7 fps** | 15.1 MB |
|
|
1533
|
+
| 4K HEVC MKV (EAC3) | libx264 (CPU) | 26.2s | 722 | 27.6 fps | 15.1 MB |
|
|
1534
|
+
|
|
1535
|
+
**Direct FFmpeg CLI baseline (local file, no HTTP proxy):**
|
|
1536
|
+
|
|
1537
|
+
| Source | Encoder | Wall Clock | CPU Time | CPU Usage |
|
|
1538
|
+
|--------|---------|-----------|----------|-----------|
|
|
1539
|
+
| 4K HEVC MKV | VideoToolbox (GPU) | **11.9s** | 10.7s | 92% |
|
|
1540
|
+
| 4K HEVC MKV | libx264 (CPU) | 11.4s | 81.7s | 725% |
|
|
1541
|
+
|
|
1542
|
+
**Key observations:**
|
|
1543
|
+
- **GPU MediaFlow matches direct FFmpeg** -- the optimized pipeline adds near-zero overhead (11.7s vs 11.9s)
|
|
1544
|
+
- GPU **exceeds real-time by 2.5x** for 4K 24fps content (62 fps), meaning no buffering delays
|
|
1545
|
+
- **GPU uses ~7x less CPU** than software encoding (92% vs 725%), leaving resources free for concurrent streams
|
|
1546
|
+
- The pipeline optimizations (thread-safe queues, eliminated async round-trips, skip redundant decoder flush) reduced GPU wall-clock from ~17s to ~11.7s (**31% improvement**)
|
|
1547
|
+
- On servers with NVIDIA GPUs, hardware HEVC decoding (`hevc_cuvid`) would further reduce both wall-clock time and CPU usage
|
|
1548
|
+
|
|
1549
|
+
*Tested on Apple Silicon (M4) with PyAV 16.1.0 and FFmpeg 8.0. Results vary by hardware, content complexity, and network conditions.*
|
|
1550
|
+
|
|
1350
1551
|
#### Stream with Header Removal (Fix Content-Length Issues)
|
|
1351
1552
|
|
|
1352
1553
|
```bash
|
|
@@ -56,6 +56,15 @@ MediaFlow Proxy is a powerful and flexible solution for proxifying various types
|
|
|
56
56
|
- Optional IP-based access control for encrypted URLs
|
|
57
57
|
- URL expiration support for encrypted URLs
|
|
58
58
|
|
|
59
|
+
### On-the-fly Transcoding
|
|
60
|
+
- **Universal video/audio transcoding** to browser-compatible fMP4 (H.264 + AAC)
|
|
61
|
+
- **GPU hardware acceleration** (NVIDIA NVENC, Apple VideoToolbox, Intel VAAPI/QSV) with automatic CPU fallback
|
|
62
|
+
- Supports **any input container** (MKV, MP4, TS, WebM, FLV, etc.) and codec (HEVC, VP8/VP9, MPEG-2, MPEG-4, AC3, EAC3, Vorbis, Opus, etc.)
|
|
63
|
+
- **On-the-fly streaming** -- no full-file buffering; pipe-based demuxing for MKV/TS/WebM and moov-atom probing for MP4
|
|
64
|
+
- **Smart format detection** -- filename extension hints + magic byte sniffing to avoid wasteful probe attempts
|
|
65
|
+
- Available on **all proxy endpoints**: `/proxy/stream`, Telegram, Acestream, and Xtream Codes
|
|
66
|
+
- Triggered by `&transcode=true` query parameter with optional `&start=<seconds>` for seeking
|
|
67
|
+
|
|
59
68
|
### Additional Features
|
|
60
69
|
- Built-in speed test for RealDebrid and AllDebrid services
|
|
61
70
|
- Custom header injection and modification
|
|
@@ -177,6 +186,50 @@ Set the following environment variables:
|
|
|
177
186
|
- `DASH_SEGMENT_CACHE_TTL`: Optional. TTL in seconds for cached DASH segments. Default: `60`. Longer values help with slow network playback.
|
|
178
187
|
- `FORWARDED_ALLOW_IPS`: Optional. Controls which IP addresses are trusted to provide forwarded headers (X-Forwarded-For, X-Forwarded-Proto, etc.) when MediaFlow Proxy is deployed behind reverse proxies or load balancers. Default: `127.0.0.1`. See [Forwarded Headers Configuration](#forwarded-headers-configuration) for detailed usage.
|
|
179
188
|
|
|
189
|
+
### Redis Configuration (Optional)
|
|
190
|
+
|
|
191
|
+
Redis enables cross-worker coordination for rate limiting and caching. This is **recommended** when running with multiple workers (`--workers N`) to prevent CDN rate-limiting issues (e.g., Vidoza 509 errors).
|
|
192
|
+
|
|
193
|
+
- `REDIS_URL`: Optional. Redis connection URL. Default: `None` (disabled). Example: `redis://localhost:6379` or `redis://user:pass@host:6379/0`.
|
|
194
|
+
|
|
195
|
+
**When to use Redis:**
|
|
196
|
+
- Running multiple uvicorn workers (`--workers 4` or more)
|
|
197
|
+
- Streaming from rate-limited CDNs like Vidoza
|
|
198
|
+
- Need shared caching across workers (extractor results, HEAD responses, segments)
|
|
199
|
+
|
|
200
|
+
**Features enabled by Redis:**
|
|
201
|
+
- **Rate limiting**: Prevents rapid-fire requests that trigger CDN 509 errors
|
|
202
|
+
- **HEAD cache**: Serves repeated HEAD probes (e.g., ExoPlayer) without upstream connections
|
|
203
|
+
- **Stream gate**: Serializes initial connections to rate-limited URLs
|
|
204
|
+
- **Extractor cache**: Shares extraction results across all workers
|
|
205
|
+
- **Segment cache**: Shares downloaded segments across workers
|
|
206
|
+
|
|
207
|
+
**Docker Compose example with Redis:**
|
|
208
|
+
```yaml
|
|
209
|
+
services:
|
|
210
|
+
redis:
|
|
211
|
+
image: redis:7-alpine
|
|
212
|
+
restart: unless-stopped
|
|
213
|
+
healthcheck:
|
|
214
|
+
test: ["CMD", "redis-cli", "ping"]
|
|
215
|
+
interval: 10s
|
|
216
|
+
timeout: 5s
|
|
217
|
+
retries: 5
|
|
218
|
+
|
|
219
|
+
mediaflow-proxy:
|
|
220
|
+
image: mhdzumair/mediaflow-proxy:latest
|
|
221
|
+
ports:
|
|
222
|
+
- "8888:8888"
|
|
223
|
+
environment:
|
|
224
|
+
- API_PASSWORD=your_password
|
|
225
|
+
- REDIS_URL=redis://redis:6379
|
|
226
|
+
depends_on:
|
|
227
|
+
redis:
|
|
228
|
+
condition: service_healthy
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Note**: If Redis is not configured, MediaFlow Proxy works normally but rate limiting features are disabled. This is fine for single-worker deployments or CDNs that don't rate-limit aggressively.
|
|
232
|
+
|
|
180
233
|
### Acestream Configuration
|
|
181
234
|
|
|
182
235
|
MediaFlow Proxy can act as a proxy for Acestream P2P streams, converting them to HLS or MPEG-TS format that any media player can consume.
|
|
@@ -203,6 +256,8 @@ MediaFlow Proxy can act as a proxy for Acestream P2P streams, converting them to
|
|
|
203
256
|
|-----------|-------------|
|
|
204
257
|
| `id` | Acestream content ID (alternative to infohash) |
|
|
205
258
|
| `infohash` | Acestream infohash (40-char hex from magnet link) |
|
|
259
|
+
| `transcode` | Set to `true` to transcode to browser-compatible fMP4 (H.264 + AAC) |
|
|
260
|
+
| `start` | Seek start time in seconds (used with `transcode=true`) |
|
|
206
261
|
|
|
207
262
|
**Example URLs:**
|
|
208
263
|
```
|
|
@@ -212,6 +267,9 @@ https://your-mediaflow/proxy/acestream/stream?id=YOUR_CONTENT_ID&api_password=yo
|
|
|
212
267
|
# MPEG-TS stream (infohash from magnet)
|
|
213
268
|
https://your-mediaflow/proxy/acestream/stream?infohash=b04372b9543d763bd2dbd2a1842d9723fd080076&api_password=your_password
|
|
214
269
|
|
|
270
|
+
# Transcode to browser-compatible fMP4
|
|
271
|
+
https://your-mediaflow/proxy/acestream/stream?id=YOUR_CONTENT_ID&transcode=true&api_password=your_password
|
|
272
|
+
|
|
215
273
|
# HLS manifest (alternative)
|
|
216
274
|
https://your-mediaflow/proxy/acestream/manifest.m3u8?id=YOUR_CONTENT_ID&api_password=your_password
|
|
217
275
|
```
|
|
@@ -284,6 +342,9 @@ TELEGRAM_SESSION_STRING=your_session_string_here
|
|
|
284
342
|
|----------|-------------|
|
|
285
343
|
| `/proxy/telegram/stream` | Stream media from t.me link or file_id |
|
|
286
344
|
| `/proxy/telegram/stream/{filename}` | Stream with custom filename |
|
|
345
|
+
| `/proxy/telegram/transcode/playlist.m3u8` | HLS transcode playlist (recommended for browser playback and smooth seeking) |
|
|
346
|
+
| `/proxy/telegram/transcode/init.mp4` | fMP4 init segment for Telegram transcode playlist |
|
|
347
|
+
| `/proxy/telegram/transcode/segment.m4s` | fMP4 media segment for Telegram transcode playlist |
|
|
287
348
|
| `/proxy/telegram/info` | Get media metadata |
|
|
288
349
|
| `/proxy/telegram/status` | Session status and health check |
|
|
289
350
|
|
|
@@ -296,6 +357,8 @@ TELEGRAM_SESSION_STRING=your_session_string_here
|
|
|
296
357
|
| `message_id` | Message ID within the chat (use with `chat_id`) |
|
|
297
358
|
| `file_id` | Bot API file_id (use with `file_size`) |
|
|
298
359
|
| `file_size` | File size in bytes (required when using `file_id`) |
|
|
360
|
+
| `transcode` | Set to `true` for direct transcode mode on `/proxy/telegram/stream` (URL Generator defaults to `/proxy/telegram/transcode/playlist.m3u8` when no start time is set) |
|
|
361
|
+
| `start` | Seek start time in seconds (direct transcode mode only, used with `transcode=true`) |
|
|
299
362
|
|
|
300
363
|
#### Supported Input Formats
|
|
301
364
|
|
|
@@ -1029,11 +1092,65 @@ Ideal for users who want a reliable, plug-and-play solution without the technica
|
|
|
1029
1092
|
4. `/proxy/mpd/playlist.m3u8`: Generate HLS playlists from MPD
|
|
1030
1093
|
5. `/proxy/mpd/segment.mp4`: Process and decrypt media segments
|
|
1031
1094
|
6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
|
|
1032
|
-
7. `/extractor/video
|
|
1095
|
+
7. `/extractor/video`: Extract direct video stream URLs from supported hosts (see below)
|
|
1033
1096
|
8. `/playlist/builder`: Build and customize playlists from multiple sources
|
|
1097
|
+
9. `/proxy/transcode/playlist.m3u8`: Generate HLS VOD playlist for generic stream transcode
|
|
1098
|
+
10. `/proxy/transcode/init.mp4`: fMP4 init segment for generic transcode playlist
|
|
1099
|
+
11. `/proxy/transcode/segment.m4s`: fMP4 media segment for generic transcode playlist
|
|
1100
|
+
12. `/proxy/telegram/transcode/playlist.m3u8`: Generate HLS VOD playlist for Telegram transcode
|
|
1101
|
+
13. `/proxy/telegram/transcode/init.mp4`: fMP4 init segment for Telegram transcode playlist
|
|
1102
|
+
14. `/proxy/telegram/transcode/segment.m4s`: fMP4 media segment for Telegram transcode playlist
|
|
1034
1103
|
|
|
1035
1104
|
Once the server is running, for more details on the available endpoints and their parameters, visit the Swagger UI at `http://localhost:8888/docs`.
|
|
1036
1105
|
|
|
1106
|
+
### Video Extractor Endpoint
|
|
1107
|
+
|
|
1108
|
+
The extractor endpoint extracts direct video stream URLs from various video hosting services. It supports an optional file extension in the URL for better player compatibility.
|
|
1109
|
+
|
|
1110
|
+
#### Endpoints
|
|
1111
|
+
|
|
1112
|
+
| Endpoint | Description |
|
|
1113
|
+
|----------|-------------|
|
|
1114
|
+
| `/extractor/video` | Base endpoint (generic, backward compatible) |
|
|
1115
|
+
| `/extractor/video.m3u8` | HLS streams - helps ExoPlayer detect HLS |
|
|
1116
|
+
| `/extractor/video.mp4` | MP4 streams |
|
|
1117
|
+
| `/extractor/video.mkv` | MKV streams |
|
|
1118
|
+
| `/extractor/video.ts` | MPEG-TS streams |
|
|
1119
|
+
| `/extractor/video.webm` | WebM streams |
|
|
1120
|
+
| `/extractor/video.avi` | AVI streams |
|
|
1121
|
+
|
|
1122
|
+
#### Why Use Extensions?
|
|
1123
|
+
|
|
1124
|
+
Some video players (notably Android's ExoPlayer used in Stremio) determine the media source type from the URL before making any HTTP requests. Without the correct extension:
|
|
1125
|
+
|
|
1126
|
+
- ExoPlayer sees `/extractor/video?...` → Uses `ProgressiveMediaSource`
|
|
1127
|
+
- ExoPlayer sees `/extractor/video.m3u8?...` → Uses `HlsMediaSource` ✓
|
|
1128
|
+
|
|
1129
|
+
For HLS streams, using the `.m3u8` extension ensures the player uses the correct HLS playback pipeline.
|
|
1130
|
+
|
|
1131
|
+
#### Parameters
|
|
1132
|
+
|
|
1133
|
+
| Parameter | Required | Description |
|
|
1134
|
+
|-----------|----------|-------------|
|
|
1135
|
+
| `host` | Yes | Extractor host name (e.g., `TurboVidPlay`, `Vidoza`) |
|
|
1136
|
+
| `d` | Yes | Destination URL (the video page URL to extract) |
|
|
1137
|
+
| `api_password` | Yes* | API password (*if configured) |
|
|
1138
|
+
| `redirect_stream` | No | If `true`, returns 302 redirect to the proxied stream URL |
|
|
1139
|
+
|
|
1140
|
+
#### Example Usage
|
|
1141
|
+
|
|
1142
|
+
**Get extraction result as JSON:**
|
|
1143
|
+
```
|
|
1144
|
+
GET /extractor/video?host=Vidoza&d=https://videzz.net/example.html&api_password=your_password
|
|
1145
|
+
```
|
|
1146
|
+
|
|
1147
|
+
**Redirect directly to stream (for players):**
|
|
1148
|
+
```
|
|
1149
|
+
GET /extractor/video.m3u8?host=TurboVidPlay&d=https://turbovidhls.com/t/abc123&api_password=your_password&redirect_stream=true
|
|
1150
|
+
```
|
|
1151
|
+
|
|
1152
|
+
This redirects to the proxied HLS manifest URL, and because the request URL contains `.m3u8`, players like ExoPlayer will correctly use HLS playback.
|
|
1153
|
+
|
|
1037
1154
|
### Xtream Codes (XC) API Proxy
|
|
1038
1155
|
|
|
1039
1156
|
MediaFlow Proxy can act as a stateless pass-through proxy for Xtream Codes API, allowing you to proxy streams from XC-compatible IPTV providers through MediaFlow. This is particularly useful for:
|
|
@@ -1214,6 +1331,44 @@ Apply stream content transformations for specific hosting providers.
|
|
|
1214
1331
|
- **Example:** `&transformer=ts_stream&x_headers=content-length,content-range` for streams with PNG wrappers.
|
|
1215
1332
|
- **Note:** This parameter is automatically set when using extractors for supported hosts.
|
|
1216
1333
|
|
|
1334
|
+
**`/proxy/transcode/playlist.m3u8` and `/proxy/telegram/transcode/playlist.m3u8` (recommended)**
|
|
1335
|
+
Use HLS transcode playlists for smooth browser playback and robust seeking with fMP4 segments.
|
|
1336
|
+
- **Usage:** Open the playlist endpoint directly with `d` (or Telegram params), optional `api_password`, and optional `h_*` headers.
|
|
1337
|
+
- **Effect:** Generates an HLS VOD playlist that references `init.mp4` + `segment.m4s` endpoints with browser-compatible H.264/AAC output.
|
|
1338
|
+
- **URL Generator behavior:** When transcode is enabled and no start time is provided, URL Generator outputs these playlist URLs by default.
|
|
1339
|
+
|
|
1340
|
+
**`&transcode=true` (direct mode)**
|
|
1341
|
+
Transcode the stream directly to browser-compatible fragmented MP4 (fMP4) with H.264 video and AAC audio.
|
|
1342
|
+
- **Usage:** Add `&transcode=true` to `/proxy/stream`, `/proxy/telegram/stream`, `/proxy/acestream/stream`, or Xtream Codes live/movie/series stream URLs.
|
|
1343
|
+
- **Effect:** Re-encodes unsupported video codecs (HEVC, VP8/VP9, MPEG-2, MPEG-4, etc.) to H.264 and unsupported audio codecs (AC3, EAC3, Vorbis, Opus, FLAC, DTS, etc.) to AAC. Browser-compatible codecs (H.264 video, AAC audio) are passed through without re-encoding.
|
|
1344
|
+
- **GPU Acceleration:** Automatically uses GPU encoding when available (NVIDIA NVENC, Apple VideoToolbox, Intel VAAPI/QSV). Falls back to CPU (libx264) otherwise.
|
|
1345
|
+
- **On-the-fly:** Streaming is real-time with pipe-based demuxing. For MP4 inputs, the moov atom is probed and rewritten for immediate playback without downloading the full file.
|
|
1346
|
+
|
|
1347
|
+
**`&start=120`**
|
|
1348
|
+
Seek to a specific time position before starting transcoded playback.
|
|
1349
|
+
- **Usage:** Add `&start=120` (value in seconds) alongside `&transcode=true` in direct transcode mode
|
|
1350
|
+
- **Effect:** Starts transcoding from the specified time offset. For indexed containers (MKV cues, MP4 moov), this seeks to the nearest keyframe. For non-indexed formats (TS), this is a byte-estimate seek.
|
|
1351
|
+
- **Supported Endpoints:** `/proxy/stream`, `/proxy/telegram/stream`, `/proxy/acestream/stream`, Xtream Codes live/movie/series endpoints
|
|
1352
|
+
- **Note:** `start` is not used by `/proxy/transcode/playlist.m3u8` or `/proxy/telegram/transcode/playlist.m3u8` endpoints.
|
|
1353
|
+
- **Example:** `&transcode=true&start=300` starts playback from 5 minutes into the stream
|
|
1354
|
+
|
|
1355
|
+
**`&ratelimit=vidoza`**
|
|
1356
|
+
Apply host-specific rate limiting to prevent CDN 509 (Bandwidth Limit Exceeded) errors. Requires Redis to be configured.
|
|
1357
|
+
- **Usage:** Add `&ratelimit=handler_id` to the `/proxy/stream` URL
|
|
1358
|
+
- **Effect:** Limits the frequency of upstream connections to avoid triggering rate limits on aggressive CDNs.
|
|
1359
|
+
- **Auto-detection:** If not specified, rate limiting is automatically applied for known hosts (e.g., Vidoza).
|
|
1360
|
+
- **Available Handlers:**
|
|
1361
|
+
- `vidoza` - 5-second cooldown between connections, HEAD caching, stream gating (auto-detected for vidoza.net)
|
|
1362
|
+
- `aggressive` - 3-second cooldown, suitable for other rate-limited hosts
|
|
1363
|
+
- `none` - Explicitly disable rate limiting (use when auto-detection is unwanted)
|
|
1364
|
+
- **How it works:** When a rate-limited stream is requested:
|
|
1365
|
+
1. HEAD responses are cached to serve repeated probes without upstream connections
|
|
1366
|
+
2. A cooldown period prevents rapid-fire GET requests
|
|
1367
|
+
3. If another request arrives during cooldown, returns `503 Service Unavailable` with `Retry-After` header
|
|
1368
|
+
4. Players automatically retry after the cooldown, resulting in smooth playback
|
|
1369
|
+
- **Requires:** `REDIS_URL` must be configured for rate limiting to function. Without Redis, rate limiting is disabled.
|
|
1370
|
+
- **Example:** `&ratelimit=vidoza` for Vidoza streams, or `&ratelimit=none` to disable auto-detection.
|
|
1371
|
+
|
|
1217
1372
|
**`&rp_content-type=video/mp2t`**
|
|
1218
1373
|
Set response headers that propagate to HLS/DASH segments.
|
|
1219
1374
|
- **Usage:** Add `&rp_header-name=value` to the proxy URL (rp_ prefix)
|
|
@@ -1307,6 +1462,51 @@ mpv "http://localhost:8888/proxy/acestream/manifest.m3u8?id=your_content_id&star
|
|
|
1307
1462
|
|
|
1308
1463
|
**Note:** The `start_offset` parameter is particularly useful for live streams where the prebuffer system cannot prefetch segments when sitting at the live edge. By starting slightly behind (e.g., `-18` seconds), there are future segments available for prebuffering, resulting in smoother playback. This works for both native HLS and DASH/MPD streams converted to HLS.
|
|
1309
1464
|
|
|
1465
|
+
#### Transcode Stream for Browser Playback
|
|
1466
|
+
|
|
1467
|
+
```bash
|
|
1468
|
+
# Recommended: HLS transcode playlist for generic streams
|
|
1469
|
+
mpv "http://localhost:8888/proxy/transcode/playlist.m3u8?d=https://example.com/video.mkv&api_password=your_password"
|
|
1470
|
+
|
|
1471
|
+
# Recommended: HLS transcode playlist for Telegram streams
|
|
1472
|
+
mpv "http://localhost:8888/proxy/telegram/transcode/playlist.m3u8?d=https://t.me/channelname/123&api_password=your_password"
|
|
1473
|
+
|
|
1474
|
+
# Direct transcode mode with explicit seek start (start at 5 minutes)
|
|
1475
|
+
mpv "http://localhost:8888/proxy/stream?d=https://example.com/video.mp4&transcode=true&start=300&api_password=your_password"
|
|
1476
|
+
|
|
1477
|
+
# Acestream transcode (direct mode)
|
|
1478
|
+
mpv "http://localhost:8888/proxy/acestream/stream?id=YOUR_CONTENT_ID&transcode=true&api_password=your_password"
|
|
1479
|
+
```
|
|
1480
|
+
|
|
1481
|
+
**Note:** Transcoding uses GPU hardware acceleration when available (NVIDIA, Apple VideoToolbox, Intel). Browser-compatible codecs (H.264 video, AAC audio) are passed through without re-encoding to minimize resource usage.
|
|
1482
|
+
|
|
1483
|
+
#### Transcode Performance Benchmarks
|
|
1484
|
+
|
|
1485
|
+
Benchmark results for on-the-fly HEVC (H.265) to H.264 transcoding. Source: 4K (3840x2160) 30-second clip at 24fps with EAC3 5.1 audio, from a real movie file.
|
|
1486
|
+
|
|
1487
|
+
**MediaFlow Proxy (on-the-fly streaming via PyAV pipeline):**
|
|
1488
|
+
|
|
1489
|
+
| Source | Encoder | Wall Clock | Video Frames | Effective FPS | Output |
|
|
1490
|
+
|--------|---------|-----------|--------------|---------------|--------|
|
|
1491
|
+
| 4K HEVC MKV (EAC3) | VideoToolbox (GPU) | **11.7s** | 722 | **61.7 fps** | 15.1 MB |
|
|
1492
|
+
| 4K HEVC MKV (EAC3) | libx264 (CPU) | 26.2s | 722 | 27.6 fps | 15.1 MB |
|
|
1493
|
+
|
|
1494
|
+
**Direct FFmpeg CLI baseline (local file, no HTTP proxy):**
|
|
1495
|
+
|
|
1496
|
+
| Source | Encoder | Wall Clock | CPU Time | CPU Usage |
|
|
1497
|
+
|--------|---------|-----------|----------|-----------|
|
|
1498
|
+
| 4K HEVC MKV | VideoToolbox (GPU) | **11.9s** | 10.7s | 92% |
|
|
1499
|
+
| 4K HEVC MKV | libx264 (CPU) | 11.4s | 81.7s | 725% |
|
|
1500
|
+
|
|
1501
|
+
**Key observations:**
|
|
1502
|
+
- **GPU MediaFlow matches direct FFmpeg** -- the optimized pipeline adds near-zero overhead (11.7s vs 11.9s)
|
|
1503
|
+
- GPU **exceeds real-time by 2.5x** for 4K 24fps content (62 fps), meaning no buffering delays
|
|
1504
|
+
- **GPU uses ~7x less CPU** than software encoding (92% vs 725%), leaving resources free for concurrent streams
|
|
1505
|
+
- The pipeline optimizations (thread-safe queues, eliminated async round-trips, skip redundant decoder flush) reduced GPU wall-clock from ~17s to ~11.7s (**31% improvement**)
|
|
1506
|
+
- On servers with NVIDIA GPUs, hardware HEVC decoding (`hevc_cuvid`) would further reduce both wall-clock time and CPU usage
|
|
1507
|
+
|
|
1508
|
+
*Tested on Apple Silicon (M4) with PyAV 16.1.0 and FFmpeg 8.0. Results vary by hardware, content complexity, and network conditions.*
|
|
1509
|
+
|
|
1310
1510
|
#### Stream with Header Removal (Fix Content-Length Issues)
|
|
1311
1511
|
|
|
1312
1512
|
```bash
|
|
@@ -64,8 +64,16 @@ class Settings(BaseSettings):
|
|
|
64
64
|
dash_prebuffer_emergency_threshold: int = 90 # Emergency threshold percentage to trigger aggressive cache cleanup.
|
|
65
65
|
dash_prebuffer_inactivity_timeout: int = 60 # Seconds of inactivity before cleaning up stream state.
|
|
66
66
|
dash_segment_cache_ttl: int = 60 # TTL (seconds) for cached media segments; longer = better for slow playback.
|
|
67
|
+
dash_player_lock_timeout: float = 2.5 # Max wait (seconds) for player requests when a segment lock is busy.
|
|
68
|
+
dash_prebuffer_lock_timeout: float = 0.25 # Max wait (seconds) for background prebuffer lock acquisition.
|
|
69
|
+
dash_prefetch_max_concurrent: int = 1 # Max concurrent live DASH prefetch downloads to reduce lock contention.
|
|
70
|
+
dash_live_initial_media_prebuffer: bool = (
|
|
71
|
+
False # Whether manifest-time prebuffer should fetch live media segments (init segments are still prewarmed).
|
|
72
|
+
)
|
|
67
73
|
mpd_live_init_cache_ttl: int = 60 # TTL (seconds) for live init segment cache; 0 disables caching.
|
|
68
74
|
mpd_live_playlist_depth: int = 8 # Number of recent segments to expose per live playlist variant.
|
|
75
|
+
remux_to_ts: bool = False # Remux fMP4 segments to MPEG-TS for ExoPlayer/VLC compatibility.
|
|
76
|
+
processed_segment_cache_ttl: int = 60 # TTL (seconds) for caching processed (decrypted/remuxed) segments.
|
|
69
77
|
|
|
70
78
|
# FlareSolverr settings (for Cloudflare bypass)
|
|
71
79
|
flaresolverr_url: str | None = None # FlareSolverr service URL. Example: http://localhost:8191
|
|
@@ -88,6 +96,13 @@ class Settings(BaseSettings):
|
|
|
88
96
|
telegram_max_connections: int = 8 # Max parallel DC connections for downloads (max 20, careful of floods).
|
|
89
97
|
telegram_request_timeout: int = 30 # Request timeout in seconds.
|
|
90
98
|
|
|
99
|
+
# Transcode settings
|
|
100
|
+
enable_transcode: bool = True # Whether to enable on-the-fly transcoding endpoints (MKV→fMP4, HLS VOD).
|
|
101
|
+
transcode_prefer_gpu: bool = True # Prefer GPU acceleration (NVENC/VideoToolbox/VAAPI) when available.
|
|
102
|
+
transcode_video_bitrate: str = "4M" # Target video bitrate for re-encoding (e.g. "4M", "2000k").
|
|
103
|
+
transcode_audio_bitrate: int = 192000 # AAC audio bitrate in bits/s for the Python transcode pipeline.
|
|
104
|
+
transcode_video_preset: str = "medium" # Encoding speed/quality tradeoff (libx264: ultrafast..veryslow).
|
|
105
|
+
|
|
91
106
|
user_agent: str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36" # The user agent to use for HTTP requests.
|
|
92
107
|
|
|
93
108
|
# Upstream error resilience settings
|
|
@@ -96,6 +111,12 @@ class Settings(BaseSettings):
|
|
|
96
111
|
upstream_retry_delay: float = 1.0 # Delay (seconds) between retry attempts.
|
|
97
112
|
graceful_stream_end: bool = True # Return valid empty playlist instead of error when upstream fails.
|
|
98
113
|
|
|
114
|
+
# Redis settings
|
|
115
|
+
redis_url: str | None = None # Redis URL for distributed locking and caching. None = disabled.
|
|
116
|
+
cache_namespace: str | None = (
|
|
117
|
+
None # Optional namespace for instance-specific caches (e.g. pod name or hostname). When set, extractor results and other IP-bound data are stored under this namespace so multiple pods sharing one Redis don't serve each other's IP-specific URLs.
|
|
118
|
+
)
|
|
119
|
+
|
|
99
120
|
class Config:
|
|
100
121
|
env_file = ".env"
|
|
101
122
|
extra = "ignore"
|