Last active
February 1, 2021 09:41
-
-
Save silverbeak/419dabf8d062afbe992e5802666f31d4 to your computer and use it in GitHub Desktop.
An XSLT transform I use for converting itt-formatted subtitles to srt-formatted subtitles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!-- | |
This will convert itt-formatted subtitles to srt-formatted subtitles (or captions, if you prefer that) | |
Use it like so (using xsltproc in this example, feel free to use whatever engine you like): | |
# xsltproc itt-to-srt.xslt input_in_itt.itt > output_in_srt.srt | |
--> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:ttp="http://www.w3.org/ns/ttml#parameter" | |
xmlns:tt_feature="http://www.w3.org/ns/ttml/feature/" | |
xmlns:tts="http://www.w3.org/ns/ttml#styling" | |
xmlns:tt_extension="http://www.w3.org/ns/ttml/extension/" | |
xmlns:tt_profile="http://www.w3.org/ns/ttml/profile/" | |
xmlns:ttm="http://www.w3.org/ns/ttml#metadata" | |
xmlns:ry="http://namespace.itunes.apple.com/itt/ttml-extension#ruby" | |
xmlns="http://www.w3.org/ns/ttml" | |
ttp:frameRate="50" | |
ttp:frameRateMultiplier="1 1" | |
xml:lang="en" xmlns:tt="http://www.w3.org/ns/ttml" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
ttp:dropMode="nonDrop" | |
ttp:timeBase="smpte" | |
> | |
<xsl:output method="text" omit-xml-declaration="yes" indent="no" /> | |
<xsl:strip-space elements="*" /> | |
<xsl:template match="/tt:tt/tt:body"> | |
<xsl:apply-templates/> | |
</xsl:template> | |
<xsl:template match="/tt:tt/tt:head"> | |
</xsl:template> | |
<xsl:template match="tt:div/tt:p/tt:span/tt:br"> | |
<xsl:text>
</xsl:text> | |
</xsl:template> | |
<xsl:template match="tt:div"> | |
<xsl:for-each select="tt:p"> | |
<xsl:value-of select="position()"/> | |
<xsl:text>
</xsl:text> | |
<xsl:value-of select='substring(@begin, 0, 9)' />,<xsl:value-of select='concat(substring(@begin, 10, 12), 0)' /> --> <xsl:value-of select='substring(@end, 0, 9)' />,<xsl:value-of select='concat(substring(@end, 10, 12), 0)' /> | |
<xsl:text>
</xsl:text> | |
<xsl:apply-templates select="tt:span"/> | |
<xsl:text>
</xsl:text> | |
<xsl:text>
</xsl:text> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Bilal. That sounds awesome. I'm by no means an expert in any of this. I just hacked something together that worked for me at the time. I even forgot that I had this Gist. :)
Please feel free to improve on it. I'll be happy to update the Gist if you like.