- player = CreateIAviReadFile(filename);
- astream = player->GetStream(0, AviStream::Audio);
- vstream = player->GetStream(0, AviStream::Video);
- if(!vstream)
- do_video = 0;
- if(!astream)
- do_audio = 0;
-#ifndef VERSION6
- MainAVIHeader head;
- int dwMicroSecPerFrame = 0;
- player->GetFileHeader(&head);
- printf("fps: %d\n", 1000000/head.dwMicroSecPerFrame);
- printf("frames: %d\n", head.dwTotalFrames);
- printf("streams: %d\n", head.dwStreams);
- printf("width: %d\n", head.dwWidth);
- printf("height: %d\n", head.dwHeight);
- printf("sound: %u samples (%f seconds)\n", astream->GetEndPos(),
- astream->GetEndTime());
- oldwidth = head.dwWidth;
- oldheight = head.dwHeight;
- dwMicroSecPerFrame = head.dwMicroSecPerFrame;
- samplesperframe = astream->GetEndPos()/astream->GetEndTime()*head.dwMicroSecPerFrame/1000000;
- samplerate = (int)(astream->GetEndPos()/astream->GetEndTime());
- fps = 1000000.0/dwMicroSecPerFrame;
-#else
- StreamInfo*audioinfo;
- StreamInfo*videoinfo;
- if(do_video)
- {
- videoinfo = vstream->GetStreamInfo();
- oldwidth = videoinfo->GetVideoWidth();
- oldheight = videoinfo->GetVideoHeight();
- fps = (double)(videoinfo->GetFps());
- delete(videoinfo);
- }
- if(do_audio)
- {
- audioinfo = astream->GetStreamInfo();
- samplerate = audioinfo->GetAudioSamplesPerSec();
- samplesperframe = audioinfo->GetAudioSamplesPerSec()/videoinfo->GetFps();
- delete(audioinfo);
- }
-#endif
- width = (int)(oldwidth*scale);
- height = (int)(oldheight*scale);
- reziscale = 1/scale;
-
- vstream -> StartStreaming();
- if(do_audio)
- {
- astream -> StartStreaming();
- printf("%f framerate\n", fps);
- printf("%f samples/frame\n", samplesperframe);
- printf("%d samplerate\n", samplerate);
- }
-
- if(zlib)
- file = open("__tmp__.swf", O_WRONLY|O_CREAT|O_TRUNC, 0644);
- else
- file = open(outputfilename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
-
- memset(&swf, 0, sizeof(swf));
- swf.frameRate = (int)(fps*256);
- swf.fileVersion = 4;
- swf.fileSize = 0x0fffffff;
- swf.frameCount = lastframe - firstframe;
- r.xmin = 0;
- r.ymin = 0;
- r.xmax = width*20;
- r.ymax = height*20;
- swf.movieSize = r;
-
- filesize += swf_WriteHeader(file, &swf);
-
- tag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
- swf_SetU8(tag,0); //black
- swf_SetU8(tag,0);
- swf_SetU8(tag,0);
- filesize += swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
-
- tag = swf_InsertTag(NULL, ST_SOUNDSTREAMHEAD2);
- swf_SetSoundStreamHead(tag, (int)samplesperframe/4);
- filesize += swf_WriteTag(file, tag);
- swf_DeleteTag(tag);
-
- int frame = 0;
- initdisplay(file);
-
- double movie_sound_pos = 0;
- int mp3_sound_pos = 0;
-
- if(do_audio)
- {
- WAVEFORMATEX wave;
- astream->GetAudioFormatInfo(&wave,0);
-
- printf("nChannels:%d\n", wave.nChannels);
- printf("nSamplesPerSec:%d\n", wave.nSamplesPerSec);
- printf("nAvgBytesPerSec:%d\n", wave.nAvgBytesPerSec);
- printf("nBlockAlign:%d\n", wave.nBlockAlign);
- printf("wBitsPerSample:%d\n", wave.wBitsPerSample);
- printf("cbSize:%d\n", wave.cbSize);
- }
-
- SoundReader* sound = new SoundReader(astream);
-
- while(1) {
- if(vstream->ReadFrame()<0) {
- printf("\n");
- break;
- }
-
- if(frame < firstframe)
- {
- movie_sound_pos += samplesperframe;
- if(do_audio)
- while(mp3_sound_pos<movie_sound_pos) {
- short int* samples = sound->readFrame();
- mp3_sound_pos += mp3_block_size;