shaka-project / shaka-player

JavaScript player library / DASH & HLS client / MSE-EME player
Apache License 2.0
7.09k stars 1.33k forks source link

Support for styling subtitles in ISOBMFF #563

Closed birme closed 7 years ago

birme commented 7 years ago

We have a large library with assets having subtitles embedded in ISOBMFF containers where the styling and positioning is incorrect. The subtitle format in this case is TTML.

In Exoplayer we have the option to disable the styling in the ISOBMFF and a default behaviour is used by the player. A similar feature would be interesting to have in Shaka. I see two ways this could be implemented:

1) A specific mp4 ttml-parser that cleanup any incorrect styling and applies a default styling / positioning 2) An option to existing mp4 ttml-parser to cleanup incorrect styling and apply a default styling / positioning

We're happy to provide a PR for this if this sounds like a good feature to add.

joeyparrish commented 7 years ago

I'm not sure what it would mean to clean up the styling. Do you mean that this option would ignore styling and only parse the text payload of each cue?

birme commented 7 years ago

With this option it would extract the text payload (including any TTML styling) and strip out the TTML styling elements and create a new text payload with a default TTML styling applied.

joeyparrish commented 7 years ago

@birme, the way our parsers work is that we extract the text and the styling and apply it all to a cue object we feed to the browser. The browser does all the rendering. For us, there's no difference between default styling and no styling. Does this make sense?

birme commented 7 years ago

@joeyparrish: Let us assume that we have one single ISOBMFF box with this TTML payload:

<tt 
 xmlns="http://www.w3.org/ns/ttml" xmlns:ttp="http://www.w3.org/ns/ttml#parameter"
 xmlns:tts="http://www.w3.org/ns/ttml#styling" ttp:timeBase="media" xml:lang="en"
 ttp:cellResolution="50 30">
    <head>
        <styling>       
            <style xml:id="spanStyle" tts:color="#ffffff" tts:backgroundColor="#000000" tts:fontSize="160%" tts:fontFamily="monospace"/>
            <style xml:id="paragraphStyle" tts:textAlign="center" />
        </styling>
        <layout>
            <region xml:id="bottom" tts:origin="10% 10%" tts:extent="80% 80%" tts:displayAlign="after" />
        </layout>
    </head>
    <body>
        <div>
            <p xml:id="subtitle1" region="bottom" begin="00:00:10.000" end="00:00:20.000" style="paragraphStyle">
                <span style="spanStyle">One line Subtitle.</span>
            </p>
        </div>
    </body>
</tt>

In our case the <layout> and <styling> portion are incorrect and what I want is that before it is feed to the browser it can be replaced with a "default" TTML layout block. I can agree that this might be a special case but similar to ExoPlayer it would be great to have a function to "clean" bad or incorrect styling. If you don't think this is an entirely stupid thing I could make a PR with a proposal on how to solve this.

joeyparrish commented 7 years ago

Let me see if I understand you. You want the ability to instruct Shaka Player to ignore styling and only parse the cue timing and text. Is that correct?

Do you also want the ability to specify replacement style attributes, or is it enough to let the browser apply its defaults?

birme commented 7 years ago

I think you can actually close this one. I've solved the problem with a PR that fixed some of the issues with
in ttml was not handled correctly and some alignment issues

joeyparrish commented 7 years ago

Okay, sounds good. Thanks!