Skip to content

Support remote HLS external WebVTT subtitles in loopback mode (non-nativeRemoteHLS) #154

Closed

Description

@jihongboo

What happened?

Support remote HLS external WebVTT subtitles in loopback mode (non-nativeRemoteHLS)

Description

When playing a remote HLS stream with external WebVTT subtitles (e.g. WWDC video streams using separate subtitle playlist tracks #EXT-X-MEDIA:TYPE=SUBTITLES) in loopback mode (nativeRemoteHLS = false), no subtitle tracks are populated, and the subtitle picker remains empty.

Steps to reproduce

  1. Load a remote HLS URL containing external subtitles, such as:
    https://devstreaming-cdn.apple.com/videos/wwdc/2025/323/4/0fd37581-632a-4827-b656-d192163cece0/cmaf.m3u8
  2. Configure load options to disable bypass: options.nativeRemoteHLS = false
  3. Inspect engine.subtitleTracks after the stream is loaded.
  4. Expected Result: Subtitle tracks for all declared languages (English, Chinese, Japanese, etc.) are available for selection.
  5. Actual Result: engine.subtitleTracks is empty.

AetherEngine version or commit SHA

5.9.5

Host app

AetherPlayer

Platform

macOS

OS version

macOS 27 beta3

Device / chip

MacBook Pro M3

Playback path

Native AVPlayer

Source media (for playback bugs)

https://devstreaming-cdn.apple.com/videos/wwdc/2025/323/4/0fd37581-632a-4827-b656-d192163cece0/cmaf.m3u8

Error codes / log lines

## Root Cause Analysis

Upon inspecting the `AetherEngine` source code, the issue stems from the following aspects in the loopback pipeline:

1. **FFmpeg Probe Limitation**:
   FFmpeg (`libavformat`)'s HLS demuxer does not automatically resolve and expose `#EXT-X-MEDIA:TYPE=SUBTITLES` tracks as inline `AVMEDIA_TYPE_SUBTITLE` streams during the initial probe. Thus, `Demuxer.subtitleTrackInfos()` returns an empty array.

2. **Ingest Engine Omits Subtitles**:
   In `Sources/AetherEngine/IO/HLSIngest/HLSPlaylist.swift`, the `parseMaster(_:)` method only resolves variant streams and audio renditions (`TYPE=AUDIO`), completely ignoring `TYPE=SUBTITLES` declarations:
   
   // Currently only AUDIO is parsed:
   } else if line.hasPrefix("#EXT-X-MEDIA:") {
       if attribute("TYPE", in: line) == "AUDIO",
          let uri = attribute("URI", in: line),
          let group = attribute("GROUP-ID", in: line) {
           ...
       }
   }

Anything else

No response

Activity

  1. added
    bug
    on Jul 19, 2026
  2. superuser404notfound commented on Jul 19, 2026

    @superuser404notfound
    Owner

    Thanks for the detailed report and the source-level analysis, both pointers were on target.

    Digging in showed the situation was one step worse than described: with nativeRemoteHLS = false, a remote VOD m3u8 did not just come up with an empty subtitleTracks, the load itself could never succeed. The bundled FFmpeg is built with --disable-network, so the hls demuxer neither engages behind the engine's custom AVIO context (its probe rejects a playlist without a .m3u8 extension or MIME hint, the "Not detecting m3u8/hls with non standard extension and non standard mime type" log) nor could it ever fetch a variant or a segment. On 5.9.5 the repro URL fails with openFailed(-1094995529) (AVERROR_INVALIDDATA) before any track list exists. The HLSPlaylist.parseMaster in the analysis belongs to the live MPEG-TS ingest (HLSLiveIngestReader); it does ignore TYPE=SUBTITLES, but it also rejects fMP4/CMAF playlists (EXT-X-MAP goes terminal), so it never participates in this stream either.

    Demuxing remote HLS VOD inside the loopback pipeline would mean rebuilding AVPlayer's HLS stack (CMAF ingest, byte ranges, rendition switching), which goes against the engine's native-first design; AVPlayer plays remote HLS natively and well. 5.10.0 fixes the issue along that line instead:

    • A non-live m3u8 on the loopback path is now detected as a typed misroute (AVIOReaderError.hlsPlaylistOnVODPath, the load(url:) with isLive: true on an HLS playlist URL fails open: silent reconnect loop with no terminal state (262 cycles over a 5.75-min observation), playlist body consumed as raw bytes, no error, no give-up #140 sibling for VOD) and load() transparently reroutes it onto the nativeRemoteHLS bypass. options.nativeRemoteHLS = false still lands on AVPlayer for remote HLS, the host just no longer needs to pre-route it.
    • On that bypass the engine now surfaces the item's legible AVMediaSelectionGroup as engine.subtitleTracks: synthetic ids, group order preserved, language tags, forced and SDH dispositions carried. selectSubtitleTrack(index:) selects the rendition through AVPlayer's media selection (AVPlayer renders the cues itself; there are no overlay cues on this path), clearSubtitle() deselects, and a selection made by AVKit or a system caption preference is mirrored into activeSubtitleTrackIndex once the item is ready.
    • A VOD startPosition now also applies on the bypass as a resume seek.

    Verified end to end against the WWDC URL from the report: the reroute engages, all 7 declared renditions (en, zh, ja, ko, fr, es, pt) appear in subtitleTracks, and selecting English lands on the item's media selection.

    Released in 5.10.0. Please retest with that version and report back.

  3. jihongboo commented on Jul 22, 2026

    @jihongboo
    ContributorAuthor

    Thank you for your reply. I’ve used the latest version, and I’ve found that the issue has been resolved on non-MacOS platforms. However, the problem still persists on Mac. When I tried to debug it, I noticed that setting nativeRemoteHLS doesn’t seem to have any effect.

  4. superuser404notfound commented on Jul 22, 2026

    @superuser404notfound
    Owner

    Thanks for retesting, and for the extra detail on the macOS side.

    Two things up front, then a fix and one request.

    On nativeRemoteHLS having no effect: that is expected now. Since 5.10.0 a remote HLS VOD URL is rerouted onto the AVPlayer bypass whether nativeRemoteHLS is true or false, because the loopback pipeline (FFmpeg built with --disable-network) can never demux it. So toggling the flag no longer changes remote-HLS behavior; both settings land on AVPlayer.

    On the empty picker: subtitleTracks is populated asynchronously and is a @Published property. On the bypass the engine loads the item's legible AVMediaSelectionGroup and only then sets subtitleTracks, which happens after load() returns (sometimes after readyToPlay). A host that reads engine.subtitleTracks once, right after load(), will see it empty. It has to observe the property. Worth double-checking on your side, since that alone can look like "empty on one platform, populated on another" purely from timing.

    I could not reproduce an empty result on macOS 26.5: the reroute engages, all 7 declared renditions surface, and English is selectable end to end. You are on macOS 27 beta3, one OS version ahead of what I can test here, so the most likely cause is a real timing difference: on that OS loadMediaSelectionGroup(for: .legible) may return an empty group until the item reaches readyToPlay, and the discovery loaded that group exactly once and gave up if it was empty, leaving subtitleTracks empty for the whole session.

    I have staged a fix along that line: the discovery now retries the legible-group load once after readyToPlay before giving up, so an early-empty group recovers instead of dropping every rendition. The fast path is unchanged (a non-empty first load skips the wait). Commit 87d8216 on fix/ae154-remote-hls-subtitle-readiness-retry.

    To make sure that is actually your failure mode before I cut a release, could you grab two log lines from a macOS 27 beta3 run (both go through EngineLog)?

    1. [AVIOReader] HLS playlist body on the VOD loopback path (AE#154); rerouting to the native remote-HLS bypass.
    2. [AetherEngine] AE#154: remote-HLS legible group surfaced N subtitle rendition(s)

    Interpretation:

    • No line 1 at all: the reroute is not firing on your setup, which is a different root cause. Please share the full load log in that case.
    • Line 1 present, line 2 shows surfaced 0 or is absent: the early-empty group is the cause and the staged retry fixes it.
    • Line 2 shows surfaced 7 but your picker is still empty: the engine surfaced the tracks and the host is reading subtitleTracks once instead of observing the @Published value.

    Thanks again.

  5. superuser404notfound commented on Jul 22, 2026

    @superuser404notfound
    Owner

    Follow-up: the readiness retry is now released in AetherEngine 5.18.6, and AetherPlayer 0.12.2 (build 54) bundles it.

    Since the symptom is macOS-only while iOS works, it is worth ruling out that the macOS AetherPlayer you tested pins an engine from before the fix. The cleanest retest is on a current build: update AetherPlayer to 0.12.2 through the in-app updater (Sparkle), or grab the DMG directly from https://github.com/superuser404notfound/AetherPlayer/releases/tag/v0.12.2, then load the WWDC URL again and open the subtitle picker.

    If 0.12.2 still shows an empty picker on macOS 27 beta3, the two log lines from my previous comment (the rerouting to the native remote-HLS bypass line and the legible group surfaced N subtitle rendition(s) line) will tell us exactly which layer to look at. Thanks.

  6. jihongboo commented on Jul 22, 2026

    @jihongboo
    ContributorAuthor

    First of all, I downloaded AetherPlayer 0.12.2, but I didn't find the entrance to play the remote video.

    Secondly, I didn't find these two logs.

    About [AVIOReader] HLS playlist body on the VOD loopback path (AE#154); rerouteing to the native remote-HLS bypass. , Self.bodyBeginsWithHLSPlaylistTag(firstWindowPrefix()) returns false, firstWindowPrefix() returns:

    (lldb) p firstWindowPrefix()
    ([UInt8]) 16 values {
      [0] = 0
      [1] = 0
      [2] = 0
      [3] = 28
      [4] = 102
      [5] = 116
      [6] = 121
      [7] = 112
      [8] = 77
      [9] = 52
      [10] = 86
      [11] = 32
      [12] = 0
      [13] = 0
      [14] = 0
      [15] = 1
    }
    

    Regarding [AetherEngine] AE#154: remote-HLS legible group surfaced N subtitle rendition(s), first of all, I need to set nativeRemoteHLS to true, and secondly, the following conditions returned directly, which seems to be group acquisition failure.

        func publishRemoteHLSSubtitleTracks(host: NativeAVPlayerHost) {
            remoteHLSSubtitleDiscoveryTask?.cancel()
            guard let item = host.avPlayer.currentItem else { return }
            remoteHLSSubtitleDiscoveryTask = Task { @MainActor [weak self] in
                guard let group = try? await item.asset.loadMediaSelectionGroup(for: .legible),
                      !group.options.isEmpty else { return }

    By the way I just updated macOS to 27 beta4, and the issue sill there.

  7. superuser404notfound commented on Jul 23, 2026

    @superuser404notfound
    Owner

    Thanks, you are right about AetherPlayer 0.12.2: the macOS app did not expose any way to enter a remote URL, so the released app was not actually usable as the retest vehicle. I have added an Open URL sheet to the macOS empty state and File menu, with Cmd-L as the shortcut, in AetherPlayer commit d52f8c6. It uses the same URL validation and PlayerViewModel.open path as the iOS UI. This will be included in the next AetherPlayer release.

    I tested that macOS UI end to end on macOS 26.5 with the exact WWDC URL from this issue. Playback starts through the native path and the subtitle menu contains all seven renditions: English, Chinese, Japanese, Korean, French, Spanish, and Portuguese.

    There are also two important clues in the debugger data:

    1. The bytes you captured decode to an ISO BMFF header: 00 00 00 1c 66 74 79 70 4d 34 56 20, or ftypM4V. That is an MP4 media object, not an HLS playlist. The exact issue URL currently responds with Content-Type: application/vnd.apple.mpegurl and begins with #EXTM3U. Therefore the AVIOReader in that debug run was not reading the master-playlist response when firstWindowPrefix() was inspected. Please check the exact url held by that AVIOReader, including any host-side URL replacement or redirect handling.

    2. The publishRemoteHLSSubtitleTracks implementation in your comment is the older one-shot version. AetherEngine 5.18.6, commit c10ec2508a19ae334163d0077a86c2e995ff32c7, uses var group, waits for readyToPlay after an empty first result, and loads the legible group again. AetherPlayer 0.12.2 pins that exact commit. If your source build still shows the one-shot guard let group implementation, it is compiling a different AetherEngine revision from the one bundled by 0.12.2.

    The new macOS URL entry point will make the next retest unambiguous. Since I cannot test macOS 27 beta4 locally, please retest that build there once it is published. If it still differs, the exact AetherEngine revision plus the AVIOReader.url value at the prefix check should identify whether the remaining difference is dependency resolution, URL routing, or AVFoundation behavior on macOS 27.

  8. superuser404notfound commented on Jul 23, 2026

    @superuser404notfound
    Owner

    Follow-up: AetherPlayer v0.12.3 (build 55) is now released and bundles AetherEngine 5.20.1.

    The macOS retest path is now:

    1. Click Open URL... on the empty screen, or choose File > Open URL... with Cmd-L.
    2. Paste the exact WWDC cmaf.m3u8 URL from this issue.
    3. Leave Live stream (tuner / IPTV) off for this VOD stream.
    4. Click Play, wait for playback to begin, then open the Subtitles menu.

    The signed and notarized DMG is available from the release page, and the Sparkle appcast now advertises build 55. Please retest this build on macOS 27 beta4. If the subtitle menu is still empty there, please share the exact AetherEngine revision and the AVIOReader.url value from that run.

  9. jihongboo commented on Jul 25, 2026

    @jihongboo
    ContributorAuthor

    I just updated to the latest version (5.23.2), and then I found that the problem was solved. Similarly, there is no problem with AetherPlayer. I think this bug has been solved.
    Thank you.

  10. added 2 commits that reference this issue on Nov 12, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions