Skip to content

Allow A/V startup before sparse PGS subtitle dimensions resolve in the main probe #858

Closed

Description

@qoli

What should the engine do?

Allow the main playback probe to finish once the parameters required for safe audio/video playback are ready, even when already-enumerated PGS subtitle tracks still lack dimensions. Keep those tracks available and complete their remaining metadata during playback or when selected. An opt-in load policy would also meet our integration need.

On our measured Matroska source, four unresolved PGS tracks keep the shared probe reading to its 50 MiB ceiling, costing 13.46–14.39 seconds before playback can be constructed.

Motivating media / integration

We are optimizing startup in Syncnext / SyncnextHybrid. The controlled measurements below are from a macOS Release native-player probe using the same engine pin as our tvOS integration.

  • AetherEngine 7.45.0, commit 52802afaaf035a7f729bba1043b640ad4d9ebb3e.
  • FFmpegBuild 3.9.0, commit 3b398c8f6340fe5fb4a7cb9a2a211a16677171e0; FFmpeg version header n8.1.3.
  • Apple M2 Ultra; macOS 27.0.1 (26A434).
  • Native AVPlayer through the engine's local remux/HLS path; HTTP URL input from a local SwiftBun media-source proxy, held source connection and progressive segment delivery.
  • AVPlayer forward-buffer preference held at 4 seconds.
  • Finite 64.4 GiB Matroska VOD: 1 video + 12 audio + 13 subtitle streams, 26 total.
  • Default main-probe budget: probesize = 52,428,800 bytes, max_analyze_duration = 60,000,000 microseconds. The latter is a media-analysis budget, not a 60-second wall-clock deadline.

Observed behavior and reproduction

  1. Start a fresh source process and resolve the same media again.
  2. Load its HTTP URL with the settings above.
  3. Measure containerOpened → streamsProbed using the engine checkpoints and a monotonic clock.
  4. Observe the main shared probe reach its byte ceiling, with PGS streams 13, 14, 21 and 24 still reporting unspecified size.

Two runs used the same Release binary and source configuration; only detailed probe logging / thread sampling changed:

Measurement Detailed logging + sampling Normal logging
Main-probe wall time 13.464 s 14.389 s
Whole player-process CPU during that interval 0.536 s 0.260 s
Wall time minus process CPU 12.928 s 14.129 s
Unresolved subtitle stream indices at exit 13, 14, 21, 24 13, 14, 21, 24

Whole-process CPU includes every app thread and logging; it is an upper bound on probe CPU, not exclusive FFmpeg time. The separate source process is outside that measurement.

In the detailed run:

  • All 26 streams were already enumerated before avformat_find_stream_info.
  • AVIO cumulative bytes read increased from 262,144 to 52,754,165: 52,492,021 additional bytes, about 50.060 MiB, at about 3.899 MB/s.
  • The explicit exit reason was the 52,428,800-byte probe ceiling. The four PGS tracks were the remaining codec-parameter warnings.
  • The function performed no seeks. Tail-index requests occurred after this probe.
  • From the byte-ceiling log to the function's “After” log took about 0.842 ms.
  • In an eight-second middle-window thread sample, 698 / 711 demux-thread samples (98.17%) were in AVIOReader.readPersistent → NSCondition.waitUntilDate; the source-pump thread was waiting in HeldSourceConnection.readFromSocket.

This supports waiting for source delivery as the dominant elapsed cost. It does not separate proxy scheduling from external-origin or network delays, and the sampling fraction is not an exact whole-probe wait-time measurement.

Log excerpt, with process-specific context pointers removed:

Before avformat_find_stream_info() pos: 15887 bytes read:262144 seeks:0 nb_streams:26
Probe buffer size limit of 52428800 bytes reached
Could not find codec parameters for stream 13 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Could not find codec parameters for stream 14 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Could not find codec parameters for stream 21 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
Could not find codec parameters for stream 24 (Subtitle: hdmv_pgs_subtitle (pgssub)): unspecified size
After avformat_find_stream_info() pos: 52634935 bytes read:52754165 seeks:0 frames:27406

The logged frames counter describes packets in the shared scan, not decoded video-frame count.

Why this needs a main-probe policy

The pinned main probeStreams path invokes avformat_find_stream_info. FFmpeg's PGS parameter check requires a width; its shared readiness / byte-limit loop explains why an unresolved subtitle can prevent early completion. This is consistent with the observed warnings and exit reason.

Related work:

We are requesting the supported upstream approach, without prescribing a particular implementation.

Required behavior / validation

  • Preserve the A/V analysis needed for correct playback, including video reorder/DTS information and audio parameters.
  • Keep all enumerated subtitle tracks, indices and language metadata; unresolved dimensions should remain pending rather than making the tracks disappear.
  • Verify selecting each of the four PGS tracks after startup, actual bitmap cues and canvas placement, switching, seeking and cancellation. Track counts alone are insufficient.
  • Keep the 4-second AVPlayer buffer preference for comparison. Compare probe bytes/time, first decoded frame, verified playback progress and subsequent stalls so the result does not merely move waiting past startup.

Evidence limits

These measurements use our patched consumer integration, not a pristine upstream build. The consumer carries integration and request-diagnostics patches; this experiment did not change FFmpeg or the main probeStreams algorithm/default budget, whose implementation was checked against the pin.

The exact earlier instant when all required A/V parameters become ready has not been measured. Consequently, the full ~14 seconds is not a claimed achievable saving. This diagnostic baseline also did not validate cue rendering for every subtitle track; the deferred-subtitle behavior remains a request to implement and verify.

The input is a private media source; no public minimal media reproducer is attached. Source URLs, headers, credentials and raw private traces are omitted.

Area

Performance / public API surface

Activity

  1. superuser404notfound commented on Oct 25, 2026

    @superuser404notfound
    Owner

    Thanks for the thorough report. The FFmpeg pointers and the evidence limits made this quick to pin down.

    Fixed on main in de860e4 (merge b194dce). It will ship with the next release.

    What changed: the main playback probe now parks every PGS track whose codec is already known as ATTACHMENT for the duration of avformat_find_stream_info. That is the same lever the engine already uses for undecodable audio (#466) and cover art (#75), and the tracks are restored right after the probe. has_codec_parameters asks nothing of an attachment, so the pass ends as soon as audio and video are resolved. Video reorder/DTS information and audio parameters go through the probe exactly as before.

    The tracks keep their index, language, codec and disposition. Their width stays 0, which is exactly what a full-budget probe left on your source anyway. Playback never needed that width from the probe: EmbeddedSubtitleDecoder takes the canvas from the decoded presentation composition segment and falls back to the video size, the same footing the subtitle side reader has had since #87. No new API or opt-in is involved; it applies to every main open.

    Measured with aetherctl against a 1080p MKV with two PGS tracks whose first cue sits at 150 s, behind a throttled 4 MB/s HTTP origin, two runs per arm:

    before after
    find_stream_info 3371 / 3535 ms 23 / 16 ms
    bytes read by the open 10.6 MB 0.39 / 0.46 MB

    This fixture stops at the 60 s analyze-duration budget rather than the 50 MiB ceiling because its bitrate is low. On your source, the ceiling was the exit.

    Subtitle validation (aetherctl play --subs pgssub): I used a 720p video carrying a 1920x1080 PGS canvas, which is the case where the probe-resolved width could have mattered. Early cues (inside the old probe window) and late cues (past it) land at the identical normalized position and canvas on both builds. Every authored cue arrives in 3 of 3 runs, and cues keep arriving after a seek. The new unit test uses a synthetic transport stream with a cue-less PGS PID: the open reads 262,144 bytes instead of 1,572,864, and the track is still listed as a subtitle.

    What I could not reproduce here: your 26-stream source, track switching across all four PGS tracks, and the 4 s AVPlayer buffer comparison on tvOS. Numbers from your harness after the next release would be very welcome, especially first decoded frame and any later stalls.

  2. superuser404notfound commented on Oct 26, 2026

    @superuser404notfound
    Owner

    Released in 7.48.0 (263dc11). Leaving this open for the retest.

  3. qoli commented on Nov 6, 2026

    @qoli
    ContributorAuthor

    Verified on the original 64.4 GiB Matroska source with all 26 streams on a physical Apple TV running tvOS 26.6.1. Syncnext 1.212 (579) used AetherEngine 7.56.0 (76ad51a7), FFmpegBuild 3.12.1 and the effective 4.00 s AVPlayer forward-buffer preference.

    • Main probe. The diagnostic build measured 6 ms in find_stream_info with the default 50 MiB budget. AVIO had read 262,144 bytes before the call and 262,144 bytes after it, so the call added 0 bytes to that counter. All 13 PGS tracks were enumerated and restored, including indices 13, 14, 21 and 24. The earlier 7.45.0 macOS runs on the same media took 13.46–14.39 s, with 52,492,021 additional AVIO bytes in the detailed run.
    • A/V playback. The signed app's Release configuration used native AVPlayer with 4K HEVC and TrueHD audio through the bridge. The engine's first-frame-ready checkpoint arrived 2.64 s after renderer load began. Playback advanced from 0.26 s to 128.11 s with no observed stall after startup.
    • PGS on tvOS. In a separate diagnostic run, selecting 13, 14 and 21 mounted real bitmaps around 610–611 s. Track 24 mounted at 734.30 s in an authored interval. Each image was attached to the player window and matched its 1920×1080 canvas mapping. After moving ahead and seeking back to 732.30 s, track 24 again mounted at 734.24 s in the same placement. Switching tracks and stopping cleared the bitmap history and overlay. The focused PGS probe-parking suite passed as well.

    The original playback and all four deferred subtitle tracks passed device acceptance.

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