/* timecode.c show timecode in dv stream Author SEKINE Kohei (eggman@ptie.org) Date 0.1 2001.8.7 */ #include "stdafx.h" #include #include #include static unsigned char AAUXstart[] ={ 0x3f, 0x07, 0x00 } ; int show_timecode(FILE *fp); int decode_timecode(unsigned char *pstr); int decode_bcd(unsigned char s); int show_timecode(FILE *fp) { unsigned char *pbuff, *pw, *pend; unsigned long i,j; size_t size; j=0; i=0; if(pbuff = (unsigned char *)malloc( (sizeof(char)*1024*1024) ) ){ while(size = fread(pbuff, sizeof(char), (1024*1024), fp) ){ pw = pbuff; pend = pbuff + size; while(pw < pend){ i++; if(!memcmp(pw++, AAUXstart, sizeof(AAUXstart) )){ /* printf("find\n"); for(i = 0; i < 77; i++){ printf("%02X ",*pw++); } printf("\n"); */ pw += 5; i += 5; decode_timecode(pw); //printf(" iti %ld sabun %ld\n", i, i-j); //j = i; pw += 120000; } } } free(pbuff); }else{ puts("can't malloc"); } return 0; } int decode_timecode(unsigned char *pstr) { if(*pstr == 0x13){ return printf("%02d:%02d:%02d:%02d\n", decode_bcd(pstr[4] & 0x3f), decode_bcd(pstr[3] & 0x7f), decode_bcd(pstr[2] & 0x7f), decode_bcd(pstr[1] & 0x3f )); }else{ return 0; } } int decode_bcd(unsigned char s) { return 10 * (s >> 4 ) + (s & 0x0f ); } int main(int argc, char **argv) { FILE *fp; if(fp = fopen(argv[1], "rb")){ show_timecode(fp); fclose(fp); }else{ printf("can't open file %s\n", argv[1]); puts("usage timecode inputfile"); } return 0; }