Created
August 12, 2018 00:03
-
-
Save mukunm/f3bb54a45c3009affecee817ab225907 to your computer and use it in GitHub Desktop.
tsSegmenter Code for Blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double numSegmentFrames = segmentDuration * frameRate; | |
if(keyFrameInt > numSegmentFrames) { | |
System.out.println("Key frame interval too high!"); | |
System.out.println(keyFrameInt + " > " + numSegmentFrames); | |
return; | |
} | |
if(numSegmentFrames % keyFrameInt == 0) { | |
System.out.println("Divisible inputs selected. Divide at every " + segmentDuration + "s"); | |
return; | |
} | |
double f0 = getWholeNumber(numSegmentFrames); | |
double numKeyFramesModder = f0 % keyFrameInt; | |
while (numKeyFramesModder != 0) { | |
f0--; | |
numKeyFramesModder = f0 % keyFrameInt; | |
} | |
double f1 = getWholeNumber(numSegmentFrames); | |
numKeyFramesModder = f1 % keyFrameInt; | |
while(numKeyFramesModder != 0) { | |
f1++; | |
numKeyFramesModder = f1 % keyFrameInt; | |
} | |
double t0 = f0 / frameRate; | |
double t1 = f1 / frameRate; | |
double a0 = 1.0; | |
double a1 = findA1(a0, segmentDuration, t0, t1); | |
while(isWholeNumber(a1) == false) { | |
a0++; | |
a1 = findA1(a0, segmentDuration, t0, t1); | |
} | |
System.out.println("\n=======Outputs========="); | |
System.out.println("a0 = " + a0); | |
System.out.println("a1 = " + getWholeNumber(a1)); | |
System.out.println("t0 = " + t0); | |
System.out.println("t1 = " + t1); | |
System.out.println("======= End ========="); | |
double verifyLHS = a0 * t0 + a1 * t1; | |
double verifyRHS = segmentDuration * (a0 + a1); | |
if(equals(verifyLHS, verifyRHS) == false) { | |
System.out.println("Invalid results Found!"); | |
System.out.println("verifyLHS = " + verifyLHS); | |
System.out.println("verifyRHS = " + verifyRHS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment