aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatt Braddock <matt.braddock@gmail.com> 2019-01-01 13:33:51 -0500
committerMatt Braddock <matt.braddock@gmail.com> 2019-01-01 13:33:51 -0500
commit251625624088ab6af6db03f29334ef845dbc3359 (patch)
tree396cef675d57886af9d5127525d819514e4e7b77
parent6ea7063ac4a1d417711bc1b36574419542b6688d (diff)
fixed frame timing from debug info
-rw-r--r--README.md2
-rw-r--r--main.js6
2 files changed, 5 insertions, 3 deletions
diff --git a/README.md b/README.md
index 9089135..957cf5d 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,2 @@
# yt-frame-timer
-A JavaScript-based program to determine the time between start and end points of a YouTube video down to the frame. Based on [https://docs.google.com/spreadsheets/d/1c3eiw1_00Tx1snAdU_kvncuA8C8xu5-q3tSOPRuqhzI/](https://docs.google.com/spreadsheets/d/1c3eiw1_00Tx1snAdU_kvncuA8C8xu5-q3tSOPRuqhzI/). \ No newline at end of file
+A JavaScript-based program to determine the time between start and end points of a YouTube video down to the frame. Based on [https://docs.google.com/spreadsheets/d/1c3eiw1_00Tx1snAdU_kvncuA8C8xu5-q3tSOPRuqhzI/](https://docs.google.com/spreadsheets/d/1c3eiw1_00Tx1snAdU_kvncuA8C8xu5-q3tSOPRuqhzI/) by Slush Puppy (big thanks to them for their work). \ No newline at end of file
diff --git a/main.js b/main.js
index 66e1e10..1deac10 100644
--- a/main.js
+++ b/main.js
@@ -8,8 +8,10 @@ function compute() {
let seconds = 0;
let milliseconds = 0;
let frameRate = parseInt(framerate);
- let diff = (endObj.lct - startObj.lct) * frameRate;
- let frames = diff;
+ let frameFromObj = (time, fps) => Math.floor(time * fps) / fps; //round to the nearest frame
+ let startFrame = frameFromObj(startObj.lct, frameRate);
+ let endFrame = frameFromObj(endObj.lct, frameRate);
+ let frames = (endFrame - startFrame) * frameRate;
if (frames >= frameRate) {
seconds = Math.floor(frames / frameRate);
frames = frames % frameRate;