BlueGit

timfa filemanager

Merge feat/subtitle-walker-larger-step

timfa Tim Falken · pushed by timfa

Authored 2026-05-27 · 5 months ago

Hash
8c62bee0ab57bca56e0a605e97bca37efa0675f1
5 files changed +55 −9
.github/technical-reference.md +3 −3
@@ -199,14 +199,14 @@
199 199 - Standalone public share page served at /share/:token; no auth required.
200 200 - Timer bar - Live HH:MM:SS countdown showing remaining validity; turns red and disables download when expired.
201 201 - tryPreview(name, isDir) - Renders inline preview (img/video/audio/text pre); no-op for unsupported types or directories.
202 - Share video preview - Uses the shared browser video-player helper used by app previews: VOD UI enforcement, long forward buffer, forced caption overrides (text background opacity transparent + text edge style uniform), subtitle/audio track restore/save by matching track names, image-subtitle overlay support, background stream-ahead prefetch (session playlist/variant/segment fetches continue towards video end while playback reads cache), seek-bar cache frontier marker (`:`) for walker progress, service-worker-backed HLS segment cache enablement during playback (with per-session cache cleanup on close), and explicit backend session release on unload.
202 - Share video preview - Uses the shared browser video-player helper used by app previews: VOD UI enforcement, long forward buffer, forced caption overrides (text background opacity transparent + text edge style uniform), subtitle/audio track restore/save by matching track names, image-subtitle overlay support (configured with a 2-second subtitle prefetch stride to reduce walker request volume), background stream-ahead prefetch (session playlist/variant/segment fetches continue towards video end while playback reads cache), seek-bar cache frontier marker (`:`) for walker progress, service-worker-backed HLS segment cache enablement during playback (with per-session cache cleanup on close), and explicit backend session release on unload.
203 203 - Fetches /api/share/info/:token on load; shows error state for 404/410 responses.
204 204 - Download link points to /api/share/download/:token; labelled "Download als .zip" for directories.
205 205
206 206 ## public/shared-video-player.js
207 207 - applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
208 208 - bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
209 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
209 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports configurable prefetch stride (`prefetchStepSeconds`, default 0.5s, capped at 5s) to trade subtitle walker request volume vs sampling density, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
210 210 - bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
211 211 - bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
212 212 - bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
@@ -295,7 +295,7 @@
295 295 - buildAuthHeaders() - Builds the authenticated fetch headers used by preview-side API calls that need the bearer token plus fingerprint header.
296 296 - renderStreamedVideoPreview(item) - For authenticated video previews, creates a backend stream session and starts the background stream-ahead prefetch worker so playlist/segment requests can continue independently of playback reads until cleanup.
297 297 - bindImageSubtitleOverlay(player, videojs, prefs, session, item) - Adds the fullscreen-safe image-subtitle button, menu, and bottom overlay used to fetch and display subtitle frames for image-based tracks; keeps subtitle bitmaps horizontally centred at the bottom, highlights the currently selected IM menu option, persists per-user image subtitle stream index + track name, restores by saved track name first (then stream index), batches subtitle timing diagnostics to `/api/files/video-stream-subtitle-log`, and reads X-Subtitle-Frame-* headers from server responses to properly upscale downscaled frames while maintaining proportions.
298 - renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enables service-worker-backed HLS segment caching for the active stream session (and clears that cache on close), enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), wires the image-subtitle overlay controller, forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, releases the backend stream session on close/unload, and uses a preview initialisation token guard so stale async player/walker setup from a previously closed preview is discarded immediately.
298 - renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enables service-worker-backed HLS segment caching for the active stream session (and clears that cache on close), enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), wires the image-subtitle overlay controller, forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, releases the backend stream session on close/unload, uses a preview initialisation token guard so stale async player/walker setup from a previously closed preview is discarded immediately, and configures image-subtitle walker stride to 2 seconds in app playback.
299 299 - modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
300 300 - loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
301 301 - modelThumbnailDataUrl(item, blob) - Builds a blue SVG thumbnail for STL/OBJ files by parsing their geometry client-side; falls back to a badge when parsing fails.
@@ -199,14 +199,14 @@
199- Standalone public share page served at /share/:token; no auth required.
199- Standalone public share page served at /share/:token; no auth required.
200- Timer bar - Live HH:MM:SS countdown showing remaining validity; turns red and disables download when expired.
200- Timer bar - Live HH:MM:SS countdown showing remaining validity; turns red and disables download when expired.
201- tryPreview(name, isDir) - Renders inline preview (img/video/audio/text pre); no-op for unsupported types or directories.
201- tryPreview(name, isDir) - Renders inline preview (img/video/audio/text pre); no-op for unsupported types or directories.
202- Share video preview - Uses the shared browser video-player helper used by app previews: VOD UI enforcement, long forward buffer, forced caption overrides (text background opacity transparent + text edge style uniform), subtitle/audio track restore/save by matching track names, image-subtitle overlay support, background stream-ahead prefetch (session playlist/variant/segment fetches continue towards video end while playback reads cache), seek-bar cache frontier marker (`:`) for walker progress, service-worker-backed HLS segment cache enablement during playback (with per-session cache cleanup on close), and explicit backend session release on unload.
202- Share video preview - Uses the shared browser video-player helper used by app previews: VOD UI enforcement, long forward buffer, forced caption overrides (text background opacity transparent + text edge style uniform), subtitle/audio track restore/save by matching track names, image-subtitle overlay support (configured with a 2-second subtitle prefetch stride to reduce walker request volume), background stream-ahead prefetch (session playlist/variant/segment fetches continue towards video end while playback reads cache), seek-bar cache frontier marker (`:`) for walker progress, service-worker-backed HLS segment cache enablement during playback (with per-session cache cleanup on close), and explicit backend session release on unload.
203- Fetches /api/share/info/:token on load; shows error state for 404/410 responses.
203- Fetches /api/share/info/:token on load; shows error state for 404/410 responses.
204- Download link points to /api/share/download/:token; labelled "Download als .zip" for directories.
204- Download link points to /api/share/download/:token; labelled "Download als .zip" for directories.
205
205
206## public/shared-video-player.js
206## public/shared-video-player.js
207- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
207- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
208- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
208- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
209- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
209- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), supports cache-only foreground playback with `currentFetchEnabled: false` (foreground uses cached frames while walker owns server fetches), supports startup warmup with `initialPrefetchSeconds` (default 60s) so early timeline subtitle frames are requested immediately on player load before playback advances, supports configurable prefetch stride (`prefetchStepSeconds`, default 0.5s, capped at 5s) to trade subtitle walker request volume vs sampling density, extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), merges buffered-end signals from both Video.js/player APIs and underlying media buffered ranges so under-reported player values do not cap subtitle prefetch early, keeps the prefetch frontier pinned to at least current playback time so it chases buffered-ahead range instead of replaying stale lag after video/session changes, coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, caches received subtitle PNG frames client-side for the lifetime of the player session (including prefetched frames) so rewind playback can render from local cache even after server-side purge, ensures force-seek aborts still clear in-flight current-request state so subtitle refreshes continue instead of deadlocking, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), keeps both marker positions forward-only (never regressing to earlier times), allows the two bracket glyphs to overlap naturally when positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
210- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
210- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Cache-frame time matching now uses a small epsilon window around start/end timestamps to avoid boundary misses; cache-only mode can also perform a throttled direct current-frame fallback fetch on cache miss (`cacheMissFallbackEnabled`, `cacheMissFallbackIntervalMs`) so subtitles recover without waiting for another seek/timeupdate cycle, fallback fetches preserve prefetch progress so repeated cache misses do not keep resetting subtitle lookahead, and duration metadata hints now extend lookahead prefetch to the known video end even before playback advances.
211- bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
211- bindStreamAheadPrefetch(opts) - Starts a background HLS walker that repeatedly fetches the session playlist, discovers variant playlists and media segments, and prefetches those assets into the browser cache so playback can read already-fetched segments while the backend prunes old files; tracks cached-through timeline progress (primary from playlist segment durations, with filename-based segment-index fallback for `.ts/.m4s` naming and a section-ratio fallback from fetched segments/total discovered segments when absolute timing metadata is missing) and returns a controller with stop()/done()/getStatus()/subscribe().
212- bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
212- bindStreamAheadSeekMarker(player, streamAheadPrefetch, opts) - Renders a non-interactive `:` marker on the playback seek bar showing how far the stream-ahead walker has cached through the timeline; subscribes to walker progress updates, updates tooltip text with formatted cached-through time, and removes itself on detach.
@@ -295,7 +295,7 @@
295- buildAuthHeaders() - Builds the authenticated fetch headers used by preview-side API calls that need the bearer token plus fingerprint header.
295- buildAuthHeaders() - Builds the authenticated fetch headers used by preview-side API calls that need the bearer token plus fingerprint header.
296- renderStreamedVideoPreview(item) - For authenticated video previews, creates a backend stream session and starts the background stream-ahead prefetch worker so playlist/segment requests can continue independently of playback reads until cleanup.
296- renderStreamedVideoPreview(item) - For authenticated video previews, creates a backend stream session and starts the background stream-ahead prefetch worker so playlist/segment requests can continue independently of playback reads until cleanup.
297- bindImageSubtitleOverlay(player, videojs, prefs, session, item) - Adds the fullscreen-safe image-subtitle button, menu, and bottom overlay used to fetch and display subtitle frames for image-based tracks; keeps subtitle bitmaps horizontally centred at the bottom, highlights the currently selected IM menu option, persists per-user image subtitle stream index + track name, restores by saved track name first (then stream index), batches subtitle timing diagnostics to `/api/files/video-stream-subtitle-log`, and reads X-Subtitle-Frame-* headers from server responses to properly upscale downscaled frames while maintaining proportions.
297- bindImageSubtitleOverlay(player, videojs, prefs, session, item) - Adds the fullscreen-safe image-subtitle button, menu, and bottom overlay used to fetch and display subtitle frames for image-based tracks; keeps subtitle bitmaps horizontally centred at the bottom, highlights the currently selected IM menu option, persists per-user image subtitle stream index + track name, restores by saved track name first (then stream index), batches subtitle timing diagnostics to `/api/files/video-stream-subtitle-log`, and reads X-Subtitle-Frame-* headers from server responses to properly upscale downscaled frames while maintaining proportions.
298- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enables service-worker-backed HLS segment caching for the active stream session (and clears that cache on close), enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), wires the image-subtitle overlay controller, forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, releases the backend stream session on close/unload, and uses a preview initialisation token guard so stale async player/walker setup from a previously closed preview is discarded immediately.
298- renderStreamedVideoPreview(item, targetEl) - Creates the Video.js player with HLS source/track config, enables service-worker-backed HLS segment caching for the active stream session (and clears that cache on close), enforces non-live playback UI for file streams, uses container-fill sizing to keep previews within bounds, restores per-user video prefs (volume + subtitle/audio track names when present), wires the image-subtitle overlay controller, forces caption overrides on each open (text background opacity transparent + text edge style uniform), reports watch progress, warns when subtitle streams exist but none are web-compatible, releases the backend stream session on close/unload, uses a preview initialisation token guard so stale async player/walker setup from a previously closed preview is discarded immediately, and configures image-subtitle walker stride to 2 seconds in app playback.
299- modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
299- modelPreviewType(name) - Classifies direct client-side 3D preview support for `.stl` and `.obj`.
300- loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
300- loadThreePreviewModules() - Lazy-loads Three.js plus OrbitControls/STLLoader/OBJLoader via import map aliases.
301- modelThumbnailDataUrl(item, blob) - Builds a blue SVG thumbnail for STL/OBJ files by parsing their geometry client-side; falls back to a badge when parsing fails.
301- modelThumbnailDataUrl(item, blob) - Builds a blue SVG thumbnail for STL/OBJ files by parsing their geometry client-side; falls back to a badge when parsing fails.
public/app.js +2 −0
@@ -116,6 +116,7 @@ const VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED = false;
116 116 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
117 117 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
118 118 const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
119 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 2;
119 120 let videoJsLoaderPromise = null;
120 121 let threePreviewModulesPromise = null;
121 122
@@ -435,6 +436,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
435 436 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
436 437 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
437 438 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
439 prefetchStepSeconds: IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS,
438 440 sendSubtitleLogBatch,
439 441 buildFrameRequest: ({ currentTime, streamIndex, session: activeSession }) => ({
440 442 url: `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${streamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}&videoWidth=${encodeURIComponent(String(activeSession.videoWidth || ''))}&videoHeight=${encodeURIComponent(String(activeSession.videoHeight || ''))}`,
@@ -116,6 +116,7 @@ const VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED = false;
116const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
116const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
117const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
117const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
118const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
118const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
119const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 2;
119let videoJsLoaderPromise = null;
120let videoJsLoaderPromise = null;
120let threePreviewModulesPromise = null;
121let threePreviewModulesPromise = null;
121
122
@@ -435,6 +436,7 @@ function bindImageSubtitleOverlay (player, videojs, prefs, session, item)
435 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
436 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
436 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
437 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
437 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
438 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
439 prefetchStepSeconds: IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS,
438 sendSubtitleLogBatch,
440 sendSubtitleLogBatch,
439 buildFrameRequest: ({ currentTime, streamIndex, session: activeSession }) => ({
441 buildFrameRequest: ({ currentTime, streamIndex, session: activeSession }) => ({
440 url: `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${streamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}&videoWidth=${encodeURIComponent(String(activeSession.videoWidth || ''))}&videoHeight=${encodeURIComponent(String(activeSession.videoHeight || ''))}`,
442 url: `/api/files/video-stream-subtitle-frame?filePath=${encodeURIComponent(item.path)}&streamIndex=${streamIndex}&timeSeconds=${encodeURIComponent(String(currentTime))}&videoWidth=${encodeURIComponent(String(activeSession.videoWidth || ''))}&videoHeight=${encodeURIComponent(String(activeSession.videoHeight || ''))}`,
public/share.html +2 −0
@@ -252,6 +252,7 @@
252 252 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
253 253 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
254 254 const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
255 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 2;
255 256 const SHARE_VIDEO_PREFS_KEY = 'filemanager.share-video-prefs.v1';
256 257 let expiresAt = null;
257 258 let timerInterval = null;
@@ -511,6 +512,7 @@
511 512 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
512 513 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
513 514 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
515 prefetchStepSeconds: IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS,
514 516 sendSubtitleLogBatch: (entries) =>
515 517 {
516 518 if (!Array.isArray(entries) || !entries.length) return Promise.resolve();
@@ -252,6 +252,7 @@
252 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
252 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS = 15;
253 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
253 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS = 60;
254 const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
254 const IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS = 40;
255 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 2;
255 const SHARE_VIDEO_PREFS_KEY = 'filemanager.share-video-prefs.v1';
256 const SHARE_VIDEO_PREFS_KEY = 'filemanager.share-video-prefs.v1';
256 let expiresAt = null;
257 let expiresAt = null;
257 let timerInterval = null;
258 let timerInterval = null;
@@ -511,6 +512,7 @@
511 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
512 lookaheadSeconds: IMAGE_SUBTITLE_LOOKAHEAD_SECONDS,
512 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
513 initialPrefetchSeconds: IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS,
513 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
514 prefetchRequestIntervalMs: IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS,
515 prefetchStepSeconds: IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS,
514 sendSubtitleLogBatch: (entries) =>
516 sendSubtitleLogBatch: (entries) =>
515 {
517 {
516 if (!Array.isArray(entries) || !entries.length) return Promise.resolve();
518 if (!Array.isArray(entries) || !entries.length) return Promise.resolve();
public/shared-video-player.js +11 −6
@@ -13,7 +13,8 @@
13 13 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS_MAX = 30;
14 14 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_DEFAULT = 60;
15 15 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_MAX = 120;
16 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 0.5;
16 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_DEFAULT = 0.5;
17 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_MAX = 5;
17 18 const IMAGE_SUBTITLE_TIME_MATCH_EPSILON_SECONDS = 0.05;
18 19 const IMAGE_SUBTITLE_CACHE_MISS_FALLBACK_INTERVAL_MS_DEFAULT = 2000;
19 20 const IMAGE_SUBTITLE_CURRENT_REQUEST_TIMEOUT_MS_DEFAULT = 4000;
@@ -305,6 +306,10 @@
305 306 const prefetchRequestIntervalMs = Number.isFinite(requestedPrefetchRequestIntervalMs)
306 307 ? Math.max(0, requestedPrefetchRequestIntervalMs)
307 308 : IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS_DEFAULT;
309 const requestedPrefetchStepSeconds = Number(opts.prefetchStepSeconds);
310 const prefetchStepSeconds = Number.isFinite(requestedPrefetchStepSeconds)
311 ? Math.max(0.25, Math.min(IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_MAX, requestedPrefetchStepSeconds))
312 : IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_DEFAULT;
308 313 const requestedCacheMissFallbackIntervalMs = Number(opts.cacheMissFallbackIntervalMs);
309 314 const cacheMissFallbackIntervalMs = Number.isFinite(requestedCacheMissFallbackIntervalMs)
310 315 ? Math.max(500, requestedCacheMissFallbackIntervalMs)
@@ -511,7 +516,7 @@
511 516 const rawEnd = parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time');
512 517 const endTimeSeconds = Number.isFinite(rawEnd)
513 518 ? rawEnd
514 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS : null);
519 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + prefetchStepSeconds : null);
515 520
516 521 const frameWidth = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Width') || ''), 10);
517 522 const frameHeight = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Height') || ''), 10);
@@ -543,7 +548,7 @@
543 548 const startTimeSeconds = Number.isFinite(metadata && metadata.startTimeSeconds) ? metadata.startTimeSeconds : null;
544 549 const endTimeSeconds = Number.isFinite(metadata && metadata.endTimeSeconds)
545 550 ? metadata.endTimeSeconds
546 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS : null);
551 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + prefetchStepSeconds : null);
547 552 if (!Number.isFinite(startTimeSeconds) || !Number.isFinite(endTimeSeconds) || endTimeSeconds <= startTimeSeconds)
548 553 {
549 554 return null;
@@ -902,7 +907,7 @@
902 907
903 908 const startTime = includeCurrentTime
904 909 ? currentTime
905 : currentTime + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS;
910 : currentTime + prefetchStepSeconds;
906 911 const uncappedEndTime = Math.max(
907 912 currentTime + lookaheadSeconds,
908 913 Number.isFinite(bufferedVideoEndSeconds) ? bufferedVideoEndSeconds : -1,
@@ -920,7 +925,7 @@
920 925 {
921 926 cancelPrefetchRequests({ resetProgress: true });
922 927 prefetchedThroughTimeSeconds = includeCurrentTime
923 ? currentTime - IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS
928 ? currentTime - prefetchStepSeconds
924 929 : currentTime;
925 930 } else if (prefetchedThroughTimeSeconds < currentTime)
926 931 {
@@ -946,7 +951,7 @@
946 951
947 952 const nextTime = prefetchedThroughTimeSeconds < 0
948 953 ? startTime
949 : prefetchedThroughTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS;
954 : prefetchedThroughTimeSeconds + prefetchStepSeconds;
950 955 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
951 956
952 957 const request = buildFrameRequest({
@@ -13,7 +13,8 @@
13 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS_MAX = 30;
13 const IMAGE_SUBTITLE_LOOKAHEAD_SECONDS_MAX = 30;
14 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_DEFAULT = 60;
14 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_DEFAULT = 60;
15 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_MAX = 120;
15 const IMAGE_SUBTITLE_INITIAL_PREFETCH_SECONDS_MAX = 120;
16 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS = 0.5;
16 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_DEFAULT = 0.5;
17 const IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_MAX = 5;
17 const IMAGE_SUBTITLE_TIME_MATCH_EPSILON_SECONDS = 0.05;
18 const IMAGE_SUBTITLE_TIME_MATCH_EPSILON_SECONDS = 0.05;
18 const IMAGE_SUBTITLE_CACHE_MISS_FALLBACK_INTERVAL_MS_DEFAULT = 2000;
19 const IMAGE_SUBTITLE_CACHE_MISS_FALLBACK_INTERVAL_MS_DEFAULT = 2000;
19 const IMAGE_SUBTITLE_CURRENT_REQUEST_TIMEOUT_MS_DEFAULT = 4000;
20 const IMAGE_SUBTITLE_CURRENT_REQUEST_TIMEOUT_MS_DEFAULT = 4000;
@@ -305,6 +306,10 @@
305 const prefetchRequestIntervalMs = Number.isFinite(requestedPrefetchRequestIntervalMs)
306 const prefetchRequestIntervalMs = Number.isFinite(requestedPrefetchRequestIntervalMs)
306 ? Math.max(0, requestedPrefetchRequestIntervalMs)
307 ? Math.max(0, requestedPrefetchRequestIntervalMs)
307 : IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS_DEFAULT;
308 : IMAGE_SUBTITLE_PREFETCH_REQUEST_INTERVAL_MS_DEFAULT;
309 const requestedPrefetchStepSeconds = Number(opts.prefetchStepSeconds);
310 const prefetchStepSeconds = Number.isFinite(requestedPrefetchStepSeconds)
311 ? Math.max(0.25, Math.min(IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_MAX, requestedPrefetchStepSeconds))
312 : IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS_DEFAULT;
308 const requestedCacheMissFallbackIntervalMs = Number(opts.cacheMissFallbackIntervalMs);
313 const requestedCacheMissFallbackIntervalMs = Number(opts.cacheMissFallbackIntervalMs);
309 const cacheMissFallbackIntervalMs = Number.isFinite(requestedCacheMissFallbackIntervalMs)
314 const cacheMissFallbackIntervalMs = Number.isFinite(requestedCacheMissFallbackIntervalMs)
310 ? Math.max(500, requestedCacheMissFallbackIntervalMs)
315 ? Math.max(500, requestedCacheMissFallbackIntervalMs)
@@ -511,7 +516,7 @@
511 const rawEnd = parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time');
516 const rawEnd = parseHeaderFloat(res, 'X-Subtitle-Frame-End-Time');
512 const endTimeSeconds = Number.isFinite(rawEnd)
517 const endTimeSeconds = Number.isFinite(rawEnd)
513 ? rawEnd
518 ? rawEnd
514 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS : null);
519 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + prefetchStepSeconds : null);
515
520
516 const frameWidth = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Width') || ''), 10);
521 const frameWidth = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Width') || ''), 10);
517 const frameHeight = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Height') || ''), 10);
522 const frameHeight = Number.parseInt(String(res.headers.get('X-Subtitle-Frame-Height') || ''), 10);
@@ -543,7 +548,7 @@
543 const startTimeSeconds = Number.isFinite(metadata && metadata.startTimeSeconds) ? metadata.startTimeSeconds : null;
548 const startTimeSeconds = Number.isFinite(metadata && metadata.startTimeSeconds) ? metadata.startTimeSeconds : null;
544 const endTimeSeconds = Number.isFinite(metadata && metadata.endTimeSeconds)
549 const endTimeSeconds = Number.isFinite(metadata && metadata.endTimeSeconds)
545 ? metadata.endTimeSeconds
550 ? metadata.endTimeSeconds
546 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS : null);
551 : (Number.isFinite(startTimeSeconds) ? startTimeSeconds + prefetchStepSeconds : null);
547 if (!Number.isFinite(startTimeSeconds) || !Number.isFinite(endTimeSeconds) || endTimeSeconds <= startTimeSeconds)
552 if (!Number.isFinite(startTimeSeconds) || !Number.isFinite(endTimeSeconds) || endTimeSeconds <= startTimeSeconds)
548 {
553 {
549 return null;
554 return null;
@@ -902,7 +907,7 @@
902
907
903 const startTime = includeCurrentTime
908 const startTime = includeCurrentTime
904 ? currentTime
909 ? currentTime
905 : currentTime + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS;
910 : currentTime + prefetchStepSeconds;
906 const uncappedEndTime = Math.max(
911 const uncappedEndTime = Math.max(
907 currentTime + lookaheadSeconds,
912 currentTime + lookaheadSeconds,
908 Number.isFinite(bufferedVideoEndSeconds) ? bufferedVideoEndSeconds : -1,
913 Number.isFinite(bufferedVideoEndSeconds) ? bufferedVideoEndSeconds : -1,
@@ -920,7 +925,7 @@
920 {
925 {
921 cancelPrefetchRequests({ resetProgress: true });
926 cancelPrefetchRequests({ resetProgress: true });
922 prefetchedThroughTimeSeconds = includeCurrentTime
927 prefetchedThroughTimeSeconds = includeCurrentTime
923 ? currentTime - IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS
928 ? currentTime - prefetchStepSeconds
924 : currentTime;
929 : currentTime;
925 } else if (prefetchedThroughTimeSeconds < currentTime)
930 } else if (prefetchedThroughTimeSeconds < currentTime)
926 {
931 {
@@ -946,7 +951,7 @@
946
951
947 const nextTime = prefetchedThroughTimeSeconds < 0
952 const nextTime = prefetchedThroughTimeSeconds < 0
948 ? startTime
953 ? startTime
949 : prefetchedThroughTimeSeconds + IMAGE_SUBTITLE_PREFETCH_STEP_SECONDS;
954 : prefetchedThroughTimeSeconds + prefetchStepSeconds;
950 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
955 if (!Number.isFinite(nextTime) || nextTime > prefetchTargetTimeSeconds + 1e-6) return;
951
956
952 const request = buildFrameRequest({
957 const request = buildFrameRequest({
tests/shared-video-player.test.js +37 −0
@@ -304,6 +304,43 @@ describe('shared image subtitle prefetching', () =>
304 304 window.close();
305 305 });
306 306
307 test('prefetch respects configured larger prefetch step size', async () =>
308 {
309 const window = createWindow();
310 const helper = loadSharedVideoPlayer(window);
311 const { player, videojs } = buildPlayerHarness(window);
312 const requestedTimes = [];
313
314 player.duration(6);
315
316 window.fetch = jest.fn(async (url) =>
317 {
318 const parsed = new URL(url, 'http://localhost/');
319 requestedTimes.push(Number(parsed.searchParams.get('timeSeconds')));
320 return new Response(null, {
321 status: 204,
322 headers: { 'X-Subtitle-Frame-Status': 'none' },
323 });
324 });
325
326 helper.bindImageSubtitleOverlay(player, videojs, {}, {
327 imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
328 }, {
329 lookaheadSeconds: 0,
330 initialPrefetchSeconds: 0,
331 prefetchStepSeconds: 2,
332 buildFrameRequest: ({ currentTime, streamIndex }) => ({
333 url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
334 }),
335 });
336
337 await flushAsyncWork(window, 14);
338
339 expect(requestedTimes).toEqual(expect.arrayContaining([0, 2, 4, 6]));
340
341 window.close();
342 });
343
307 344 test('prefetch uses furthest buffered end when player.bufferedEnd under-reports', async () =>
308 345 {
309 346 const window = createWindow();
@@ -304,6 +304,43 @@ describe('shared image subtitle prefetching', () =>
304 window.close();
304 window.close();
305 });
305 });
306
306
307 test('prefetch respects configured larger prefetch step size', async () =>
308 {
309 const window = createWindow();
310 const helper = loadSharedVideoPlayer(window);
311 const { player, videojs } = buildPlayerHarness(window);
312 const requestedTimes = [];
313
314 player.duration(6);
315
316 window.fetch = jest.fn(async (url) =>
317 {
318 const parsed = new URL(url, 'http://localhost/');
319 requestedTimes.push(Number(parsed.searchParams.get('timeSeconds')));
320 return new Response(null, {
321 status: 204,
322 headers: { 'X-Subtitle-Frame-Status': 'none' },
323 });
324 });
325
326 helper.bindImageSubtitleOverlay(player, videojs, {}, {
327 imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
328 }, {
329 lookaheadSeconds: 0,
330 initialPrefetchSeconds: 0,
331 prefetchStepSeconds: 2,
332 buildFrameRequest: ({ currentTime, streamIndex }) => ({
333 url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
334 }),
335 });
336
337 await flushAsyncWork(window, 14);
338
339 expect(requestedTimes).toEqual(expect.arrayContaining([0, 2, 4, 6]));
340
341 window.close();
342 });
343
307 test('prefetch uses furthest buffered end when player.bufferedEnd under-reports', async () =>
344 test('prefetch uses furthest buffered end when player.bufferedEnd under-reports', async () =>
308 {
345 {
309 const window = createWindow();
346 const window = createWindow();