Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting timecodes with 3 digits for milliseconds #5

Open
pietrop opened this issue Jul 8, 2018 · 4 comments
Open

converting timecodes with 3 digits for milliseconds #5

pietrop opened this issue Jul 8, 2018 · 4 comments

Comments

@pietrop
Copy link

pietrop commented Jul 8, 2018

First of all thanks for the great module, been using it as part of autoEdit_2, text based video editing app.

However I've run into a use case when I am not sure how would I convert a timecode like this '00:33:19,470' where the timestamp format is hh:mm:sss,fff where fff represents milliseconds?


I tried this in npm runkit

using this code

var nodeTimecodes = require("node-timecodes")
console.log(nodeTimecodes.toSeconds('00:33:19,470')); 

and as expected it gives a bunch of errors.

Object.toSeconds in node-timecodes/dist/toSeconds.js — line 16

 var frameRate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _constants.framerate;
  if (!TIMECODE_REGEXP.test(timecode)) {
    throw new Error('invalid timecode : ' + timecode);
  }
  if (typeof timecode === 'number') {
    return timecode;
@charlesritchea
Copy link

@pietrop Try replacing the comma ',' with a period / full-stop '.' which is the decimal in the US

@patrick99e99
Copy link

patrick99e99 commented Jun 24, 2019

@novaterata

I am not sure why you say a period would help? The regex the input is being tested against explictly wants a colon at the end: /\d+\:\d+\:\d+\:\d+/

https://github.com/Synchronized-TV/node-timecodes/blob/master/src/toSeconds.js#L5

It would be nice if this library supported a user supplied custom frame delimiter ':', '.', ',', etc.

timecodes.fromSeconds(1427.4, { frameDelimiter: '.' }); // -> '00:23:47.10'

etc...

@jide
Copy link
Contributor

jide commented Jun 24, 2019

The usage of a period is widely used and is some kind of standard.

https://en.wikipedia.org/wiki/SMPTE_timecode :

While non-drop timecode is displayed with colons separating the digit pairs—"HH:MM:SS:FF"—drop-frame is usually represented with a semicolon (;) or period (.) as the divider between all the digit pairs—"HH;MM;SS;FF", "HH.MM.SS.FF"—or just between the seconds and frames—"HH:MM:SS;FF" or "HH:MM:SS.FF". The period is usually used on VTRs and other devices that don't have the ability to display a semicolon.

It's really easy to just convert the dot yourself ? :

timecodes.toSeconds(myTimecode.replace(',', '.'));

timecodes.fromSeconds(1427.4).replace('.', ',');

@patrick99e99
Copy link

patrick99e99 commented Jun 24, 2019

@jide I feel like the point of this issue is getting confused.

The problem is, the library expects frames to be specified with a colon. @pietrop is working with "," as a frame delimiter, and I myself am working with a period being a delimiter. Your first example will not work with the current implementation which throws an error if the input does not match the regex /\d+\:\d+\:\d+\:\d+/

With the current implementation your second example would actually need to be:
timecodes.fromSeconds(1427.4).replace(/:(\d+)$/, ',$1');

Because frames are delimited with ':' not '.'--- which is why I said, it would be nice if this library would accommodate a custom frame delimiter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants