Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TTML origin and extent attributes defined in style instead of region #1987

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ojoNetgem
Copy link

@ojoNetgem ojoNetgem commented Dec 18, 2024

Hello,

This adds support for tts:origin and/or tts:extent attributes defined in style instead of region. This issue has been quoted long time ago by @ojw28 in google/ExoPlayer#2953 (comment)

Here is an example of a sequence of 3 TTML subtitles that change the position of origin and extent, resulting on a jump of subtitles when the 2nd subtitle is on screen:

  1. origin & extent are defined in region
<tt
	xmlns="http://www.w3.org/ns/ttml"
	xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="">
	<head>
		<styling>
			<style xml:id="speakerStyle" tts:fontFamily="proportionalSansSerif" tts:fontSize="0.68c" tts:backgroundColor="transparent" tts:displayAlign="after" tts:color="white" tts:textOutline="black 2px" />
		</styling>
		<layout>
			<region xml:id="speaker_1" tts:origin="10% 60%" tts:extent="80% 35%" tts:textAlign="center" style="speakerStyle" tts:zIndex="1" />
			<region xml:id="speaker_2" tts:origin="12% 80%" tts:extent="75% 16%" tts:textAlign="center" style="speakerStyle" tts:zIndex="1" />
		</layout>
	</head>
	<body>
		<div>
			<p begin="87327:40:41.026" end="87327:40:41.186" region="speaker_1"></p>
			<p begin="87327:40:41.186" end="87327:40:43.026" region="speaker_2">
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">C&apos;est un réservoir d&apos;eau douce,</span>
				<br />
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">bien utile pour les Inuits.</span>
			</p>
		</div>
	</body>
</tt>
  1. origin & extent are defined in style
<?xml version="1.0" encoding="utf-8"?>
<tt
	xmlns="http://www.w3.org/ns/ttml"
	xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="">
	<head>
		<styling>
			<style xml:id="speakerStyle" tts:fontFamily="proportionalSansSerif" tts:fontSize="0.68c" tts:origin="12% 80%" tts:extent="75% 16%" tts:textAlign="center" tts:backgroundColor="transparent" tts:displayAlign="after" tts:color="white" tts:textOutline="black 2px" />
		</styling>
		<layout>
			<region xml:id="speaker" style="speakerStyle" tts:zIndex="1" />
		</layout>
	</head>
	<body>
		<div>
			<p begin="87327:40:43.026" end="87327:40:45.026" region="speaker">
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">C&apos;est un réservoir d&apos;eau douce,</span>
				<br />
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">bien utile pour les Inuits.</span>
			</p>
		</div>
	</body>
</tt>
  1. origin & extent are defined again in region
<?xml version="1.0" encoding="utf-8"?>
<tt
	xmlns="http://www.w3.org/ns/ttml"
	xmlns:tts="http://www.w3.org/ns/ttml#styling" xml:lang="">
	<head>
		<styling>
			<style xml:id="speakerStyle" tts:fontFamily="proportionalSansSerif" tts:fontSize="0.68c" tts:backgroundColor="transparent" tts:displayAlign="after" tts:color="white" tts:textOutline="black 2px" />
		</styling>
		<layout>
			<region xml:id="speaker_1" tts:origin="12% 80%" tts:extent="75% 16%" tts:textAlign="center" style="speakerStyle" tts:zIndex="1" />
			<region xml:id="speaker_2" tts:origin="10% 60%" tts:extent="80% 35%" tts:textAlign="center" style="speakerStyle" tts:zIndex="1" />
			<region xml:id="speaker_3" tts:origin="9% 80%" tts:extent="80% 16%" tts:textAlign="center" style="speakerStyle" tts:zIndex="1" />
		</layout>
	</head>
	<body>
		<div>
			<p begin="87327:40:45.026" end="87327:40:45.706" region="speaker_1">
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">C&apos;est un réservoir d&apos;eau douce,</span>
				<br />
				<span tts:color="cyan" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">bien utile pour les Inuits.</span>
			</p>
			<p begin="87327:40:45.706" end="87327:40:46.066" region="speaker_2"></p>
			<p begin="87327:40:46.066" end="87327:40:47.026" region="speaker_3">
				<span tts:color="green" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">-On va enlever la 1re couche.</span>
				<br />
				<span tts:color="green" tts:fontStyle="normal" tts:fontWeight="normal" tts:textDecoration="none">La glace sera meilleure, dessous.</span>
			</p>
		</div>
	</body>
</tt>

Note that this fix works only if styles are defined before regions.

Copy link

google-cla bot commented Dec 18, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant