media icon indicating copy to clipboard operation
media copied to clipboard

TTML style attributes are not read from the region tag

Open svart-riddare opened this issue 1 year ago • 2 comments

Version

Media3 main branch

More version details

No response

Devices that reproduce the issue

Application : https://play.google.com/store/apps/details?id=com.canal.android.canal&hl=fr Device : Redmi Note 11 Pro 5G (issue not specific to device) Android : 13 TKQ1.221114.001

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Play a DASH stream containing TTML subtitles, like the following:

<?xml version="1.0" encoding="utf-8"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling%22  xmlns:ttp="http://www.w3.org/ns/ttml#parameter%22  xml:lang="" ttp:cellResolution="40 24">
  <head>
    <styling>
      <style xml:id="speakerStyleDoubleHeight" tts:fontFamily="proportionalSansSerif" tts:fontSize="166.66%" tts:lineHeight="120.00%" tts:overflow="visible" tts:backgroundColor="transparent" tts:color="white" tts:textOutline="black 2px"/>
    </styling>
  <layout>
    <region xml:id="speaker_1" tts:origin="7.50% 62.50%" tts:extent="50.00% 16.67%" tts:displayAlign="after" tts:textAlign="left" style="speakerStyleDoubleHeight"/>
  </layout>
  </head>
  <body>
    <div>
      <p begin="82287:47:57.880" end="82287:47:59.360" region="speaker_1">
      subtitle text
      </p>
    </div>
  </body>
</tt>

Expected result

The above subtitle is left aligned in the given region; i.e. the tts:textAlign style element has been taken into account.

Actual result

The above subtitle is centered on screen; the tts:textAlign style element has been ignored.

See TTML specification https://www.w3.org/TR/2018/REC-ttml1-20181108/#layout-vocabulary-region:

<region
  [begin](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-attribute-begin) = [<timeExpression>](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-value-timeExpression)
  [dur](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-attribute-dur) = [<timeExpression>](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-value-timeExpression)
  [end](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-attribute-end) = [<timeExpression>](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-value-timeExpression)
  [style](https://www.w3.org/TR/2018/REC-ttml1-20181108/#style-attribute-style) = IDREFS
  [timeContainer](https://www.w3.org/TR/2018/REC-ttml1-20181108/#timing-attribute-timeContainer) = (par|seq)
  [ttm:role](https://www.w3.org/TR/2018/REC-ttml1-20181108/#metadata-attribute-role) = string
  [xml:id](https://www.w3.org/TR/2018/REC-ttml1-20181108/#content-attribute-id) = ID
  [xml:lang](https://www.w3.org/TR/2018/REC-ttml1-20181108/#content-attribute-lang) = string
  [xml:space](https://www.w3.org/TR/2018/REC-ttml1-20181108/#content-attribute-space) = (default|preserve)
  {any attribute in TT Style namespace}
  {any attribute not in default or any TT namespace}>
  Content: [Metadata.class](https://www.w3.org/TR/2018/REC-ttml1-20181108/#element-vocab-group-table)*, [Animation.class](https://www.w3.org/TR/2018/REC-ttml1-20181108/#element-vocab-group-table)*, [style](https://www.w3.org/TR/2018/REC-ttml1-20181108/#styling-vocabulary-style)*
</region>

See function parseRegionAttributes() : https://github.com/androidx/media/blob/release/libraries/extractor/src/main/java/androidx/media3/extractor/text/ttml/TtmlParser.java#L352

Media

<?xml version="1.0" encoding="utf-8"?>
<tt xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling%22  xmlns:ttp="http://www.w3.org/ns/ttml#parameter%22  xml:lang="" ttp:cellResolution="40 24">
  <head>
    <styling>
      <style xml:id="speakerStyleDoubleHeight" tts:fontFamily="proportionalSansSerif" tts:fontSize="166.66%" tts:lineHeight="120.00%" tts:overflow="visible" tts:backgroundColor="transparent" tts:color="white" tts:textOutline="black 2px"/>
    </styling>
  <layout>
    <region xml:id="speaker_1" tts:origin="7.50% 62.50%" tts:extent="50.00% 16.67%" tts:displayAlign="after" tts:textAlign="left" style="speakerStyleDoubleHeight"/>
  </layout>
  </head>
  <body>
    <div>
      <p begin="82287:47:57.880" end="82287:47:59.360" region="speaker_1">
      subtitle text
      </p>
    </div>
  </body>
</tt>

Bug Report

  • [ ] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

svart-riddare avatar Jun 18 '24 14:06 svart-riddare

I agree support for parsing styling information directly from <region> nodes isn't supported. I'll track this as an enhancement, but I'm afraid we have no immediate plans to work on this. We would consider a high quality PR implementing this (probably by re-using existing parsing support and the TtmlStyle type).

icbaker avatar Jun 28 '24 16:06 icbaker

Thank you for your reply, I will be forwarding this to the developpers of https://play.google.com/store/apps/details?id=com.canal.android.canal, perhaps they will be able to submit a PR.

As a side note there are also style elements that are parsed in the <region> tag but not in the <style> tag, like tts:diplayAlign. In my opinion, the pull request should also address that.

svart-riddare avatar Jul 01 '24 08:07 svart-riddare