google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.74k stars 6.03k forks source link

TTML: Captions - Support for style tts:textOutline #9391

Open johnquinn-syn opened 3 years ago

johnquinn-syn commented 3 years ago

Searching https://github.com/google/ExoPlayer/labels/enhancement and https://github.com/google/ExoPlayer/pulls I cannot see "outline" or "textOutline" mentioned.

TTML: Support for tts:textOutline

The https://exoplayer.dev/dash.html indicates support for ISO/IEC 14496-30 which in turn references https://www.w3.org/TR/ttml1/#style-attribute-textOutline. This is missing from TtmlDecoder parseStyleAttributes This is not supported and is very useful for high-lighting white subtitle text against a white background. (Our customers have complained)

Proposed solution

Implement support for https://www.w3.org/TR/2018/REC-ttml2-20181108/#style-attribute-textOutline as per the example in the document: <style tts:textOutline="black 2px 0px"/>

Alternatives considered

Possible to over-ride the supplied subtites with CaptionStyleCompat but this is not suitable for all customers and it is best to respect the in-stream track.

icbaker commented 3 years ago

Thanks for the request.

This looks like it might be slightly fiddly to implement, because ExoPlayer relies on styling spans to represent text styling inside Cue objects. Unfortunately I can't see a platform-provided Span that supports outline styling as required by this feature.

We may need to add a custom span, and then manually add styling support to both WebViewSubtitleOutput and CanvasSubtitleOutput. We already have some of these custom spans, like RubySpan.

I don't know when we'll have time to implemeting this ourselves - we would accept a high quality PR (but given the potential complexity mentioned above, it might be worth a prospective PR author sketching out their plans in a comment here before spending ages on the code so we can take a look).

nigelmegitt commented 3 years ago

It may be possible to simulate something approaching the desired presentation of text outline by using a small shadow, if there's adequate control over both the "hardness" of the shadow edge and the size of the shadow.

johnquinn-syn commented 3 years ago

Thank you for investigating. I don't think we have the right expertise in this area to offer a fix. Is something that Nigel suggests doable?

nigelmegitt commented 3 years ago

My expertise is in the format and rendering requirements, not the specific implementation of ExoPlayer, so this may be way off, but I wonder if the shadow attributes in TextAppearanceSpan could be helpful.