Timecode
Timecode is good.
- class timecode.Timecode(timecode: str | int | Timecode, mode: CountingMode | None = None, rate: int | None = None)
Timecode representing a given frame number and rate
Specifying The Counting Mode
A CountingMode can be set during the creation of a Timecode object by setting the mode parameter.
NonDropFrame and DropFrame counting modes are available in the timecode.modes subpackage.
Timecode will default to NonDropFrame mode, unless otherwise specified.
>>> from timecode import Timecode
>>> from timecode.modes import DropFrame
..
>>> Timecode(86400, mode=DropFrame())
<Timecode 00;48;02;28 @ 30 DF>
The default counting mode can be set program-wide by assigning a CountingMode class to timecode.Timecode.DEFAULT_MODE
Note
Also included in the timecode.modes subpackage is an abstract class CountingMode, which can be subclassed to make your
own weird little counting modes. Give it a shot!
See also: Counting Modes
Specifying The Rate
Timecode will default to the DEFAULT_RATE set by the CountingMode. Or, it
may be explicitly set with the rate parameter.
>>> from timecode import Timecode
..
>>> Timecode("01:00:00:00", rate=30)
<Timecode 01:00:00:00 @ 30 NDF>
Warning
The CountingMode will validate the specified rate and may throw an exception if the rate is inappropriate. For example,
DropFrame only accepts frame rates which are multiples of 30.
Doin’ Math
Arithmetic
timecode.Timecode supports typical arithmetic operations (addition, subtraction, multiplication, and division) against
other timecode.Timecode objects, as well as other int-type numbers. If the operand is an int,
it will be assumed to be a frame number.
>>> # Add two `Timecode`s
>>> Timecode("01:00:01:00") + Timecode("02:03")
<Timecode 01:00:03:03 @ 24 NDF>
..
>>> # Add a `Timecode`` and some frames
>>> Timecode("59:59:00") + 24
<Timecode 01:00:00:00 @ 24 NDF>
Resampling
Oh! You can resample() a timecode.Timecode object from one rate and/or mode to another.
>>> from timecode import Timecode
>>> from timecode.modes import DropFrame, NonDropFrame
..
>>> Timecode("00:48:20:12", mode=NonDropFrame()).resample(rate=30)
<Timecode 00:48:20:15 @ 30 NDF>
..
>>> Timecode("00:48:20:15", rate=30, mode=NonDropFrame()).resample(mode=DropFrame())
<Timecode 00;48;23;13 (88) @ 30 DF>
More Info
See timecode.Timecode in the API Documentation.