Counting Modes

A CountingMode defines the frame counting behavior of a Timecode or TimecodeRange object. It also handles string formatting, as different modes may be represented differently (e.g. DropFrame timecode traditionally uses a ; separator).

class timecode.modes.CountingMode

An abstract class to facilitate timecode frame counting modes

Two of the most common modes are provided: NonDropFrame and DropFrame. Additional modes may be created by subclassing the CountingMode class.

Note

The CountingMode classes are provided in the timecode.modes subpackage.

Using a Counting Mode

A CountingMode is typically provided by setting the mode parameter to an instance of a CountingMode during the creation of a Timecode object:

>>> from timecode import Timecode
>>> from timecode.modes import DropFrame, NonDropFrame
>>> Timecode("01:00:00:00", mode=DropFrame())
<Timecode 01;00;00;00 @ 30 DF>

See also: Specifying The Counting Mode

Defaults

A CountingMode defines a default rate to use if the rate is not explicitly set during the creation of a Timecode object. It may also define additional rules to validate the rate. Below are the defaults and rules for the out-of-the-box CountingMode classes:

Mode

Default Rate

Additional Rules

NonDropFrame

24

Rate must be a positive integer

DropFrame

30

Rate must be a positive integer, and a multiple of 30

Here we illustrate the default rates and rate validation:

>>> from timecode import Timecode
>>> from timecode.modes import DropFrame, NonDropFrame
..
>>> # NonDropFrame defaults to 24 fps
>>> Timecode("01:00:00:00", mode=NonDropFrame())
<Timecode 01:00:00:00 @ 24 NDF>
..
>>> # DropFrame defaults to 30 fps
>>> Timecode("01:00:00:00", mode=DropFrame())
<Timecode 01;00;00;00 @ 30 DF>
..
>>> # DropFrame throws a `ValueError` for rates
>>> # that are not multiples of 30
>>> Timecode("01:00:00:00", mode=DropFrame(), rate=24)
ValueError: Drop Frame mode requires the rate to be a multiple of 30.

See also: Specifying The Rate

More Info

See timecode.modes.CountingMode in the API Documentation.