UNPKG

@bbc/react-transcript-editor

Version:

A React component to make transcribing audio and video easier and faster.

19 lines 1.45 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/** * Raised in this comment https://github.com/bbc/react-transcript-editor/pull/9 * abstracted from https://github.com/bbc/newslabs-cdn/blob/master/js/20-bbcnpf.utils.js * In broadcast VIDEO, timecode is NOT hh:mm:ss:ms, it's hh:mm:ss:ff where ff is frames, * dependent on the framerate of the media concerned. * `hh:mm:ss:ff` */ /** * Helper function * Rounds to the 14milliseconds boundaries * Time in video can only "exist in" 14milliseconds boundaries. * This makes it possible for the HTML5 player to be frame accurate. * @param {*} seconds * @param {*} fps */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 function _padZero(n){return 10>n?"0".concat(parseInt(n)):parseInt(n)}// written for PAL non-drop timecode var 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;/* * @param {*} seconds * @param {*} fps */exports.default=_default;