Module: SMPTE

Defined in:
lib/smpte/base.rb,
lib/smpte/version.rb

Overview

Ruby SMPTE time class

By Michael Chaney, Michael Chaney Consulting Corporation Copyright 2014 Michael Chaney Consulting Corporation, All Rights Reserved

Released publicly under the terms of the MIT License or GNU Public License v2.

# smpte for 1 hour, 50 minutes, and 30 seconds smpte = SMPTE.new(‘01:50:30’) smpte.to_i

=> 198900

smpte2 = SMPTE.new(‘01:20:00’) smpte - smpte2

> #<SMPTE:0x00000100d42b40 @frames=0, @seconds=30, @minutes=30, @hours=0, @has_frames=true, @has_subframes=false, @frame_count=54900, @df=“ndf”, @ten_minute_periods=0>

smpte4 = SMPTE.new(107892, ‘df’) smpte4.to_s

> “01:00:00;00”

smpte5 = SMPTE.new(108000, ‘ndf’) smpte5.to_s

> “01:00:00:00”

Methods “to_i”, “to_f” and “to_s” are available to convert to integer (frame count), float (frame count with optional subframe count) and string respectively.

You can use “+” to add an integer number of frames to a SMPTE which will return another SMPTE,

You can use “-” to subtract one SMPTE from another returning a SMPTE.

You can use “<=>” to compare two SMPTE objects. Enumerable is mixed in to give you “<”, “>”, etc.

Note that the SMPTE objects are immutable.

The constructor can accept one of the following: string in SMPTE format (HH:MM:SS:FF.SF) where “FF” is a frame count and “SF” is subframes count (both optional) string in SMPTE format (HH:MM:SS;FF.SF) Note the semi-colon - this forced “drop frame format” (see below)

integer - frame count float - frame count - decimal portion is subframes SMPTE - another SMPTE

The second parameter to the initializer is “df” or “ndf” for “drop frame” and “non-drop frame” format respectively. The default is “ndf” unless the frame count is preceded by a semi-colon in which case the default is “df”.

Drop Frame vs. Non-Drop Frame format

Drop frame format: Two frame numbers - “00” and “01” - are dropped every minute ( 2 x 60 = 120 frame numbers ) EXCEPT for minute points that have a “0” number - 00, 10, 20, 30, 40 and 50 minutes - ( 2 x 6 = 12 frames ). This results in 120-12 or 108 frame numbers (not frames) being skipped.

One hour of NTSC video has 107,892 instead of 108,000 frames. Ten minutes of NTSC video has 17,982 frames instead of 18,000.

Defined Under Namespace

Classes: InvalidParameterError, SMPTE, SMPTEError

Constant Summary collapse

VERSION =
'1.0.3'