- if(cache)
- delete cache;
- xblocksize = (width/3)&~7;
- yblocksize = (height/2)&~7;
- xblocks = width/xblocksize;
- yblocks = height/yblocksize;
- printf("%dx%d blocks of size %dx%d\n", xblocks,yblocks, xblocksize, yblocksize);
- printf("cutting lower %d lines, right %d columns\n",
- height-yblocks*yblocksize, width-xblocks*xblocksize);
- blocks = new GfxBlockEncoder[xblocks*yblocks];
- blockbuffer = new U8[xblocksize*yblocksize*4]; //should be 3
- cache = new GfxBlockCache(file);
- int t;
- for(t=0;t<xblocks*yblocks;t++) {
- blocks[t].init(t*64,
- (t%xblocks)*xblocksize,
- (t/xblocks)*yblocksize,
- xblocksize, yblocksize);
- }
-
- TAG*tag = swf_InsertTag(NULL, ST_JPEGTABLES);
- JPEGBITS * jpeg = swf_SetJPEGBitsStart(tag, xblocksize, yblocksize, jpeg_quality);
- swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
- free(jpeg);
-}
-
-void destroydisplay(int file)
-{
- delete cache;
- free(blocks);
- free(blockbuffer);
-}
-
-SWF swf;
-TAG*tag;
-
-int main (int argc,char ** argv)
-{
- int file;
- IAviReadFile* player;
- IAviReadStream* astream;
- IAviReadStream* vstream;
- MainAVIHeader head;
- SRECT r;
- double samplesperframe;
- int samplerate;
- int samplefix;
-
- processargs(argc, argv);
- lastframe += firstframe;
- if(!filename)
- exit(0);
-
- memset(idtab, 0, sizeof(idtab));
-
- player = CreateIAviReadFile(filename);
- player->GetFileHeader(&head);
- printf("fps: %d\n", 1000000/head.dwMicroSecPerFrame);
- printf("frames: %d\n", head.dwTotalFrames);
- printf("streams: %d\n", head.dwStreams);
- printf("streams: %d\n", player->StreamCount());
- printf("width: %d\n", head.dwWidth);
- printf("height: %d\n", head.dwHeight);
-
- astream = player->GetStream(0, AviStream::Audio);
- vstream = player->GetStream(0, AviStream::Video);
-
- vstream -> StartStreaming();
- astream -> StartStreaming();
-
- width = head.dwWidth;
- height = head.dwHeight;
-
- printf("sound: %u samples (%f seconds)\n", astream->GetEndPos(),
- astream->GetEndTime());
- samplesperframe = astream->GetEndPos()/astream->GetEndTime()*head.dwMicroSecPerFrame/1000000;
- printf("%f samples/frame\n", samplesperframe);
- samplerate = (int)(astream->GetEndPos()/astream->GetEndTime());
- printf("%d samplerate\n", samplerate);
- samplefix = 44100/samplerate;
-
- if(!samplefix) {
- printf("samplerate too high!\n");
- return 0;
- }
- printf("%d mp3 samples per movie sample\n", samplefix);
-
- file = open(outputfilename,O_WRONLY|O_CREAT|O_TRUNC, 0644);
-
- memset(&swf, 0, sizeof(swf));
- swf.frameRate = (int)(1000000.0/head.dwMicroSecPerFrame*256);
- swf.fileVersion = 4;
- swf.fileSize = 476549;//0x0fffffff;
- swf.frameCount = lastframe - firstframe;
- r.xmin = 0;
- r.ymin = 0;
- r.xmax = width*20;
- r.ymax = height*20;
- swf.movieSize = r;
-
- swf_WriteHeader(file, &swf);
-
- tag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
- swf_SetU8(tag,0); //black
- swf_SetU8(tag,0);
- swf_SetU8(tag,0);
- swf_WriteTag(file, tag);
- swf_DeleteTag(tag);