View Single Post
Old 06-05-2016, 08:43 AM   #19
mrlimbic
Human being with feelings
 
mrlimbic's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 669
Default

If it helps here are some drop frame calculations below for 29.97 in my code that I adapted from Andrew Duncan. http://andrewduncan.net/timecodes/

Remember that relevant frame durations are 1001/30000 and 1001/24000 and 1001/60000 for NTSC. Replace 1001 with 1000 for non NTSC.

Don't try to use the number 29.97 or 23.98 in calculations. Use how they are derived.

Also it turned out easier and more accurate for me to do many calculations in Vordio using rational numbers instead of floats.

I learned this from FCPX where all times are done as rationals. It makes mixed frame and sample rate calculations really easy.

Code:
<audio lane="-1" offset="33117926400/720000s" ref="r3" duration="8697600/720000s" start="33117926400/720000s"
To convert from reaper's floats I just multiply time by project sample rate over project sample rate and round to nearest sample to get a rational.

Code:
	public long toFrames(long h, long m, long s, long f) {
		if (ntsc) {			
			if (drop) {
				if (timebase == 30) {
					// Formula from http://andrewduncan.net/timecodes/
					long totalMinutes = 60 * h + m;
					return 108000 * h + 1800 * m + 30 * s + f - 2 * (totalMinutes - totalMinutes / 10);					



	public long[] toHMSF(long frames) {
		if (ntsc) {
			if (drop) {
				if (timebase == 30) {
					// Formula from http://andrewduncan.net/timecodes/
					long D = frames / 17982;
					long M = frames % 17982;
					frames += 18*D + 2*((M - 2) / 1798);
//				    (If -2 div 1798 doesn't return 0, you'll have to special-case M = 0 or 1.)
					long f = frames % 30;
					long s = (frames / 30) % 60;
					long m =  ((frames / 30) / 60) % 60;
					long h   = (((frames / 30) / 60) / 60) % 24;
					return new long[] { h, m, s, f };
__________________
Vordio - Post Production Toolkit
http://vordio.net

Last edited by mrlimbic; 06-05-2016 at 09:05 AM.
mrlimbic is offline   Reply With Quote