|
1 | | -# @spiretechnology/js-timecode |
| 1 | +# js-timecode |
2 | 2 |
|
3 | | -SMPTE timecode parser and formatter for JavaScript and TypeScript. |
| 3 | +A TypeScript / JavaScript library for parsing and manipulating SMPTE timecodes and frame rates. |
| 4 | + |
| 5 | +Development of this library is very test-driven to ensure accuracy of the frame and timecode calculations. If you'd like to contribute to this library, adding additional useful test cases is a great place to start! |
| 6 | + |
| 7 | +## Installation |
| 8 | + |
| 9 | +```sh |
| 10 | +npm install --save @spiretechnology/js-timecode |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage Examples |
| 14 | + |
| 15 | +### Parse a timecode (drop frame) |
| 16 | + |
| 17 | +```ts |
| 18 | +import { Parse, Rate_23_976 } from '@spiretechnology/js-timecode'; |
| 19 | + |
| 20 | +const tc = Parse('00:01:02;23', Rate_23_976); |
| 21 | +tc.toString(); // => 00:01:02;23 |
| 22 | +tc.frame; // => 1509 |
| 23 | +``` |
| 24 | + |
| 25 | +### Parse a timecode (non-drop frame) |
| 26 | + |
| 27 | +```ts |
| 28 | +const tc = Parse('00:01:02:23', Rate_24); |
| 29 | +tc.toString(); // => 00:01:02:23 |
| 30 | +tc.frame; // => 1511 |
| 31 | +``` |
| 32 | + |
| 33 | +### Create a timecode from a frame count |
| 34 | + |
| 35 | +```ts |
| 36 | +const tc = new Timecode(1511, Rate_24, false /* non-drop frame */); |
| 37 | +tc.toString(); // => 00:01:02:23 |
| 38 | +tc.frame; // => 1511 |
| 39 | +``` |
| 40 | + |
| 41 | +### Algebra with timecodes and frames |
| 42 | + |
| 43 | +```ts |
| 44 | +let tc = Parse('00:01:02:23', Rate_24); |
| 45 | +tc = tc.add(3); |
| 46 | +tc.toString(); // => 00:01:03:02 |
| 47 | +tc.frame; // => 1514 |
| 48 | +``` |
| 49 | + |
| 50 | +## Note: parsing timecodes that don't exist in drop frame |
| 51 | + |
| 52 | +Drop frame timecodes skip the first 2 frames of each minute, unless the minute is a multiple of 10. This changes to the first 4 frames of each minute if the frame rate is 59.94. |
| 53 | + |
| 54 | +For instance, in `23.976`, the timecode `00:00:59:23` is immediately followed by `00:01:00:02`. Two timecodes were dropped: `00:01:00:00` and `00:01:00:01` |
| 55 | + |
| 56 | +Those dropped timecodes don't correspond to any actual frame number, and so we need to choose how to resolve those frames. The choice we have made with this library is to round up the next valid frame. If you try to parse `00:01:00:00`, the result will be rounded up to `00:01:00:02`, which is the next valid frame in the sequence. |
| 57 | + |
| 58 | +## Contributing |
| 59 | + |
| 60 | +We welcome contributions that make this library more reliable. To add test cases, fix bugs, or anything else, please submit a pull request. |
| 61 | + |
| 62 | +## Other resources |
| 63 | + |
| 64 | +- [spiretechnology/go-timecode](https://github.com/spiretechnology.com/go-timecode) - A Go library for parsing and manipulating SMPTE timecodes and frame rates. |
0 commit comments