feat: add initial Dart server with API routing, authentication, streaming, and static file serving.

This commit is contained in:
Michael committed 2025-12-07 15:21:29 +01:00
1 parent 9cb193b9f7
commit 7372f51b19
1 file changed
+35 -3
+35 -3
View File
@@ -418,6 +418,8 @@ Handler _createStreamHandler() {
// Get parameters
final iptvUrl = request.url.queryParameters['url'];
final quality = request.url.queryParameters['quality'] ?? 'high';
if (iptvUrl == null || iptvUrl.isEmpty) {
return Response.badRequest(body: 'Missing url parameter');
}
@@ -452,9 +454,39 @@ Handler _createStreamHandler() {
// Output format: MPEG-TS for streaming (compatible with mpegts.js)
'-f', 'mpegts',
// Video: Copy is BEST for performance (0% CPU)
// Browsers support H.264 well.
'-c:v', 'copy',
// Video: Transcode based on quality
// High = Copy (efficient), Low/Medium = Transcode to H.264 (compatible)
if (quality == 'high') {
ffmpegArgs.addAll(['-c:v', 'copy']);
} else {
// Transcode to H.264 (Baseline profile for max mobile compatibility)
ffmpegArgs.addAll([
'-c:v', 'libx264',
'-preset', 'ultrafast', // Critical for live streaming
'-tune', 'zerolatency',
'-profile:v', 'baseline',
'-level', '3.0',
'-pix_fmt', 'yuv420p', // Ensure standard pixel format for web
'-g', '60', // Keyframe interval (2s at 30fps) for seeking
]);
if (quality == 'low') {
// Low: ~480p, 800k
ffmpegArgs.addAll([
'-vf', 'scale=-2:480',
'-b:v', '800k',
'-maxrate', '800k',
'-bufsize', '1600k'
]);
} else {
// Medium: Original res (or cap at 720p?), 2500k
ffmpegArgs.addAll([
'-b:v', '2500k',
'-maxrate', '2500k',
'-bufsize', '5000k'
]);
}
}
// Audio: Transcode to AAC is SAFEST for browsers
// (Many IPTV streams typically use MP2/AC3 which browsers hate)