UNPKG

1.45 kBJavaScriptView Raw
1"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/**
2* Raised in this comment https://github.com/bbc/react-transcript-editor/pull/9
3* abstracted from https://github.com/bbc/newslabs-cdn/blob/master/js/20-bbcnpf.utils.js
4* In broadcast VIDEO, timecode is NOT hh:mm:ss:ms, it's hh:mm:ss:ff where ff is frames,
5* dependent on the framerate of the media concerned.
6* `hh:mm:ss:ff`
7*/ /**
8 * Helper function
9 * Rounds to the 14milliseconds boundaries
10 * Time in video can only "exist in" 14milliseconds boundaries.
11 * This makes it possible for the HTML5 player to be frame accurate.
12 * @param {*} seconds
13 * @param {*} fps
14 */var normalisePlayerTime=function(seconds,fps){return+(1/fps*Math.floor(+(fps*seconds).toPrecision(12))).toFixed(2)},secondsToTimecode=function(seconds,framePerSeconds){// prepends zero - example pads 3 to 03
15function _padZero(n){return 10>n?"0".concat(parseInt(n)):parseInt(n)}// written for PAL non-drop timecode
16var fps=25;framePerSeconds!==void 0&&(fps=framePerSeconds);var normalisedSeconds=normalisePlayerTime(seconds,fps),wholeSeconds=Math.floor(normalisedSeconds),frames=((normalisedSeconds-wholeSeconds)*fps).toFixed(2);return"".concat(_padZero(wholeSeconds/60/60%60),":").concat(_padZero(wholeSeconds/60%60),":").concat(_padZero(wholeSeconds%60),":").concat(_padZero(frames))},_default=secondsToTimecode;/*
17* @param {*} seconds
18* @param {*} fps
19*/exports.default=_default;
\No newline at end of file