BlueGit

timfa filemanager

Merge fix/subtitle-fullscreen-horizontal-centering

timfa Tim Falken · pushed by timfa

Authored 2026-05-18 · 6 months ago

Hash
df23f41c1e8cf68db9ed701eb191717104ca603d
3 files changed +24 −5
.github/technical-reference.md +1 −1
@@ -10,7 +10,7 @@
10 10 - logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
11 11
12 12 ## server/image-subtitles.js
13 - parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing; canvas is capped at 1280x720 to bound subtitle frame memory/CPU cost.
13 - parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing; canvas is scaled down within a 1280x720 ceiling while preserving requested aspect ratio to keep subtitle placement stable in fullscreen.
14 14 - renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
15 15 - clearCachesForFile(filePath) - Removes all event and frame cache entries for a given file path using path-prefixed cache keys and byte-accounted eviction; called when video stream sessions end to prevent memory accumulation.
16 16 - pruneOldImageSubtitleCaches(filePath, slowestViewerTimeSeconds) - Drops subtitle frame caches for events that have passed their retention threshold of end time + event duration + 5 seconds (e.g., event ending at 30s with 10s duration is dropped after slowest viewer reaches 45s); used during segment pruning to keep memory usage bounded on long videos, especially on resource-limited hardware like Raspberry Pi.
@@ -10,7 +10,7 @@
10- logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
10- logError(message, error, details) - Appends error lines to logs.txt, trimming old lines so the file stays under 1 MB; use for route failures and process-level exceptions.
11
11
12## server/image-subtitles.js
12## server/image-subtitles.js
13- parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing; canvas is capped at 1280x720 to bound subtitle frame memory/CPU cost.
13- parseRenderOptions(options) - Normalises subtitle-frame request options and validates filePath/streamIndex/time/canvas dimensions; stream index `0` is valid and must not be treated as missing; canvas is scaled down within a 1280x720 ceiling while preserving requested aspect ratio to keep subtitle placement stable in fullscreen.
14- renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
14- renderImageSubtitleFrame({ filePath, streamIndex, timeSeconds, canvasWidth, canvasHeight }) - Extracts bitmap subtitle streams to cached `.sup`, parses PGS display sets, and returns cached/composited PNG subtitle frames for a requested timestamp; returns null when no subtitle is active.
15- clearCachesForFile(filePath) - Removes all event and frame cache entries for a given file path using path-prefixed cache keys and byte-accounted eviction; called when video stream sessions end to prevent memory accumulation.
15- clearCachesForFile(filePath) - Removes all event and frame cache entries for a given file path using path-prefixed cache keys and byte-accounted eviction; called when video stream sessions end to prevent memory accumulation.
16- pruneOldImageSubtitleCaches(filePath, slowestViewerTimeSeconds) - Drops subtitle frame caches for events that have passed their retention threshold of end time + event duration + 5 seconds (e.g., event ending at 30s with 10s duration is dropped after slowest viewer reaches 45s); used during segment pruning to keep memory usage bounded on long videos, especially on resource-limited hardware like Raspberry Pi.
16- pruneOldImageSubtitleCaches(filePath, slowestViewerTimeSeconds) - Drops subtitle frame caches for events that have passed their retention threshold of end time + event duration + 5 seconds (e.g., event ending at 30s with 10s duration is dropped after slowest viewer reaches 45s); used during segment pruning to keep memory usage bounded on long videos, especially on resource-limited hardware like Raspberry Pi.
server/image-subtitles.js +5 −2
@@ -462,8 +462,11 @@ function parseRenderOptions (options)
462 462 const filePath = String(input.filePath ?? '').trim();
463 463 const streamIndex = Number.parseInt(String(input.streamIndex ?? ''), 10);
464 464 const timeSeconds = Number.parseFloat(String(input.timeSeconds ?? ''), 10);
465 const canvasWidth = Math.max(1, Math.min(1280, toPositiveInt(input.canvasWidth ?? '', 1280)));
466 const canvasHeight = Math.max(1, Math.min(720, toPositiveInt(input.canvasHeight ?? '', 720)));
465 const requestedWidth = Math.max(1, toPositiveInt(input.canvasWidth ?? '', 1280));
466 const requestedHeight = Math.max(1, toPositiveInt(input.canvasHeight ?? '', 720));
467 const scale = Math.min(1, 1280 / requestedWidth, 720 / requestedHeight);
468 const canvasWidth = Math.max(1, Math.round(requestedWidth * scale));
469 const canvasHeight = Math.max(1, Math.round(requestedHeight * scale));
467 470
468 471 return {
469 472 filePath,
@@ -462,8 +462,11 @@ function parseRenderOptions (options)
462 const filePath = String(input.filePath ?? '').trim();
462 const filePath = String(input.filePath ?? '').trim();
463 const streamIndex = Number.parseInt(String(input.streamIndex ?? ''), 10);
463 const streamIndex = Number.parseInt(String(input.streamIndex ?? ''), 10);
464 const timeSeconds = Number.parseFloat(String(input.timeSeconds ?? ''), 10);
464 const timeSeconds = Number.parseFloat(String(input.timeSeconds ?? ''), 10);
465 const canvasWidth = Math.max(1, Math.min(1280, toPositiveInt(input.canvasWidth ?? '', 1280)));
465 const requestedWidth = Math.max(1, toPositiveInt(input.canvasWidth ?? '', 1280));
466 const canvasHeight = Math.max(1, Math.min(720, toPositiveInt(input.canvasHeight ?? '', 720)));
466 const requestedHeight = Math.max(1, toPositiveInt(input.canvasHeight ?? '', 720));
467 const scale = Math.min(1, 1280 / requestedWidth, 720 / requestedHeight);
468 const canvasWidth = Math.max(1, Math.round(requestedWidth * scale));
469 const canvasHeight = Math.max(1, Math.round(requestedHeight * scale));
467
470
468 return {
471 return {
469 filePath,
472 filePath,
tests/image-subtitles.test.js +18 −2
@@ -30,7 +30,7 @@ describe('image subtitle option parsing', () =>
30 30 expect(parsed.isValid).toBe(false);
31 31 });
32 32
33 test('caps subtitle render canvas to 1280x720', () =>
33 test('caps subtitle render canvas within 1280x720 bounds', () =>
34 34 {
35 35 const parsed = parseRenderOptions({
36 36 filePath: '/tmp/example.mkv',
@@ -41,7 +41,23 @@ describe('image subtitle option parsing', () =>
41 41 });
42 42
43 43 expect(parsed.canvasWidth).toBe(1280);
44 expect(parsed.canvasHeight).toBe(720);
44 expect(parsed.canvasHeight).toBe(675);
45 expect(parsed.canvasWidth).toBeLessThanOrEqual(1280);
46 expect(parsed.canvasHeight).toBeLessThanOrEqual(720);
47 });
48
49 test('preserves requested aspect ratio when canvas is capped', () =>
50 {
51 const parsed = parseRenderOptions({
52 filePath: '/tmp/example.mkv',
53 streamIndex: 0,
54 timeSeconds: 5,
55 canvasWidth: 3840,
56 canvasHeight: 1600,
57 });
58
59 expect(parsed.canvasWidth).toBe(1280);
60 expect(parsed.canvasHeight).toBe(533);
45 61 });
46 62
47 63 test('prune calculates drop threshold as end plus duration plus 5 seconds', () =>
@@ -30,7 +30,7 @@ describe('image subtitle option parsing', () =>
30 expect(parsed.isValid).toBe(false);
30 expect(parsed.isValid).toBe(false);
31 });
31 });
32
32
33 test('caps subtitle render canvas to 1280x720', () =>
33 test('caps subtitle render canvas within 1280x720 bounds', () =>
34 {
34 {
35 const parsed = parseRenderOptions({
35 const parsed = parseRenderOptions({
36 filePath: '/tmp/example.mkv',
36 filePath: '/tmp/example.mkv',
@@ -41,7 +41,23 @@ describe('image subtitle option parsing', () =>
41 });
41 });
42
42
43 expect(parsed.canvasWidth).toBe(1280);
43 expect(parsed.canvasWidth).toBe(1280);
44 expect(parsed.canvasHeight).toBe(720);
44 expect(parsed.canvasHeight).toBe(675);
45 expect(parsed.canvasWidth).toBeLessThanOrEqual(1280);
46 expect(parsed.canvasHeight).toBeLessThanOrEqual(720);
47 });
48
49 test('preserves requested aspect ratio when canvas is capped', () =>
50 {
51 const parsed = parseRenderOptions({
52 filePath: '/tmp/example.mkv',
53 streamIndex: 0,
54 timeSeconds: 5,
55 canvasWidth: 3840,
56 canvasHeight: 1600,
57 });
58
59 expect(parsed.canvasWidth).toBe(1280);
60 expect(parsed.canvasHeight).toBe(533);
45 });
61 });
46
62
47 test('prune calculates drop threshold as end plus duration plus 5 seconds', () =>
63 test('prune calculates drop threshold as end plus duration plus 5 seconds', () =>