https://github.com/sshaw/xslt-timecode
A pure, dependency free, XSLT 1.0 library for video timecode manipulation
https://github.com/sshaw/xslt-timecode
conversions drop-frames frame-rate timecode video-timecode-manipulation xml xslt
Last synced: 16 days ago
JSON representation
A pure, dependency free, XSLT 1.0 library for video timecode manipulation
- Host: GitHub
- URL: https://github.com/sshaw/xslt-timecode
- Owner: sshaw
- Created: 2016-08-28T15:50:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-29T00:06:38.000Z (over 9 years ago)
- Last Synced: 2025-02-12T06:59:43.242Z (about 1 year ago)
- Topics: conversions, drop-frames, frame-rate, timecode, video-timecode-manipulation, xml, xslt
- Language: XSLT
- Size: 13.7 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Timecode
=======
[](https://travis-ci.org/sshaw/xslt-timecode)
A pure, dependency free, XSLT 1.0 library for video timecode manipulation.
Supports
---------
* Any frame rate
* Drop/nondrop frame timecodes
* Arithmetic
* Conversions: to/from drop/nondrop, timecode to/from frames
* Formatting
* Field extraction
Usage
---------
Setup the timecode namespace:
Import (or include) the stylesheet:
Examples
---------
00:00:01:02
00:00:01;02
54674
29.97
01:59:59:29
00:00:00:01
00:10:59:02
2
24
00:10:21;22
Known Issues
---------
* Under Saxon, `to-frames` returns a value in scientific notation
Templates
---------
* [Overview](#overview)
* [Arithmetic](#arithmetic)
* [Conversion](#conversion)
* [Parsing & Formatting](#parsingformatting)
* [Validation](#validation)
### Overview
#### Frames Per Second (FPS)
Unless specified when calling a template frames per second defaults to `29.97`. This can be changed
globally by setting `default-fps`.
#### Drop Frame
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.
### Arithmetic
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.
#### `add`
##### Parameters
* `timecode1` - Left operand, **required**
* `fps1` - `timecode1`'s frames per second
* `drop-frame1` - Set to `true()` if `timecode1` is drop frame
* `timecode2` - Right operand, **required**
* `fps2` - `timecode2`'s frames per second
* `drop-frame2` - Set to `true()` if `timecode2` is drop frame
#### `divide`
##### Parameters
* `timecode` - Numerator, **required**
* `by` - Denominator, **required**. This is a numeric value, not a timecode
* `fps` - Frames per second of `timecode`
#### `multiply`
##### Parameters
* `timecode` - A timecode to multiply, **required**
* `by` - Value to multiply timecode by, **required**. This is a numeric value, not a timecode
* `fps` - Frames per second of `timecode`
* `drop-frame` - `true()` if `timecode` is drop frame, defaults to `false()`
#### `subtract`
##### Parameters
* `timecode1` - Left operand, **required**
* `fps1` - `timecode1`'s frames per second
* `drop-frame1` - Set to `true()` if `timecode1` is drop frame
* `timecode2` - Right operand, **required**
* `fps2` - `timecode2`'s frames per second
* `drop-frame2` - Set to `true()` if `timecode2` is drop frame
### Conversion
#### `convert`
Convert a timecode's frame rate, format, or to/from drop frame.
* `timecode` - Timecode to convert, **required**
* `fps` - `timecode`'s frames per second
* `drop-frame` - Set to `true()` if `timecode` is drop frame
* `to-fps` - Frames per second to convert `timecode` to
* `to-drop-frame` - Convert `timecode` to drop frame
* `delimiter` - 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 `":"`
#### `to-frames`
Converts the given timecode to frames.
##### Parameters
* `timecode` - Timecode to convert, **required**
* `fps` - `timecode`'s frames per second
* `drop-frame` - Set to `true()` if `timecode` is a drop frame
##### Returns
On success the frame representation of the `timecode`. On error an empty string.
### Parsing/Formatting
#### `hours`
Extract the hours part from the given timecode.
##### Parmeters
* `timecode` - Timecode to extract hours from, **required**
##### Returns
On success the hour part of `timecode`. On error an empty string.
#### `minutes`
Extract the minutes part from the given timecode.
##### Parameters
* `timecode` - Timecode to extract minutes from, **required**
##### Returns
On success the minute part of `timecode`. On error an empty string.
#### `seconds`
Extract the seconds part from the given timecode.
##### Parameters
* `timecode` - Timecode to extract seconds from, **required**
##### Returns
On success the second part of `timecode`. On error an empty string.
#### `frames`
Extract the frames part from the given timecode.
##### Parameters
* `timecode` - Timecode to extract frames from, **required**
##### Returns
On success the frame part of `timecode`. On error an empty string.
#### `from-frames`
Create a timecode from the given number of frames.
##### Parameters
* `frames` - Frames to create a timecode from, **required**
* `fps` - `frames` frames per second
* `drop-frame` - Set to `true()` if `frames` are drop frames
* `delimiter` - 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 `":"`
##### Returns
On success a timecode. On error an empty string.
### Validation
#### `valid`
Check if the given timecode is valid
##### Parameters
* `timecode` - Timecode to validate, **required**
##### Returns
`"true"` if `timecode` is valid, `"false"` otherwise.
Note that this is a string and not an XPath boolean as returned by `true()` or `false()`.
About
---------
This library is a port of the Perl [`Time::Timecode`](https://github.com/sshaw/Time-Timecode) module,
though it does not (yet) implement all of `Time::Timecode`'s functionality.
Author
---------
Skye Shaw (skye.shaw [AT] gmail)
License
---------
Copyright (C) 2011-2016 Skye Shaw
Released under the MIT License: www.opensource.org/licenses/MIT