Checkpoint bitmap subtitle overlay stability
@@ -7,3 +7,4 @@ config.json
7
7
8
8
public/thumbs/
9
9
zip-cache/
10
logs.txt
@@ -7,3 +7,4 @@ config.json7
7
8
public/thumbs/
8
public/thumbs/
9
zip-cache/
9
zip-cache/
10
logs.txt
@@ -457,6 +457,8 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
457
457
let overlayImgEl = null;
458
458
let menuEl = null;
459
459
let buttonEl = null;
460
let trackDisabled = false;
461
let failureNotified = false;
460
462
461
463
const closeObjectUrl = () =>
462
464
{
@@ -522,11 +524,30 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
522
524
saveUserVideoPrefs({ imageSubtitleTrackStreamIndex: selectedStreamIndex });
523
525
};
524
526
527
const disableTrack = () =>
528
{
529
trackDisabled = true;
530
selectedStreamIndex = null;
531
activeBucket = -1;
532
hideOverlay();
533
updateButtonState();
534
updateMenuState();
535
saveSelection();
536
537
if (!failureNotified)
538
{
539
failureNotified = true;
540
toast('Image subtitles could not be rendered for this file.', 'err');
541
}
542
};
543
525
544
const setSelectedStreamIndex = (streamIndex, { persist = true } = {}) =>
526
545
{
527
546
const nextStreamIndex = Number.isInteger(streamIndex) ? streamIndex : null;
528
547
if (nextStreamIndex !== null && !trackByStreamIndex.has(nextStreamIndex)) return;
529
548
549
trackDisabled = false;
550
failureNotified = false;
530
551
selectedStreamIndex = nextStreamIndex;
531
552
activeBucket = -1;
532
553
hideOverlay();
@@ -544,6 +565,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
544
565
{
545
566
if (selectedStreamIndex === null) return;
546
567
if (!overlayEl || !overlayImgEl) return;
568
if (trackDisabled) return;
547
569
548
570
const currentTime = Number(player.currentTime());
549
571
if (!Number.isFinite(currentTime) || currentTime < 0) return;
@@ -554,7 +576,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
554
576
555
577
const token = ++requestToken;
556
578
const headers = buildAuthHeaders();
557
const url = `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${selectedStreamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}`;
579
const url = `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${selectedStreamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}&videoWidth=${encodeURIComponent(String(session.videoWidth || ''))}&videoHeight=${encodeURIComponent(String(session.videoHeight || ''))}`;
558
580
559
581
try
560
582
{
@@ -566,15 +588,29 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
566
588
567
589
if (token !== requestToken) return;
568
590
569
if (!res.ok)
591
if (res.status === 204)
570
592
{
593
const frameStatus = String(res.headers.get('X-Subtitle-Frame-Status') || '').toLowerCase();
571
594
hideOverlay();
595
if (frameStatus === 'error') disableTrack();
596
return;
597
}
598
599
if (!res.ok)
600
{
601
disableTrack();
572
602
return;
573
603
}
574
604
575
605
const blob = await res.blob();
576
606
if (token !== requestToken) return;
577
607
608
if (!blob || blob.size === 0)
609
{
610
disableTrack();
611
return;
612
}
613
578
614
closeObjectUrl();
579
615
activeObjectUrl = URL.createObjectURL(blob);
580
616
overlayImgEl.src = activeObjectUrl;
@@ -582,7 +618,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
582
618
overlayImgEl.style.display = 'block';
583
619
} catch
584
620
{
585
if (token === requestToken) hideOverlay();
621
if (token === requestToken) disableTrack();
586
622
}
587
623
};
588
624
@@ -457,6 +457,8 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)457
let overlayImgEl = null;457
let overlayImgEl = null;458
let menuEl = null;458
let menuEl = null;459
let buttonEl = null;459
let buttonEl = null;460
let trackDisabled = false;461
let failureNotified = false;460
462
461
const closeObjectUrl = () =>463
const closeObjectUrl = () =>462
{464
{@@ -522,11 +524,30 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)522
saveUserVideoPrefs({ imageSubtitleTrackStreamIndex: selectedStreamIndex });524
saveUserVideoPrefs({ imageSubtitleTrackStreamIndex: selectedStreamIndex });523
};525
};524
526
527
const disableTrack = () =>528
{529
trackDisabled = true;530
selectedStreamIndex = null;531
activeBucket = -1;532
hideOverlay();533
updateButtonState();534
updateMenuState();535
saveSelection();536
537
if (!failureNotified)538
{539
failureNotified = true;540
toast('Image subtitles could not be rendered for this file.', 'err');541
}542
};543
525
const setSelectedStreamIndex = (streamIndex, { persist = true } = {}) =>544
const setSelectedStreamIndex = (streamIndex, { persist = true } = {}) =>526
{545
{527
const nextStreamIndex = Number.isInteger(streamIndex) ? streamIndex : null;546
const nextStreamIndex = Number.isInteger(streamIndex) ? streamIndex : null;528
if (nextStreamIndex !== null && !trackByStreamIndex.has(nextStreamIndex)) return;547
if (nextStreamIndex !== null && !trackByStreamIndex.has(nextStreamIndex)) return;529
548
549
trackDisabled = false;550
failureNotified = false;530
selectedStreamIndex = nextStreamIndex;551
selectedStreamIndex = nextStreamIndex;531
activeBucket = -1;552
activeBucket = -1;532
hideOverlay();553
hideOverlay();@@ -544,6 +565,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)544
{565
{545
if (selectedStreamIndex === null) return;566
if (selectedStreamIndex === null) return;546
if (!overlayEl || !overlayImgEl) return;567
if (!overlayEl || !overlayImgEl) return;568
if (trackDisabled) return;547
569
548
const currentTime = Number(player.currentTime());570
const currentTime = Number(player.currentTime());549
if (!Number.isFinite(currentTime) || currentTime < 0) return;571
if (!Number.isFinite(currentTime) || currentTime < 0) return;@@ -554,7 +576,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)554
576
555
const token = ++requestToken;577
const token = ++requestToken;556
const headers = buildAuthHeaders();578
const headers = buildAuthHeaders();557
const url = `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${selectedStreamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}`;579
const url = `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${selectedStreamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}&videoWidth=${encodeURIComponent(String(session.videoWidth || ''))}&videoHeight=${encodeURIComponent(String(session.videoHeight || ''))}`;558
580
559
try581
try560
{582
{@@ -566,15 +588,29 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)566
588
567
if (token !== requestToken) return;589
if (token !== requestToken) return;568
590
569
if (!res.ok)591
if (res.status === 204)570
{592
{593
const frameStatus = String(res.headers.get('X-Subtitle-Frame-Status') || '').toLowerCase();571
hideOverlay();594
hideOverlay();595
if (frameStatus === 'error') disableTrack();596
return;597
}598
599
if (!res.ok)600
{601
disableTrack();572
return;602
return;573
}603
}574
604
575
const blob = await res.blob();605
const blob = await res.blob();576
if (token !== requestToken) return;606
if (token !== requestToken) return;577
607
608
if (!blob || blob.size === 0)609
{610
disableTrack();611
return;612
}613
578
closeObjectUrl();614
closeObjectUrl();579
activeObjectUrl = URL.createObjectURL(blob);615
activeObjectUrl = URL.createObjectURL(blob);580
overlayImgEl.src = activeObjectUrl;616
overlayImgEl.src = activeObjectUrl;@@ -582,7 +618,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)582
overlayImgEl.style.display = 'block';618
overlayImgEl.style.display = 'block';583
} catch619
} catch584
{620
{585
if (token === requestToken) hideOverlay();621
if (token === requestToken) disableTrack();586
}622
}587
};623
};588
624
@@ -9,6 +9,7 @@ const { initDb, closeDb } = require('./db');
9
9
const { ensureServerKeys } = require('./crypto');
10
10
const { loadConfig } = require('./config');
11
11
const { startThumbnailCacheLoop, stopThumbnailCacheLoop } = require('./thumbnail-cache');
12
const { logError } = require('./logger');
12
13
const authRoutes = require('./routes/auth');
13
14
const filesRoutes = require('./routes/files');
14
15
const adminRoutes = require('./routes/admin');
@@ -25,6 +26,17 @@ app.use('/api/files', filesRoutes);
25
26
app.use('/api/admin', adminRoutes);
26
27
app.use('/api/share', shareRoutes);
27
28
29
app.use((err, req, res, next) =>
30
{
31
logError(`${req.method} ${req.originalUrl || req.url} failed`, err, {
32
statusCode: res.statusCode,
33
user: req.user && req.user.username ? req.user.username : null,
34
});
35
36
if (res.headersSent) return next(err);
37
res.status(500).json({ error: 'Internal Server Error' });
38
});
39
28
40
// Share page — served without authentication. OG meta tags are injected
29
41
// server-side so social media crawlers (Discord, WhatsApp, Telegram, etc.)
30
42
// can display rich previews.
@@ -117,6 +129,15 @@ function start ()
117
129
118
130
process.on('SIGINT', shutdownAll);
119
131
process.on('SIGTERM', shutdownAll);
132
process.on('uncaughtException', (err) =>
133
{
134
logError('Uncaught exception', err);
135
process.exit(1);
136
});
137
process.on('unhandledRejection', (reason) =>
138
{
139
logError('Unhandled rejection', reason instanceof Error ? reason : new Error(String(reason)));
140
});
120
141
}
121
142
122
143
try
@@ -9,6 +9,7 @@ const { initDb, closeDb } = require('./db');9
const { ensureServerKeys } = require('./crypto');9
const { ensureServerKeys } = require('./crypto');10
const { loadConfig } = require('./config');10
const { loadConfig } = require('./config');11
const { startThumbnailCacheLoop, stopThumbnailCacheLoop } = require('./thumbnail-cache');11
const { startThumbnailCacheLoop, stopThumbnailCacheLoop } = require('./thumbnail-cache');12
const { logError } = require('./logger');12
const authRoutes = require('./routes/auth');13
const authRoutes = require('./routes/auth');13
const filesRoutes = require('./routes/files');14
const filesRoutes = require('./routes/files');14
const adminRoutes = require('./routes/admin');15
const adminRoutes = require('./routes/admin');@@ -25,6 +26,17 @@ app.use('/api/files', filesRoutes);25
app.use('/api/admin', adminRoutes);26
app.use('/api/admin', adminRoutes);26
app.use('/api/share', shareRoutes);27
app.use('/api/share', shareRoutes);27
28
29
app.use((err, req, res, next) =>30
{31
logError(`${req.method} ${req.originalUrl || req.url} failed`, err, {32
statusCode: res.statusCode,33
user: req.user && req.user.username ? req.user.username : null,34
});35
36
if (res.headersSent) return next(err);37
res.status(500).json({ error: 'Internal Server Error' });38
});39
28
// Share page — served without authentication. OG meta tags are injected40
// Share page — served without authentication. OG meta tags are injected29
// server-side so social media crawlers (Discord, WhatsApp, Telegram, etc.)41
// server-side so social media crawlers (Discord, WhatsApp, Telegram, etc.)30
// can display rich previews.42
// can display rich previews.@@ -117,6 +129,15 @@ function start ()117
129
118
process.on('SIGINT', shutdownAll);130
process.on('SIGINT', shutdownAll);119
process.on('SIGTERM', shutdownAll);131
process.on('SIGTERM', shutdownAll);132
process.on('uncaughtException', (err) =>133
{134
logError('Uncaught exception', err);135
process.exit(1);136
});137
process.on('unhandledRejection', (reason) =>138
{139
logError('Unhandled rejection', reason instanceof Error ? reason : new Error(String(reason)));140
});120
}141
}121
142
122
try143
try@@ -0,0 +1,82 @@
1
'use strict';
2
3
const fs = require('fs');
4
const path = require('path');
5
6
const LOG_FILE_PATH = path.join(__dirname, '../logs.txt');
7
const MAX_LOG_BYTES = 1024 * 1024;
8
9
function formatLogLine (level, message, details = null)
10
{
11
const timestamp = new Date().toISOString();
12
const parts = [`[${timestamp}]`, `[${level}]`, String(message || '')];
13
14
if (details)
15
{
16
if (details.stack)
17
{
18
parts.push(String(details.stack));
19
} else if (details.message)
20
{
21
parts.push(String(details.message));
22
} else
23
{
24
try
25
{
26
parts.push(JSON.stringify(details));
27
} catch
28
{
29
parts.push(String(details));
30
}
31
}
32
}
33
34
return parts.join(' ') + '\n';
35
}
36
37
function trimToLimit (contents)
38
{
39
let text = String(contents || '');
40
if (Buffer.byteLength(text, 'utf8') <= MAX_LOG_BYTES) return text;
41
42
const lines = text.split(/\r?\n/);
43
while (lines.length > 1 && Buffer.byteLength(lines.join('\n'), 'utf8') > MAX_LOG_BYTES)
44
{
45
lines.shift();
46
}
47
48
text = lines.join('\n');
49
if (text && !text.endsWith('\n')) text += '\n';
50
return text;
51
}
52
53
function appendLogLine (line)
54
{
55
try
56
{
57
fs.mkdirSync(path.dirname(LOG_FILE_PATH), { recursive: true });
58
const existing = fs.existsSync(LOG_FILE_PATH) ? fs.readFileSync(LOG_FILE_PATH, 'utf8') : '';
59
fs.writeFileSync(LOG_FILE_PATH, trimToLimit(existing + line), 'utf8');
60
} catch
61
{
62
// Logging must never interfere with the request path.
63
}
64
}
65
66
function logError (message, error = null, details = null)
67
{
68
if (process.env.NODE_ENV === 'test') return;
69
70
const payload = details || {};
71
if (error && !payload.stack)
72
{
73
payload.stack = error.stack || error.message || String(error);
74
}
75
76
appendLogLine(formatLogLine('ERROR', message, payload));
77
}
78
79
module.exports = {
80
LOG_FILE_PATH,
81
logError,
82
};
@@ -0,0 +1,82 @@1
'use strict';2
3
const fs = require('fs');4
const path = require('path');5
6
const LOG_FILE_PATH = path.join(__dirname, '../logs.txt');7
const MAX_LOG_BYTES = 1024 * 1024;8
9
function formatLogLine (level, message, details = null)10
{11
const timestamp = new Date().toISOString();12
const parts = [`[${timestamp}]`, `[${level}]`, String(message || '')];13
14
if (details)15
{16
if (details.stack)17
{18
parts.push(String(details.stack));19
} else if (details.message)20
{21
parts.push(String(details.message));22
} else23
{24
try25
{26
parts.push(JSON.stringify(details));27
} catch28
{29
parts.push(String(details));30
}31
}32
}33
34
return parts.join(' ') + '\n';35
}36
37
function trimToLimit (contents)38
{39
let text = String(contents || '');40
if (Buffer.byteLength(text, 'utf8') <= MAX_LOG_BYTES) return text;41
42
const lines = text.split(/\r?\n/);43
while (lines.length > 1 && Buffer.byteLength(lines.join('\n'), 'utf8') > MAX_LOG_BYTES)44
{45
lines.shift();46
}47
48
text = lines.join('\n');49
if (text && !text.endsWith('\n')) text += '\n';50
return text;51
}52
53
function appendLogLine (line)54
{55
try56
{57
fs.mkdirSync(path.dirname(LOG_FILE_PATH), { recursive: true });58
const existing = fs.existsSync(LOG_FILE_PATH) ? fs.readFileSync(LOG_FILE_PATH, 'utf8') : '';59
fs.writeFileSync(LOG_FILE_PATH, trimToLimit(existing + line), 'utf8');60
} catch61
{62
// Logging must never interfere with the request path.63
}64
}65
66
function logError (message, error = null, details = null)67
{68
if (process.env.NODE_ENV === 'test') return;69
70
const payload = details || {};71
if (error && !payload.stack)72
{73
payload.stack = error.stack || error.message || String(error);74
}75
76
appendLogLine(formatLogLine('ERROR', message, payload));77
}78
79
module.exports = {80
LOG_FILE_PATH,81
logError,82
};@@ -1171,9 +1171,11 @@ router.get('/video-stream-subtitle-frame', requireAuth, async (req, res, next) =
1171
1171
1172
1172
if (!frameData || frameData.length === 0)
1173
1173
{
1174
res.set('X-Subtitle-Frame-Status', 'none');
1174
1175
return res.status(204).end();
1175
1176
}
1176
1177
1178
res.set('X-Subtitle-Frame-Status', 'ok');
1177
1179
res.set('Content-Type', 'image/png');
1178
1180
res.set('Cache-Control', 'private, max-age=3600');
1179
1181
res.send(frameData);
@@ -1184,6 +1186,7 @@ router.get('/video-stream-subtitle-frame', requireAuth, async (req, res, next) =
1184
1186
streamIndex: Number.parseInt(String(req.query.streamIndex || ''), 10),
1185
1187
timeSeconds: Number.parseFloat(String(req.query.timeSeconds || ''), 10),
1186
1188
});
1189
res.set('X-Subtitle-Frame-Status', 'error');
1187
1190
return res.status(204).end();
1188
1191
}
1189
1192
});
@@ -1171,9 +1171,11 @@ router.get('/video-stream-subtitle-frame', requireAuth, async (req, res, next) =1171
1171
1172
if (!frameData || frameData.length === 0)1172
if (!frameData || frameData.length === 0)1173
{1173
{1174
res.set('X-Subtitle-Frame-Status', 'none');1174
return res.status(204).end();1175
return res.status(204).end();1175
}1176
}1176
1177
1178
res.set('X-Subtitle-Frame-Status', 'ok');1177
res.set('Content-Type', 'image/png');1179
res.set('Content-Type', 'image/png');1178
res.set('Cache-Control', 'private, max-age=3600');1180
res.set('Cache-Control', 'private, max-age=3600');1179
res.send(frameData);1181
res.send(frameData);@@ -1184,6 +1186,7 @@ router.get('/video-stream-subtitle-frame', requireAuth, async (req, res, next) =1184
streamIndex: Number.parseInt(String(req.query.streamIndex || ''), 10),1186
streamIndex: Number.parseInt(String(req.query.streamIndex || ''), 10),1185
timeSeconds: Number.parseFloat(String(req.query.timeSeconds || ''), 10),1187
timeSeconds: Number.parseFloat(String(req.query.timeSeconds || ''), 10),1186
});1188
});1189
res.set('X-Subtitle-Frame-Status', 'error');1187
return res.status(204).end();1190
return res.status(204).end();1188
}1191
}1189
});1192
});@@ -769,6 +769,10 @@ async function initialiseSession (session)
769
769
throw makeHttpError(400, 'File does not contain a video stream.');
770
770
}
771
771
772
const primaryVideoStream = streamInfo.video[0] || {};
773
session.videoWidth = parsePositiveNumber(primaryVideoStream.width);
774
session.videoHeight = parsePositiveNumber(primaryVideoStream.height);
775
772
776
const subtitleResult = await extractSubtitleTracks(session.sourcePath, session.outputDir, streamInfo.subtitles);
773
777
session.subtitleTracks = subtitleResult.tracks;
774
778
session.imageSubtitleTracks = subtitleResult.imageBasedTracks;
@@ -857,6 +861,8 @@ async function createVideoStreamSession (sourcePath)
857
861
return {
858
862
sessionId: lease.id,
859
863
durationSeconds: session.durationSeconds,
864
videoWidth: session.videoWidth || null,
865
videoHeight: session.videoHeight || null,
860
866
subtitleTracks: session.subtitleTracks.map((track) => ({ ...track })),
861
867
imageSubtitleTracks: (session.imageSubtitleTracks || []).map((track) => ({ ...track })),
862
868
subtitleSummary: {
@@ -769,6 +769,10 @@ async function initialiseSession (session)769
throw makeHttpError(400, 'File does not contain a video stream.');769
throw makeHttpError(400, 'File does not contain a video stream.');770
}770
}771
771
772
const primaryVideoStream = streamInfo.video[0] || {};773
session.videoWidth = parsePositiveNumber(primaryVideoStream.width);774
session.videoHeight = parsePositiveNumber(primaryVideoStream.height);775
772
const subtitleResult = await extractSubtitleTracks(session.sourcePath, session.outputDir, streamInfo.subtitles);776
const subtitleResult = await extractSubtitleTracks(session.sourcePath, session.outputDir, streamInfo.subtitles);773
session.subtitleTracks = subtitleResult.tracks;777
session.subtitleTracks = subtitleResult.tracks;774
session.imageSubtitleTracks = subtitleResult.imageBasedTracks;778
session.imageSubtitleTracks = subtitleResult.imageBasedTracks;@@ -857,6 +861,8 @@ async function createVideoStreamSession (sourcePath)857
return {861
return {858
sessionId: lease.id,862
sessionId: lease.id,859
durationSeconds: session.durationSeconds,863
durationSeconds: session.durationSeconds,864
videoWidth: session.videoWidth || null,865
videoHeight: session.videoHeight || null,860
subtitleTracks: session.subtitleTracks.map((track) => ({ ...track })),866
subtitleTracks: session.subtitleTracks.map((track) => ({ ...track })),861
imageSubtitleTracks: (session.imageSubtitleTracks || []).map((track) => ({ ...track })),867
imageSubtitleTracks: (session.imageSubtitleTracks || []).map((track) => ({ ...track })),862
subtitleSummary: {868
subtitleSummary: {@@ -839,21 +839,39 @@ describe('video streaming routes', () =>
839
839
840
840
expect(status).toBe(200);
841
841
expect(headers['content-type']).toMatch(/image\/png/);
842
expect(headers['x-subtitle-frame-status']).toBe('ok');
842
843
expect(body.equals(Buffer.from('png-data'))).toBe(true);
843
844
});
844
845
846
test('GET /api/files/video-stream-subtitle-frame returns 204 with none status when no subtitle is active', async () =>
847
{
848
const filePath = path.join(rootDir, 'clip.mkv');
849
fs.writeFileSync(filePath, 'video');
850
mockSubtitleFrameResult = null;
851
852
const { status, headers, body } = await reqRaw(
853
'GET',
854
`/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(filePath)}&streamIndex=0&timeSeconds=2.5`
855
);
856
857
expect(status).toBe(204);
858
expect(headers['x-subtitle-frame-status']).toBe('none');
859
expect(body.length).toBe(0);
860
});
861
845
862
test('GET /api/files/video-stream-subtitle-frame returns 204 when rendering fails', async () =>
846
863
{
847
864
const filePath = path.join(rootDir, 'clip.mkv');
848
865
fs.writeFileSync(filePath, 'video');
849
866
mockSubtitleFrameError = new Error('decode failed');
850
867
851
const { status, body } = await reqRaw(
868
const { status, headers, body } = await reqRaw(
852
869
'GET',
853
870
`/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(filePath)}&streamIndex=0&timeSeconds=2.5`
854
871
);
855
872
856
873
expect(status).toBe(204);
874
expect(headers['x-subtitle-frame-status']).toBe('error');
857
875
expect(body.length).toBe(0);
858
876
});
859
877
@@ -839,21 +839,39 @@ describe('video streaming routes', () =>839
839
840
expect(status).toBe(200);840
expect(status).toBe(200);841
expect(headers['content-type']).toMatch(/image\/png/);841
expect(headers['content-type']).toMatch(/image\/png/);842
expect(headers['x-subtitle-frame-status']).toBe('ok');842
expect(body.equals(Buffer.from('png-data'))).toBe(true);843
expect(body.equals(Buffer.from('png-data'))).toBe(true);843
});844
});844
845
846
test('GET /api/files/video-stream-subtitle-frame returns 204 with none status when no subtitle is active', async () =>847
{848
const filePath = path.join(rootDir, 'clip.mkv');849
fs.writeFileSync(filePath, 'video');850
mockSubtitleFrameResult = null;851
852
const { status, headers, body } = await reqRaw(853
'GET',854
`/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(filePath)}&streamIndex=0&timeSeconds=2.5`855
);856
857
expect(status).toBe(204);858
expect(headers['x-subtitle-frame-status']).toBe('none');859
expect(body.length).toBe(0);860
});861
845
test('GET /api/files/video-stream-subtitle-frame returns 204 when rendering fails', async () =>862
test('GET /api/files/video-stream-subtitle-frame returns 204 when rendering fails', async () =>846
{863
{847
const filePath = path.join(rootDir, 'clip.mkv');864
const filePath = path.join(rootDir, 'clip.mkv');848
fs.writeFileSync(filePath, 'video');865
fs.writeFileSync(filePath, 'video');849
mockSubtitleFrameError = new Error('decode failed');866
mockSubtitleFrameError = new Error('decode failed');850
867
851
const { status, body } = await reqRaw(868
const { status, headers, body } = await reqRaw(852
'GET',869
'GET',853
`/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(filePath)}&streamIndex=0&timeSeconds=2.5`870
`/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(filePath)}&streamIndex=0&timeSeconds=2.5`854
);871
);855
872
856
expect(status).toBe(204);873
expect(status).toBe(204);874
expect(headers['x-subtitle-frame-status']).toBe('error');857
expect(body.length).toBe(0);875
expect(body.length).toBe(0);858
});876
});859
877
@@ -80,7 +80,7 @@ describe('video stream bootstrap', () =>
80
80
child.stdout.emit('data', Buffer.from(JSON.stringify({
81
81
format: { duration: '12.5' },
82
82
streams: [
83
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
83
{ codec_type: 'video', codec_name: 'h264', width: 1920, height: 1080, tags: {}, disposition: {} },
84
84
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
85
85
],
86
86
})));
@@ -112,6 +112,8 @@ describe('video stream bootstrap', () =>
112
112
expect(session).toEqual({
113
113
sessionId: expect.any(String),
114
114
durationSeconds: 12.5,
115
videoWidth: 1920,
116
videoHeight: 1080,
115
117
subtitleTracks: [],
116
118
imageSubtitleTracks: [],
117
119
subtitleSummary: {
@@ -136,7 +138,7 @@ describe('video stream bootstrap', () =>
136
138
{
137
139
child.stdout.emit('data', Buffer.from(JSON.stringify({
138
140
streams: [
139
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
141
{ codec_type: 'video', codec_name: 'h264', width: 1280, height: 720, tags: {}, disposition: {} },
140
142
{ codec_type: 'audio', codec_name: 'aac', tags: { handler_name: 'SoundHandler' }, disposition: { default: 1 } },
141
143
],
142
144
})));
@@ -165,6 +167,8 @@ describe('video stream bootstrap', () =>
165
167
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({
166
168
sessionId: expect.any(String),
167
169
durationSeconds: null,
170
videoWidth: 1280,
171
videoHeight: 720,
168
172
subtitleTracks: [],
169
173
imageSubtitleTracks: [],
170
174
subtitleSummary: {
@@ -189,7 +193,7 @@ describe('video stream bootstrap', () =>
189
193
{
190
194
child.stdout.emit('data', Buffer.from(JSON.stringify({
191
195
streams: [
192
{ codec_type: 'video', codec_name: 'h264', tags: { DURATION: '00:22:17.500000000' }, disposition: {} },
196
{ codec_type: 'video', codec_name: 'h264', width: 640, height: 360, tags: { DURATION: '00:22:17.500000000' }, disposition: {} },
193
197
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
194
198
],
195
199
})));
@@ -228,7 +232,7 @@ describe('video stream bootstrap', () =>
228
232
{
229
233
child.stdout.emit('data', Buffer.from(JSON.stringify({
230
234
streams: [
231
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
235
{ codec_type: 'video', codec_name: 'h264', width: 1024, height: 576, tags: {}, disposition: {} },
232
236
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
233
237
{ codec_type: 'subtitle', codec_name: 'subrip', tags: { language: 'eng' }, disposition: {} },
234
238
],
@@ -276,6 +280,8 @@ describe('video stream bootstrap', () =>
276
280
expect(session).toEqual({
277
281
sessionId: expect.any(String),
278
282
durationSeconds: null,
283
videoWidth: 1024,
284
videoHeight: 576,
279
285
subtitleTracks: [
280
286
expect.objectContaining({
281
287
fileName: 'subtitle-0.vtt',
@@ -305,7 +311,7 @@ describe('video stream bootstrap', () =>
305
311
{
306
312
child.stdout.emit('data', Buffer.from(JSON.stringify({
307
313
streams: [
308
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },
314
{ codec_type: 'video', codec_name: 'h264', width: 1920, height: 1080, tags: {}, disposition: {} },
309
315
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },
310
316
{ codec_type: 'subtitle', codec_name: 'hdmv_pgs_subtitle', tags: { language: 'eng' }, disposition: {} },
311
317
],
@@ -344,6 +350,8 @@ describe('video stream bootstrap', () =>
344
350
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({
345
351
sessionId: expect.any(String),
346
352
durationSeconds: null,
353
videoWidth: 1920,
354
videoHeight: 1080,
347
355
subtitleTracks: [],
348
356
imageSubtitleTracks: [
349
357
expect.objectContaining({
@@ -80,7 +80,7 @@ describe('video stream bootstrap', () =>80
child.stdout.emit('data', Buffer.from(JSON.stringify({80
child.stdout.emit('data', Buffer.from(JSON.stringify({81
format: { duration: '12.5' },81
format: { duration: '12.5' },82
streams: [82
streams: [83
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },83
{ codec_type: 'video', codec_name: 'h264', width: 1920, height: 1080, tags: {}, disposition: {} },84
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },84
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },85
],85
],86
})));86
})));@@ -112,6 +112,8 @@ describe('video stream bootstrap', () =>112
expect(session).toEqual({112
expect(session).toEqual({113
sessionId: expect.any(String),113
sessionId: expect.any(String),114
durationSeconds: 12.5,114
durationSeconds: 12.5,115
videoWidth: 1920,116
videoHeight: 1080,115
subtitleTracks: [],117
subtitleTracks: [],116
imageSubtitleTracks: [],118
imageSubtitleTracks: [],117
subtitleSummary: {119
subtitleSummary: {@@ -136,7 +138,7 @@ describe('video stream bootstrap', () =>136
{138
{137
child.stdout.emit('data', Buffer.from(JSON.stringify({139
child.stdout.emit('data', Buffer.from(JSON.stringify({138
streams: [140
streams: [139
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },141
{ codec_type: 'video', codec_name: 'h264', width: 1280, height: 720, tags: {}, disposition: {} },140
{ codec_type: 'audio', codec_name: 'aac', tags: { handler_name: 'SoundHandler' }, disposition: { default: 1 } },142
{ codec_type: 'audio', codec_name: 'aac', tags: { handler_name: 'SoundHandler' }, disposition: { default: 1 } },141
],143
],142
})));144
})));@@ -165,6 +167,8 @@ describe('video stream bootstrap', () =>165
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({167
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({166
sessionId: expect.any(String),168
sessionId: expect.any(String),167
durationSeconds: null,169
durationSeconds: null,170
videoWidth: 1280,171
videoHeight: 720,168
subtitleTracks: [],172
subtitleTracks: [],169
imageSubtitleTracks: [],173
imageSubtitleTracks: [],170
subtitleSummary: {174
subtitleSummary: {@@ -189,7 +193,7 @@ describe('video stream bootstrap', () =>189
{193
{190
child.stdout.emit('data', Buffer.from(JSON.stringify({194
child.stdout.emit('data', Buffer.from(JSON.stringify({191
streams: [195
streams: [192
{ codec_type: 'video', codec_name: 'h264', tags: { DURATION: '00:22:17.500000000' }, disposition: {} },196
{ codec_type: 'video', codec_name: 'h264', width: 640, height: 360, tags: { DURATION: '00:22:17.500000000' }, disposition: {} },193
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },197
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },194
],198
],195
})));199
})));@@ -228,7 +232,7 @@ describe('video stream bootstrap', () =>228
{232
{229
child.stdout.emit('data', Buffer.from(JSON.stringify({233
child.stdout.emit('data', Buffer.from(JSON.stringify({230
streams: [234
streams: [231
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },235
{ codec_type: 'video', codec_name: 'h264', width: 1024, height: 576, tags: {}, disposition: {} },232
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },236
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },233
{ codec_type: 'subtitle', codec_name: 'subrip', tags: { language: 'eng' }, disposition: {} },237
{ codec_type: 'subtitle', codec_name: 'subrip', tags: { language: 'eng' }, disposition: {} },234
],238
],@@ -276,6 +280,8 @@ describe('video stream bootstrap', () =>276
expect(session).toEqual({280
expect(session).toEqual({277
sessionId: expect.any(String),281
sessionId: expect.any(String),278
durationSeconds: null,282
durationSeconds: null,283
videoWidth: 1024,284
videoHeight: 576,279
subtitleTracks: [285
subtitleTracks: [280
expect.objectContaining({286
expect.objectContaining({281
fileName: 'subtitle-0.vtt',287
fileName: 'subtitle-0.vtt',@@ -305,7 +311,7 @@ describe('video stream bootstrap', () =>305
{311
{306
child.stdout.emit('data', Buffer.from(JSON.stringify({312
child.stdout.emit('data', Buffer.from(JSON.stringify({307
streams: [313
streams: [308
{ codec_type: 'video', codec_name: 'h264', tags: {}, disposition: {} },314
{ codec_type: 'video', codec_name: 'h264', width: 1920, height: 1080, tags: {}, disposition: {} },309
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },315
{ codec_type: 'audio', codec_name: 'aac', tags: {}, disposition: { default: 1 } },310
{ codec_type: 'subtitle', codec_name: 'hdmv_pgs_subtitle', tags: { language: 'eng' }, disposition: {} },316
{ codec_type: 'subtitle', codec_name: 'hdmv_pgs_subtitle', tags: { language: 'eng' }, disposition: {} },311
],317
],@@ -344,6 +350,8 @@ describe('video stream bootstrap', () =>344
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({350
await expect(createVideoStreamSession(sourceFile)).resolves.toEqual({345
sessionId: expect.any(String),351
sessionId: expect.any(String),346
durationSeconds: null,352
durationSeconds: null,353
videoWidth: 1920,354
videoHeight: 1080,347
subtitleTracks: [],355
subtitleTracks: [],348
imageSubtitleTracks: [356
imageSubtitleTracks: [349
expect.objectContaining({357
expect.objectContaining({