Skip to content

libass rendering #30

Closed
Closed

Description

@edde746

What should the engine do?

Render ASS/SSA subtitles with libass and output as CGImage like some other subtitle formats.

Motivating media or use case

All custom ASS/SSA styling currently gets stripped or output as text.

Area

Codec / container support

Host app / integration context

No response

Would you be willing to open a PR?

No

Activity

  1. added
    enhancement
    on Jun 8, 2026
  2. DrHurt commented on Jun 9, 2026

    @DrHurt
    Contributor

    Good shout for anime users though I would prefer this to be an opt in via load option to preserve the current lightweight & customisable rendering pipeline.

    Obviously not my call but I’m just thinking out loud.

  3. strangeliu commented on Jun 10, 2026

    @strangeliu

    Good shout for anime users though I would prefer this to be an opt in via load option to preserve the current lightweight & customisable rendering pipeline.

    Obviously not my call but I’m just thinking out loud.

    maybe an option to output the raw ass output text

  4. superuser404notfound commented on Jun 10, 2026

    @superuser404notfound
    Owner

    Partial step shipped in 3.0.0: LoadOptions.preserveASSMarkup emits raw ASS event lines (override tags, style refs, escapes intact) and TrackInfo.assHeader exposes the script header, so hosts can render authored styling themselves today (@strangeliu's suggestion, opt-in as @DrHurt proposed).

    Full libass rendering stays on the roadmap and is a bigger lift than it looks: libass plus freetype, fribidi, and harfbuzz need cross-builds for tvOS/iOS/macOS in FFmpegBuild (with the CoreText font provider instead of fontconfig), and animated ASS (karaoke, \move, \t) doesn't fit the engine's cue-based CGImage model, it needs a per-frame render surface synced to the playback clock. Keeping this issue open to track that work; it will land as an opt-in load option to preserve the current lightweight pipeline.

  5. DrHurt commented on Jun 10, 2026

    @DrHurt
    Contributor

    There is an open source libass renderer for AVPlayer already available.

    https://github.com/mihai8804858/swift-ass-renderer

    I’m inclined to say this type of implementation should be for host apps to implement not aether engine. So rendering remains the responsibility of host apps like it currently is.

    So basically opt in via engine load options + host app renderer plugin.

    I will need to do more reading to see what it would take for aether to output something that can be consumed by the above library!

    I suspect the above lib would also need to be forked and modified to meet aether halfway (incremental subtitles instead of full file upfront).

    Maybe one day an aether compatible fork of the above renderer can become a part of the aether project for hosts that want to implement it.

  6. superuser404notfound commented on Jun 10, 2026

    @superuser404notfound
    Owner

    Full styled ASS/SSA rendering is now live in Sodalite, host-side via swift-ass-renderer exactly as proposed here, and the engine ships everything a host needs for the same integration (on current main, will be in the next tagged release):

    The host contract

    1. LoadOptions.preserveASSMarkup: true makes ASS/SSA cues carry the raw libavcodec event lines (ReadOrder,Layer,Style,...,Text, tags intact); timing is on the cue (startTime/endTime, source-PTS seconds).
    2. TrackInfo.assHeader carries the track's script header; engine.fontAttachments carries the container's embedded fonts (write them to a directory and point FontConfig(fontsPath:) at it).
    3. ASSScriptBuilder (engine utility) reassembles the incrementally streamed events plus the header into a complete script for loadTrack(content:)/reloadTrack(content:)-style whole-file renderers. It absorbs the real-world quirks we hit during device testing so hosts do not have to rediscover them: MKV CodecPrivate usually lacks the [Events] section (the builder synthesizes it), is frequently NUL-terminated (libass parses C-string-style and silently stops there; the builder strips NULs), and ReadOrder is hardcoded to 0 on every line in real files (dedupe is content-based, not ReadOrder-based).
    4. Drive renderer.setTimeOffset from engine.clock.$sourceTime (same source-PTS coordinate as the cue times) and batch reloadTrack(content:) while events stream in; the side demuxer paces ~90 s ahead of the playhead, so a few seconds of batching costs nothing.

    Sodalite's ASSRenderCoordinator is the reference implementation of this contract (about 150 lines): https://github.com/superuser404notfound/Sodalite/blob/main/Sodalite/Player/Subtitles/ASSRenderCoordinator.swift

    Verified on device (Apple TV 4K, tvOS 26) against anime MKVs: authored styling, fonts, and positioning render via libass, memory stays flat, and the engine remains rendering-free.

    Thanks @DrHurt for steering this toward the host-plugin shape and pointing at swift-ass-renderer, @strangeliu for the raw-output suggestion that became the engine contract, and @edde746 for the original request. Closing as shipped; if a host integration hits something the contract does not cover, comment here and we will reopen.

  7. DrHurt commented on Jun 10, 2026

    @DrHurt
    Contributor

    That was incredibly fast.

    exoplayer on Android flattens ASS into plain text by default similar to aether.

    Android apps based on exoplayer often implement the libass plugin under an “enable ASS styling” toggle.

    I have no strong feelings either way but I suggest Sodalite follows this as well. Default lightweight text rendering with a settings toggle for advanced rendering.

    Rationale: ASS styling with libass is very good but isn’t perfect and forcing it on by default will cause issues sometimes. Also allowing plain text mode allows text customisations to apply (fonts, size, position, colour etc) when styling isn’t required.

    Again no strong feelings, just thinking out loud.

  8. superuser404notfound commented on Jun 10, 2026

    @superuser404notfound
    Owner

    Good instinct, and it is in already: Sodalite now has a "Styled ASS Subtitles" toggle in the playback settings (shipped right after the rendering itself). When it is off, ASS/SSA tracks go through the lightweight plain-text path and all the user's text customizations (size, color, background, position) apply, exactly the exoplayer-style split you describe.

    One deliberate deviation: it defaults to ON rather than off. Reasoning: when a track ships authored styling, that styling is what the author intended viewers to see (positioning and styling often carry meaning in anime subs, signs, speaker colors), so it felt wrong to hide it behind a setting most users never open. The escape hatch for the cases where libass output is imperfect or someone simply prefers their own text settings is one switch away. Easy to revisit if real-world reports suggest the default should flip.

    On the engine side, the host contract is now tagged: everything from the comment above (preserveASSMarkup, assHeader, fontAttachments, ASSScriptBuilder with the real-world MKV hardening) shipped in 3.1.0.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions