Skip to content

Subtitle side-demuxer's 5 s analyze ceiling adds a flat ~5 s startup stall for PGS/bitmap tracks on URL sources #87

Closed

Description

@rrgomes

On a remote (URL/HTTP) source, opening the embedded-subtitle side-demuxer for a PGS/HDMV bitmap track blocks for the full analyzeCeiling (5.0 s) before it yields: such tracks never satisfy has_codec_parameters, so find_stream_info reads to the budget cap. When that open is on the startup path (host selectSubtitleTrack at load, or LoadOptions.preferredSubtitleLanguages auto-select), the 5 s lands as a flat pause before playback begins.

Root cause

Demuxer.swift, DemuxerOpenProfile.subtitleSideDemuxer:

let probeCeiling:   Int64 = 4 * 1024 * 1024   // 4 MB
let analyzeCeiling: Int64 = 5 * 1_000_000     // 5.0 s

The profile's own doc comment already describes it: PGS streams "keep has_codec_parameters false to the budget cap (the #75 pattern)," so find_stream_info runs to the full ceiling. A fast LAN hides it; a slower/remote URL blocks ~5 s. Since EmbeddedSubtitleDecoder only needs codec_id / codec_type (resolved by avformat_open_input from the container header / MPEG-TS PMT) and seeds the bitmap canvas from the source video size, the find_stream_info chase is pure cost.

Repro

A 1080p/4K HEVC file with embedded PGS (HDMV bitmap) subtitle tracks served over an HTTP/URL source (custom AVIO); select that PGS track at load. Result: ~5 s paused before playback self-starts. The same open is instant on a local file.

Suggested fix direction

Cap the subtitle side-demuxer's analyzeCeiling to sub-second (codec params come from the header/PMT before find_stream_info), or skip find_stream_info for the side-demuxer and read codec_type / codec_id directly, or make the open non-blocking with respect to the startup gate. Related: #52, #75, #76.

Host-side note: integrators can mitigate by deferring selectSubtitleTrack past the first playing state, but the 5 s budget is unnecessary regardless.

Activity

  1. superuser404notfound commented on Jun 30, 2026

    @superuser404notfound
    Owner

    Fixed on main (e1cf6c2), taking the skip-find_stream_info direction.

    DemuxerOpenProfile gains a skipStreamInfo flag, set by subtitleSideDemuxer. probeStreams drops both the avformat_find_stream_info pass and the cover-art reclassify (which only existed to bound that pass) when the flag is set. avformat_open_input already carries codec_id / codec_type for every subtitle track from the container header / MPEG-TS PMT, and EmbeddedSubtitleDecoder seeds the bitmap canvas from the source video size, so the chase was pure cost. As the report notes, even the #76 5 s ceiling was paid in full for the selected-PGS case (the target track never satisfies has_codec_parameters), so capping the budget would not have helped that path.

    Safety net for any container that does not declare the subtitle codec in its header: the side reader checks the target stream's codec_id after open and runs a bounded resolveStreamInfo() (capped by the same subtitle-sized probe ceiling) only when it is AV_CODEC_ID_NONE. The common path is now zero find_stream_info.

    Tests: added skipStreamInfo coverage to DemuxerProfileTests; full suite green (265).

    Remaining: device-verify the actual startup delta on a 1080p/4K HEVC + embedded PGS file over an HTTP source. A before/after on the flat pause against a slow (429/503-ish) origin would confirm the measured win.

  2. added a commit that references this issue on Jun 30, 2026
  3. superuser404notfound commented on Aug 4, 2026

    @superuser404notfound
    Owner

    Late follow-up on the release side: the fix in e1cf6c2 went out in 4.10.0 on July 2 and is contained in every one of the 142 tags since, so any current build carries it. The comment above stopped at "fixed on main" and never named a tag, which is on me.

    What to look for on a retest against a remote source with a PGS or HDMV bitmap track: the flat pause before playback should be gone whether the track comes from a host selectSubtitleTrack at load or from LoadOptions.preferredSubtitleLanguages. The side demuxer no longer runs avformat_find_stream_info at all, so there is no analyze budget left to burn on tracks that can never satisfy has_codec_parameters.

    If the startup pause is gone, this can be closed. If some part of it survives, the interesting artifact would be the timestamps around the side-demuxer open rather than the whole session, since the remaining candidates sit before that call rather than inside it.

  4. rrgomes commented on Aug 4, 2026

    @rrgomes
    ContributorAuthor

    Retested on 6.7.0 against a remote-URL source carrying a PGS track: no subtitle-attributable startup cost remains. Startup with the PGS track selected at load, with an SRT track selected, and with subtitles off is indistinguishable — the flat analyze pause is gone. (The title's absolute startup is dominated by its own DV-P7 conversion spin-up, which is why we compared within-title rather than against a stopwatch.) Fine to close from our side.

  5. superuser404notfound commented on Aug 7, 2026

    @superuser404notfound
    Owner

    Thanks for going back and measuring this, and for the within-title control. Comparing PGS against SRT against subtitles-off on the same title is the right shape here, since a stopwatch on absolute startup would have been swamped by the DV-P7 conversion anyway.

    Closing as fixed. e1cf6c2 shipped in 4.10.0 and is in every build since, so the side demuxer runs zero avformat_find_stream_info on the common path and the 5 s analyze ceiling can no longer be charged to a bitmap track that never satisfies has_codec_parameters. The one item still open on my side was a device measurement of the delta on a remote HEVC + PGS source, and this retest covers it.

    On the DV-P7 conversion spin-up dominating that title's startup: that is worth its own issue if it feels longer than the file warrants. A session log from a cold start on that title would be the useful artifact, the conversion work is logged with its own timing lines and it is easy to tell apart from the network side of the open.

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