/* datecode.c SEKINE Kohei (eggman@ptie.org) show timecode in dv stream version 0.1 2001.8.7 */ #include "stdafx.h" #include #include #include static unsigned char VAUXstart[] ={ 0x5f, 0x27, 0x02 } ; static char *youbi[] = { "Sun", "Mon", "Thr", "Wed", "Thr", "Fri", "Sat" }; int show_timecode(FILE *fp); void print_timecode(unsigned char *pstr); int decode_bcd(unsigned char s); int show_timecode(FILE *fp) { unsigned char *pbuff, *pw, *pend; size_t size; if(pbuff = (unsigned char *)malloc( (sizeof(char)*1024*1024) + 2 ) ){ while(size = fread(pbuff, sizeof(char), (1024*1024), fp)){ pw = pbuff; pend = pbuff + size; while(pw < pend){ if(!memcmp(pw++, VAUXstart, sizeof(VAUXstart) )){ pw += 2; //header is 5bytes print_timecode(pw); pw += 120000; //daitai konokurai aiteru } } } free(pbuff); }else{ puts("can't malloc"); } return 0; } void print_timecode(unsigned char *pstr) { unsigned char *pw , *pend; pw = pstr; pend = pstr + (80 - 3 - 2); /* printf("print\n"); for(i = 0; i < 75; i++) printf("%02x", pstr[i]); printf("\n"); */ while(pw < pend) { if(*pw == 0x62){ printf(" %02d/%02d/%02d (%s) ", decode_bcd(pw[4] & 0x3f), decode_bcd(pw[3] & 0x1f), decode_bcd(pw[2] & 0x3f), youbi[decode_bcd(pw[3] >> 5 )]); } else if(*pw == 0x63){ printf("%02d:%02d:%02d:%02d\n", decode_bcd(pw[4] & 0x3f), decode_bcd(pw[3] & 0x7f), decode_bcd(pw[2] & 0x7f), 0 ); //decode_bcd(pw[1] & 0x3f)); } pw += 5; } return ; } int decode_bcd(unsigned char s) { return 10 * (s >> 4 ) + (0x0f & s ); } int main(int argc, char **argv) { FILE *fp; if(fp = fopen(argv[1], "rb")){ show_timecode(fp); fclose(fp); }else{ puts("can't open file"); puts("usage datacode inputfile"); } return 0; }