Fix ffmpeg redirects. Fix max resolution setting.

This commit is contained in:
Amar Sandhu
2026-04-24 15:19:19 -06:00
parent 0e26a90dae
commit f5e2c77d25
6 changed files with 44 additions and 17 deletions

View File

@ -33,6 +33,11 @@ function probeStream(url, ffprobePath, userAgent = null, timeout = 15000) {
const args = [
'-v', 'error',
'-user_agent', userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
'-http_persistent', '0',
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_on_http_error', '4xx,5xx',
'-reconnect_delay_max', '10',
'-print_format', 'json',
'-show_streams',
'-show_format',
@ -186,7 +191,7 @@ router.get('/', async (req, res) => {
console.error('[Probe] Failed:', err.message);
// On error, assume transcode needed to be safe
res.json({
const fallback = {
video: 'unknown',
audio: 'unknown',
container: 'unknown',
@ -194,7 +199,11 @@ router.get('/', async (req, res) => {
needsRemux: false,
needsTranscode: true,
error: err.message
});
};
probeCache.set(cacheKey, { result: fallback, timestamp: Date.now() - (CACHE_TTL - 30000) });
res.json(fallback);
}
});

View File

@ -44,10 +44,12 @@ router.get('/', async (req, res) => {
'-err_detect', 'ignore_err',
// Limit max demux delay to prevent buffering issues with bad timestamps
'-max_delay', '5000000',
'-http_persistent', '0',
// Reconnect settings for network drops
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '5',
'-reconnect_on_http_error', '4xx,5xx',
'-reconnect_delay_max', '10',
// Prevent Range/HEAD requests that some providers reject with 405
'-seekable', '0',
'-i', url,

View File

@ -29,7 +29,7 @@ transcodeSession.startCleanupInterval();
* Body: { url: string, seekOffset?: number }
*/
router.post('/session', async (req, res) => {
const { url, seekOffset, videoMode, videoCodec, audioCodec, audioChannels } = req.body;
const { url, seekOffset, videoMode, videoCodec, audioCodec, audioChannels, videoHeight } = req.body;
if (!url) {
return res.status(400).json({ error: 'URL is required' });
@ -55,7 +55,8 @@ router.post('/session', async (req, res) => {
videoMode: videoMode, // 'copy' or 'encode'
videoCodec: videoCodec, // 'h264', 'hevc', etc.
audioCodec: audioCodec, // 'aac', 'ac3', etc.
audioChannels: audioChannels // number of channels (2=stereo)
audioChannels: audioChannels, // number of channels (2=stereo)
videoHeight: videoHeight // source height from probe; used to cap max-resolution in JS
});
await session.start();
@ -191,10 +192,12 @@ router.get('/', async (req, res) => {
'-err_detect', 'ignore_err',
// Limit max demux delay to prevent buffering issues
'-max_delay', '2000000',
'-http_persistent', '0',
// Reconnect settings for network drops (useful for live streams)
'-reconnect', '1',
'-reconnect_streamed', '1',
'-reconnect_delay_max', '3',
'-reconnect_on_http_error', '4xx,5xx',
'-reconnect_delay_max', '10',
// Prevent Range/HEAD requests that some providers reject with 405
'-seekable', '0',
'-i', url,