feat: add -seekable 0 to fix 405 errors and configurable User-Agent presets for stream requests

This commit is contained in:
Trevor Mears
2026-01-17 00:45:55 -08:00
parent c1a1ac4faa
commit 2a03cad213
6 changed files with 111 additions and 7 deletions
+11 -2
View File
@@ -1,6 +1,7 @@
const express = require('express');
const router = express.Router();
const { spawn } = require('child_process');
const db = require('../db');
/**
* Remux stream (container conversion only)
@@ -12,21 +13,27 @@ const { spawn } = require('child_process');
*
* Note: This does NOT fix Dolby/AC3 audio issues - use /api/transcode for that.
*/
router.get('/', (req, res) => {
router.get('/', async (req, res) => {
const { url } = req.query;
if (!url) {
return res.status(400).json({ error: 'URL parameter is required' });
}
const ffmpegPath = req.app.locals.ffmpegPath || 'ffmpeg';
// Get User-Agent from settings
const settings = await db.settings.get();
const userAgent = db.getUserAgent(settings);
console.log(`[Remux] Starting remux for: ${url}`);
console.log(`[Remux] Using User-Agent: ${settings.userAgentPreset}`);
// FFmpeg arguments for pure remux (no encoding)
// Very lightweight - just changes container from TS to fragmented MP4
const args = [
'-hide_banner',
'-loglevel', 'warning',
'-user_agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'-user_agent', userAgent,
// Low-latency startup: reduce probe/analyze time for faster first bytes
'-probesize', '32768',
'-analyzeduration', '500000', // 0.5 seconds - enough to detect audio
@@ -40,6 +47,8 @@ router.get('/', (req, res) => {
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '5',
// Prevent Range/HEAD requests that some providers reject with 405
'-seekable', '0',
'-i', url,
// STRICT MAPPING: Only map video and audio, ignore subtitles/data/attachments
// This prevents remux failure when source container has incompatible subtitle tracks (e.g. MKV -> MP4)