/* dvavi2raw.c SEKINE Kohei (eggman@ptie.org) DV AVI File -> raw format file version 0.1 2001.8.12 */ #include "StdAfx.h" #include #include #include static unsigned char subchunkv_start[] = { '0', '0', 'd', 'b' }; static unsigned char subchunkv1_start[] = { '0', '0', 'd', 'c' }; void avi2raw(FILE *fpi, FILE *fpo); void avi2raw(FILE *fpi, FILE *fpo) { unsigned char *pbuff, *pw, *pend; size_t size, subchunk_size; if(pbuff = (unsigned char *)malloc( (sizeof(char)*2048*1024) + 2 ) ){ while(size = fread(pbuff, sizeof(char), (2048*1024), fpi)){ pw = pbuff; pend = pbuff + size; while(pw < pend){ if(!memcmp(pw, subchunkv_start, sizeof(subchunkv_start) )){ /* サブチャンクのヘッダーを検索 */ pw += 4; subchunk_size = *(size_t *)pw; /* サブチャンクのサイズを取得 */ pw += sizeof(size_t); //printf("subchunk size : %d ", subchunk_size); if(pend - pw + 10> subchunk_size){ /*バッファの残り容量が足りているか */ if(subchunk_size > 100){ /* AVIファイルの最後についてるインデックス部分は出力しない*/ fwrite(pw, sizeof(char), subchunk_size , fpo); } pw += subchunk_size; }else{ fseek(fpi, (long)-(pend - pw + 10) ,SEEK_CUR); /* バッファの容量が足りなかったらファイルを読みなおす. ださいなぁ*/ pend = 0; /* whileループを抜ける*/ } }else{ pw++; } } } free(pbuff); }else{ puts("can't malloc"); } } int main(int argc ,char *argv[]) { FILE *fpi, *fpo; if( (fpi = fopen(argv[1], "rb")) && (fpo = fopen(argv[2], "wb"))){ avi2raw(fpi, fpo); fclose(fpi); fclose(fpo); }else{ puts("can't open file"); puts("usage: dvavi2raw inputfile outputfile"); } return 0; }