Skip to content

Subtitle enable mid-playback is slow: on-demand ffmpeg extraction with no caching; compat endpoint buffers whole file #296

Closed

Description

@zZebrahz

Summary

Enabling a subtitle track mid-playback takes noticeably long to show cues (web player and Apple clients), while disabling is instant on the web. Investigation shows the delay is on-demand ffmpeg subtitle extraction with no caching, and the Jellyfin-compat endpoint used by the Apple clients is the slowest possible variant (whole-file pass, fully buffered before the first byte).

Subtitle toggling never restarts the transcode (subtitles are out-of-band and client-rendered on both stacks — this is good architecture), so the fix is purely about extraction latency.

Current behavior

Every subtitle enable spawns a fresh ffmpeg extraction. There is no extracted-subtitle cache anywhere.

Native API (GET /stream/{session}/subtitles/{track}, used by web):

  • Text (SRT→VTT): windowed extraction with input-side -ss + -t (default 600s window) streamed with per-chunk flush — first cue ~1s. This path is fine.
  • ASS/SSA and PGS: windowing is disabled (windowable = !IsASS && !IsPGS, internal/playback/subtitle_stream.go:129-142) — ASS needs the [Script Info] header at offset 0, PGS .sup is consumed whole by libpgs. Enabling these triggers a whole-file demux from byte 0, which takes many seconds on large files / network storage.

Jellyfin-compat API (GET /Videos/{item}/{mediaSource}/Subtitles/{index}/stream.{format}, used by Apple clients):

  • playback.ExtractSubtitle / ExtractSubtitleWithFormat (internal/playback/subtitles.go:58-132) run ffmpeg -i file -map 0:s:N with no -ss, no -t, and buffer the entire output into a bytes.Buffer before writing a single byte — for every embedded track, every request. This is strictly worse than the native path.

Web "off is instant" is expected: disable is pure client-side teardown (abort fetch, clear cues); no server round trip.

Why this matters

Plex toggles subtitles with only a momentary pause. Silo can beat that (no transcode restart needed), but today the enable path stalls on a cold whole-file ffmpeg pass on the two most common real-world cases: ASS subs on the web, and everything on Apple clients.

Proposed fixes

  1. Cache extracted subtitle tracks, keyed on media file (path + mtime or media source id) + stream index + output format. Embedded subtitle tracks are immutable for a given file; a small on-disk cache (similar to trickplay/attachment caches) makes every enable after the first instant, and makes even the first enable a one-time cost that could be pre-warmed at playback start.
  2. Fix the compat endpoint: stream ffmpeg stdout instead of buffering the full output, and reuse the native path's windowed/seeked extraction (StreamExtractSubtitle) where the format allows, instead of the whole-file ExtractSubtitle.
  3. Optional: pre-warm extraction when a playback session starts (kick off extraction of the default/likely subtitle track in the background) so the first toggle hits the cache.

Pointers

  • internal/playback/subtitles.go:58-132 — compat whole-file buffered extraction
  • internal/playback/subtitle_stream.go:114-187 — native windowed streaming extraction (windowable gate at :129)
  • internal/jellycompat/streams.go:543-670 — HandleSubtitleStream
  • internal/api/handlers/stream.go:174-256 — native HandleSubtitle
  • web/src/player/hooks/useSubtitleTracks.ts, useASSSubtitles.ts, usePGSSubtitles.ts — client renderers (off-instant/on-slow asymmetry)

Related

The Apple clients have a separate, purely client-side cause for the same symptom on direct play (CoreMedia demuxer discards subtitle packets for already-buffered media and doesn't re-seek on enable) — being fixed in silo-apple. Fixing this server issue additionally covers the sidecar/transcode cases and the web player.

Activity

  1. zZebrahz commented on Jul 3, 2026

    @zZebrahz
    ContributorAuthor

    I can handle this later, just making a note of it

  2. Quick104 commented on Sep 11, 2026

    @Quick104
    Contributor

    Closing: addressed by merged #938 (Related issues: #296; extraction caching and subtitle delivery reliability).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions