Cwmwenallt Musings

November 24, 2010

Mini-series: W3C Timed Text (TTML)

Filed under: Timed text, Work — Sean @ 1:06 pm

 

Having been involved with TTML now for best part of a decade, and with it finally coming to be a W3C recommendation as of 18th of November, it’s something of an end-of-era time for me. So following on from my last post , I thought I’d develop a little series talking about TTML, what it is, why it is what it is, and also expand a little on how I think we should go about integrating it into HTML5. I’ve written up a draft specification for this, and this is essentially what I’ve implemented in my Javascript demo. (I toyed with the idea of trying to do it inline here, but not sure how Wordpress would handle it).

The aim of this script is to make it drop dead simple to add TTML based closed captions, subtitles, chapter marks etc to your <video> page; all that is required is to add this line into the <head> section of your HTML:

<script src="ttml.js" type="text/javascript" > </script>

Point to the location of the script, then you need to add new <track> elements to point to your caption/subtitle/karaoke file(s). In the demo I use three track files:

       <video id="theVideo" controls="controls" poster="RealPCPride_Thumb.jpg">
            <source src="RealPCPride.mp4" type="video/mp4" />
            <source src="RealPCPride.ogg" type="video/ogg" />
            <track src="RealPCPride.wmv.en.captions.xml" kind="captions" srclang="en-US" label="English captions" />
            <track src="RealPCPride.wmv.en.descriptions.xml kind="captions" srclang="en-US" label="English text descriptions" />
            <track src="RealPCPride.wmv.en.xml kind="subtitles" srclang="en" label="English captions and text descriptions" /> 
                Short video from the “I’m A PC” ad campaign..  (needs HTML 5 capable browser)
        </video>

The script will add a selection element into the page, enabling the user to choose between them. That’s it!

The script is currently working in IE9 beta and Firefox 3+, and I’m working on Safari support. Still stuff to do; in particular styling the select so that it looks a little more integrated with the native video controls and handling multiple video elements.  I’m also currently scoping out how chapter files should operate. But the basic caption and subtitle kinds are reasonably well supported. You should also notice that the demo adds a second video for sign translation, which is synchronised with the main video. HTML 5 doesn’t actually add tools for this yet, so this is achieved using a second video element and some script, eventually I’ll add in support so that the sign translation can be inserted using the <track> mechanism.

Without getting into the details (see the specification for that), roughly what this does is analyse the timed text file for the content that should be active at the current playback time, and then inserts equivalent elements into the host DOM.

One nice feature of this approach is that since the timed text gets integrated into the live DOM of the page, you can override the built in styles of the caption file. The script converts any role and xml:id attributes it finds in the timed text, into class and id attributes and maps the <region> element to a div with @class=”ttml_cue”  currently I prefix these with ”ttml_” to try and reduce clashes with the host page; not sure if there is a cleaner way to do this without better namespace support.

Anyway, now if I have a caption like the following :

<p xml:id='subtitle1a' ttm:role='caption' begin='00:00:00:27' end='00:00:02:22'
>Sean: Hello.  I’m a PC,</p>

Then in my page CSS I can add a rule like:

.ttml_caption  {
	font-style:italic!important;
 }

This will override all the captions to be italic, and if I want to be specific:

#ttml_subtitle1a  {
	color:red!important;
}

Obviously if you want the TTML to take precedence, and only provide defaults for styles the TTML doesn’t specify, you can leave out the !important keyword.

OK, hopefully that’s given enough of an introduction, there’s lots more to say; next time we’ll get a little more into what Timed Text is all about.

Ciao.

Sean.

November 18, 2010

Windows Live Writer Test

Filed under: Accessibility, Timed text, Work — Tags: — Sean @ 2:02 pm

OK, so this blog hasn’t been updated much recently; I’ve been busy OK. Rest assured there is another stringed thing project in the pipeline, based on an art box and a resonator kit; but that’s for the future.

One of the things I’ve been busy with recently at work is the HTML5 working group, and in particular the choice (or preferably non-choice) of caption format. Now that the <track> element seems to be stabilising,  I’ve put together a demo of how captions , text description and and subtitles in  W3C Timed text could be integrated using just this feature now, rather than waiting for the browser implementations to catch up. To make sure its cross browser, I decided to do it all in Javascript. If this remotely interests you, the current demo is here You’ll need IE9 or a recent build of Firefox to view it (Sorry Safari users, it doesn’t work for you yet; but I’m working on it; I’m not planning on testing Opera though).

If you don’t have an HTML 5 powered browser here’s a screenshot:

screenshot of TTML demo in IE showing bill gates, a caption and a description

Longer term I aim to get this cleaned up and finished and posted on my Codeplex site (which also hasn’t seen much love recently) with audio descriptions, chapter navigation and stuff, so don’t go running off with the code just yet.

Oh, and the title? Yes this post was written using Windows Live Writer (soooo much nicer than hand crafting in notepad and pasting into Wordpress – one of the other reasons i haven’t blogged lately!)

ttfn.

Powered by WordPress