Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wfoxall committed Apr 26, 2022
2 parents 31d1a0e + 1535963 commit 1648bc4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 28 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ npm install @wfoxall/timeframe

### Timecode Class

Import the `Timecode` class and create an instance.

```typescript
import {Timecode} from '@wfoxall/timeframe';

const tc = new Timecode('00:01:02:03',"29.97DF");

console.log(tc.toString());
// 00;01;02;03
```

A `TimecodeError` is thrown if the supplied string or framerate are invalid or incompatible. And the `toString()` class will take care of formatting the timecode correctly (e.g. semicolons for drop timecode).

Timecodes can be instantiated from a string or framecount, and the framerate can be expressed in any of several ways too (see [Framerate class](#Framerate-Class)):

```typescript
const tc1 = new Timecode('00:01:01:00',"29.97DF");
console.log(tc1.toString());
// 00;01;01;00
Expand All @@ -26,7 +39,11 @@ console.log(tc2.toString());
const tc3 = new Timecode(12345,29.97); // 29.97 and 59.94 numbers are interpretted as drop-frame by default
console.log(tc3.toString());
// 00;06;51;27
```

You can add and subtract timecodes (with matching framerates) using the static method on the Timecode class, or with the method on an existing timecode object:

```typescript
let sum = Timecode.add(tc1,tc2); // Immutable - tc1 and tc2 remain unchanged.
console.log(sum.toString());
// 00;02;03;15
Expand All @@ -38,7 +55,17 @@ console.log(tc1.toString());

### Framerate Class

Framerate objects can be instantiated by passing a FramerateLike value. The resulting object can then be used to initialize a Timecode instance.
Framerate objects can be instantiated by passing a `FramerateLike` value. This can be a string, number or object as follows:

```typescript
let fr1 = "59.94DF"
let fr2 = 59.94
let fr3 = {numer:60000,denom:1001,drop:true}
```

This is particularly useful when marshalling framerates from various formats. For example, some video APIs like to express framerates as a fraction (eg. 29.97 is expressed as 30000/1001).

The resulting Framerate instance can then be used to initialize a Timecode instance.

```typescript
import {Framerate} from '@wfoxall/timeframe';
Expand All @@ -51,7 +78,6 @@ const tc = new Timecode("01:59:59:28",fr1);
console.log(tc.toString());
// 01;59;59;28
```

As framerates can be expressed in multiple formats, this is useful for marshelling the same framerate into the same uniform type. For example, the following are the same framerate:
```typescript
let fr1 = "59.94DF"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wfoxall/timeframe",
"version": "1.1.0",
"description": "A javascript library for parsing and manipulatio of SMPTE/EBU/Generic timecodes, framerates and framecounts.",
"description": "A javascript library for parsing and manipulation of SMPTE/EBU/Generic timecodes, framerates and framecounts.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
Expand Down

0 comments on commit 1648bc4

Please sign in to comment.