A pure, dependency free, XSLT 1.0 library for video timecode manipulation.
- Any frame rate
- Drop/nondrop frame timecodes
- Arithmetic
- Conversions: to/from drop/nondrop, timecode to/from frames
- Formatting
- Field extraction
Setup the timecode namespace:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tc="http://screenstaring.com/xslt/timecode">
Import (or include) the stylesheet:
<xsl:import href="/path/to/timecode.xsl"/>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tc="http://screenstaring.com/xslt/timecode">
<xsl:import href="timecode.xsl"/>
<!-- Returns: 1800 -->
<xsl:variable name="frames">
<xsl:call-template name="tc:to-frames">
<xsl:with-param name="timecode">00:00:01:02</xsl:with-param>
<xsl:with-param name="drop-frame" select="true()"/>
</xsl:call-template>
</xsl:variable>
<!-- No need to set $drop-frame if the timecode has a drop frame delimiter (";" or ".") -->
<!-- Returns: 1800 -->
<xsl:variable name="frames">
<xsl:call-template name="tc:to-frames">
<xsl:with-param name="timecode">00:00:01;02</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- Returns: 00:30:22:14 -->
<xsl:variable name="timecode>
<xsl:call-template name="tc:from-frames">
<xsl:with-param name="frames">54674</xsl:with-param>
<xsl:with-param name="fps">29.97</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- Returns: 02:00:00:00 -->
<xsl:variable name="sum">
<xsl:call-template name="tc:add">
<xsl:with-param name="timecode1">01:59:59:29</xsl:with-param>
<xsl:with-param name="timecode2">00:00:00:01</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="product">
<xsl:call-template name="tc:multiply>
<xsl:with-param name="timecode">00:10:59:02</xsl:with-param>
<xsl:with-param name="by">2</xsl:with-param>
<xsl:with-param name="fps">24</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<!-- Extract the minutes -->
<!-- Returns: 10 -->
<xsl:variable name="minutes>
<xsl:call-template name="tc:minutes">
<xsl:with-param name="timecode">00:10:21;22</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- Under Saxon,
to-framesreturns a value in scientific notation
Unless specified when calling a template frames per second defaults to 29.97. This can be changed
globally by setting default-fps.
All drop frame arguments default to false(). If the drop frame parameter is not set and the timecode's frame delimiter
is "." or ";" the timecode will be treated as drop frame.
Templates return "NaN" on error. This is a string and should not be confused with the XPath numeric type of NaN.
On success the resulting timecode is returned.
timecode1- Left operand, requiredfps1-timecode1's frames per seconddrop-frame1- Set totrue()iftimecode1is drop frametimecode2- Right operand, requiredfps2-timecode2's frames per seconddrop-frame2- Set totrue()iftimecode2is drop frame
timecode- Numerator, requiredby- Denominator, required. This is a numeric value, not a timecodefps- Frames per second oftimecode
timecode- A timecode to multiply, requiredby- Value to multiply timecode by, required. This is a numeric value, not a timecodefps- Frames per second oftimecodedrop-frame-true()iftimecodeis drop frame, defaults tofalse()
timecode1- Left operand, requiredfps1-timecode1's frames per seconddrop-frame1- Set totrue()iftimecode1is drop frametimecode2- Right operand, requiredfps2-timecode2's frames per seconddrop-frame2- Set totrue()iftimecode2is drop frame
Convert a timecode's frame rate, format, or to/from drop frame.
timecode- Timecode to convert, requiredfps-timecode's frames per seconddrop-frame- Set totrue()iftimecodeis drop frameto-fps- Frames per second to converttimecodetoto-drop-frame- Converttimecodeto drop framedelimiter- String use to delimit the hours, minutes, and seconds in the resulting timecode, defaults to":"frame-delimiter- String use to delimit frames in the resulting timecode, defaults to":"
Converts the given timecode to frames.
timecode- Timecode to convert, requiredfps-timecode's frames per seconddrop-frame- Set totrue()iftimecodeis a drop frame
On success the frame representation of the timecode. On error an empty string.
Extract the hours part from the given timecode.
timecode- Timecode to extract hours from, required
On success the hour part of timecode. On error an empty string.
Extract the minutes part from the given timecode.
timecode- Timecode to extract minutes from, required
On success the minute part of timecode. On error an empty string.
Extract the seconds part from the given timecode.
timecode- Timecode to extract seconds from, required
On success the second part of timecode. On error an empty string.
Extract the frames part from the given timecode.
timecode- Timecode to extract frames from, required
On success the frame part of timecode. On error an empty string.
Create a timecode from the given number of frames.
frames- Frames to create a timecode from, requiredfps-framesframes per seconddrop-frame- Set totrue()ifframesare drop framesdelimiter- String use to delimit the hours, minutes, and seconds in the resulting timecode, defaults to":"frame-delimiter- String use to delimit frames in the resulting timecode, defaults to":"
On success a timecode. On error an empty string.
Check if the given timecode is valid
timecode- Timecode to validate, required
"true" if timecode is valid, "false" otherwise.
Note that this is a string and not an XPath boolean as returned by true() or false().
This library is a port of the Perl Time::Timecode module,
though it does not (yet) implement all of Time::Timecode's functionality.
Skye Shaw (skye.shaw [AT] gmail)
Copyright (C) 2011-2016 Skye Shaw
Released under the MIT License: www.opensource.org/licenses/MIT