Example #1
0
size_t timecode_strftime (char *str, const size_t maxsize, const char *format, TimecodeTime const * const t, TimecodeRate const * const r) {
	Timecode tc;
	memset(&tc, 0, sizeof(Timecode));
	memcpy(&tc.t, t, sizeof(TimecodeTime));
	if (r) {
		memcpy(&tc.r, r, sizeof(TimecodeRate));
	} else {
		tc.r.num=tc.r.den=tc.r.subframes=1;
	}
	return timecode_strftimecode(str, maxsize, format, &tc);
}
Example #2
0
int main (int argc, char **argv) {
  int64_t magic = 964965602; // 05:34:43:11 @29.97ndf, 48kSPS
  //int64_t magic = 1601568888; //
	Timecode tc;
	memset(&tc, 0, sizeof(Timecode));

	checkfps(259199740, TCFPS2997DF, 48000);
	checkfps(48048, TCFPS2997DF, 48000);
	checkfps(48047, TCFPS2997DF, 48000);
	/* test converter */
	printf("test convert\n");
	checkfps(magic, &tcfps23976, 48000);
	checkfps(magic, TCFPS24, 48000);
	checkfps(magic, TCFPS25, 48000);
	checkfps(magic, &tcfps2997ndf, 48000);
	checkfps(magic, TCFPS2997DF, 48000);
	checkfps(magic, TCFPS30, 48000);
	checkfps(magic, &tcfps30df, 48000);

	/* test parser */
	printf("test parser\n");
	TimecodeTime t;
	char tcs[64];
	timecode_parse_time(&t, TCFPS25, "1:::-1");
	timecode_time_to_string(tcs, &t); fprintf(stdout, "%s\n", tcs);

	timecode_parse_time(&tc.t, TCFPS25, ":::1.100");
	timecode_copy_rate(&tc, TCFPSMS);
	timecode_strftimecode(tcs, 64, "%Z", &tc); fprintf(stdout, "%s\n", tcs);

	/* test add/sub */
	printf("test addition/subtraction\n");
	checkadd(TCFPS2997DF, 48000);
	checksub(TCFPS2997DF, 48000);

	checkadd(TCFPS30, 48000);
	checksub(TCFPS30, 48000);

	/* test add/sub */
	printf("test compare\n");
	checkcmp();

	/* test inc/dec */
	printf("test inc/dec\n");
	tc.d.year     = 2008;
	tc.d.month    = 12;
	tc.d.day      = 31;
	tc.d.timezone = 0;
	tc.t.hour     = 23;
	tc.t.minute   = 59;
	tc.t.second   = 59;
	tc.t.frame    = 29;
	tc.t.subframe = 29;
	memcpy(&tc.r, TCFPS30, sizeof(TimecodeRate));

	timecode_datetime_increment(&tc);
	timecode_datetime_decrement(&tc);

	fprintf(stdout, "%02d/%02d/%02d  %02d:%02d:%02d%c%02d\n",
			tc.d.month,
			tc.d.day,
			tc.d.year,

			tc.t.hour,
			tc.t.minute,
			tc.t.second,
			(TCFPS30->drop) ? '.' : ':',
			tc.t.frame
			);

	tc.t.subframe = 0;

	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @30fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS24, &tc.t, TCFPS30);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @24fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS25, &tc.t, TCFPS24);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @25fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS30, &tc.t, TCFPS25);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @30fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS25, &tc.t, TCFPS30);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @25fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS24, &tc.t, TCFPS25);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @24fps\n", tcs);
	timecode_convert_rate(&tc.t, TCFPS30, &tc.t, TCFPS24);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s @30fps\n", tcs);
#if 1
	timecode_convert_rate(&tc.t, &tcfpsUS, &tc.t, TCFPS30);
	timecode_time_to_string(tcs, &tc.t); fprintf(stdout, "%s\n", tcs);
#endif

	printf(" to/from sec\n");
	double sec = timecode_to_sec(&tc.t, &tcfpsUS);
	printf("%f\n", sec);
	timecode_seconds_to_time(&tc.t, TCFPSMS, sec);
	memcpy(&tc.r, TCFPSMS, sizeof(TimecodeRate));
#if 0
	tc.t.frame = 5;
	tc.d.timezone = -90;
#endif
	timecode_strftimecode(tcs, 64,"%Z", &tc); fprintf(stdout, "%s\n", tcs);

	printf(" check \n");
	timecode_copy_rate(&tc, &tcfps2997df);
	timecode_parse_time(&tc.t, &tc.r, "05:35:03:15");
	printf("%lld  <> 964965602\n", timecode_to_sample(&tc.t, &tc.r, 48000));


	timecode_copy_rate(&tc, &tcfps2997ndf);
	timecode_parse_time(&tc.t, &tc.r, "05:34:43:11");
	printf("%lld  <> 964965602\n", timecode_to_sample(&tc.t, &tc.r, 48000));

	return 0;
}