static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ OSErr cres; long framesizemax; UInt8 similarity=0; long compressedsize; OSType in_format=kYUVSPixelFormat; int width = mpi->width; int height = mpi->height; int stride = width*2; if(!codec_initialized){ FrameRect.top=0; FrameRect.left=0; FrameRect.right=width; FrameRect.bottom=height; cres = QTNewGWorldFromPtr( &frame_GWorld_in, in_format, &FrameRect, 0, 0, 0, mpi->planes[0], stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF); //dunno what todo about this frame_prev = malloc(stride * height); cres = QTNewGWorldFromPtr( &frame_GWorld_prev, in_format, &FrameRect, 0, 0, 0, frame_prev, stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"height:%i width:%i stride:%i\n",height,width,stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF); cres= GetMaxCompressionSize ( GetGWorldPixMap(frame_GWorld_in), &FrameRect, 24, codecNormalQuality, bswap_32(format), compressor, &framesizemax ); mp_msg(MSGT_MENCODER,MSGL_DBG2,"GetMaxCompressionSize returned:%i : MaxSize:%li\n",cres&0xFFFF,framesizemax); frame_comp=malloc(framesizemax); desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored (*desc)->idSize=MAX_IDSIZE; cres= CompressSequenceBegin ( &seq, GetGWorldPixMap( frame_GWorld_in), GetGWorldPixMap( frame_GWorld_prev), &FrameRect, &FrameRect, 24, // color depth bswap_32(format), // fourcc compressor, // codec component codecNormalQuality, //codecNormalQuality, codecMaxQuality, //codecNormalQuality, 10*30, // keyframe rate 0, 0, desc); mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceBegin returned:%i\n",cres&0xFFFF); mp_msg(MSGT_MENCODER,MSGL_DBG2,"Sequence ID:%i\n",seq); if (mp_msg_test(MSGT_MENCODER, MSGL_DBG2)) dump_ImageDescription(*desc); codec_initialized++; } cres = CompressSequenceFrame ( seq, GetGWorldPixMap(frame_GWorld_in), &FrameRect, 0, (char*)mux_v->buffer, &compressedsize, &similarity, 0); if(cres&0xFFFF)mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceFrame returned:%i\n",cres&0xFFFF); #if 0 printf("Size %i->%i \n",stride*height,compressedsize); printf("Ratio: %i:1\n",(stride*height)/compressedsize); #endif muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE); if(((*desc)->idSize)>MAX_IDSIZE){ mp_msg(MSGT_MENCODER,MSGL_ERR,"FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize)); } else { // according to QT docs, imagedescription may be changed while encoding // a frame (even its size may (and does!) change!) memcpy(mux_v->bih+1,*desc,(*desc)->idSize); } return 1; }
void MolDisplayWin::WriteQTMovie(wxString & filepath) { //Create a QuickTime movie using the standard animation codecs with normal quality, and //temporal compression. The final file is flattened for cross platform compatability QTExport * QTOptions = new QTExport(this); //setup controls for the current data if (MainData->GetNumFrames() > 1) { //default to frame animation QTOptions->SetMovieChoice(0); } else { QTOptions->EnableFrameMovie(false); } if (MainData->cFrame->GetNumberNormalModes() <= 0) { QTOptions->EnableModeMovie(false); } if (QTOptions->ShowModal() != wxID_OK) { //user cancelled the operation QTOptions->Destroy(); return; } //retrieve the value of each option int MovieType = QTOptions->GetMovieChoice(); bool IncludeEPlot = QTOptions->AddEnergyPlot(); int compressorChoice = QTOptions->GetCompressorChoice(); int keyFrameRate = QTOptions->GetKeyFrameRate(); if (keyFrameRate < 0) keyFrameRate = 0; QTOptions->Destroy(); CodecType mCodec; switch (compressorChoice) { case 0: mCodec = kCinepakCodecType; break; case 1: mCodec = kGraphicsCodecType; break; case 2: mCodec = kAnimationCodecType; break; case 3: default: mCodec = kMPEG4VisualCodecType; } OSStatus s; OSErr myErr = myErr; FSSpec targetSpec; //ugh I need to get an FSSpec to hand to quicktime, but these calls only seem to work if //the file already exists... const char * t = filepath.mb_str(wxConvUTF8); FILE * temp = fopen(t, "wb"); fclose(temp); #ifdef __WXOSX_COCOA__ //This function is not found in the wxCocoa implementation, it is probably possible to work around it //Otherwise the code appears to link and run currently. However, it is probably better to redue the //code to use the Cocoa qtKit framework rather than the old Carbon QT library. //This path is not tested as the current Cocoa code does not properly support the extended save dialog. // void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( filepath , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &targetSpec, NULL); verify_noerr( err ); } #else wxMacFilename2FSSpec(filepath, &targetSpec); #endif Movie theMovie = NULL; FSSpec tempSpec = targetSpec; strcpy((char *) &(tempSpec.name[1]), "MacMolPlt8933tempMovie"); tempSpec.name[0] = 22; BeginOperation(); ProgressInd->ChangeText("Creating movie..."); myErr = EnterMovies(); //initialize the quicktime manager if (myErr != noErr) { FinishOperation(); MessageAlert("Error initializing QuickTime!"); return; } //Create the movie file and initialize file data //Use Quicktime creator code 'TVOD' instead of simpletext 'ttxt' short resRefNum = 0; short resId = 0; myErr = CreateMovieFile(&tempSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resRefNum, &theMovie); if (myErr != noErr) { MessageAlert("Error creating movie file!"); } else { bool KillEPlot = false; int width, height, savedEPlotWidth, savedEPlotHeight; glCanvas->GetClientSize(&width, &height); Rect lDisplayRect={0,0,0,0}; lDisplayRect.right = width; lDisplayRect.bottom = height; Rect gRect = lDisplayRect; Rect EPlotRect = lDisplayRect; //If we are including an energy plot add space for it here if (IncludeEPlot && (MovieType == 0)) { EPlotRect.left = EPlotRect.right; EPlotRect.right = EPlotRect.left + height; if (!energyPlotWindow) { energyPlotWindow = new EnergyPlotDialog(this); KillEPlot = true; } else { energyPlotWindow->GetSize(&savedEPlotWidth, &savedEPlotHeight); } gRect.right += height; width += height; energyPlotWindow->Show(false); energyPlotWindow->SetSize(height, height); energyPlotWindow->Update(); //This is needed to initialise the window if we just created it } LocalToGlobal ((Point *) &(gRect.top)); LocalToGlobal ((Point *) &(gRect.bottom)); WindowRef TempWindow; s = CreateNewWindow(kDocumentWindowClass, kWindowNoAttributes, &gRect, &TempWindow); if (s == noErr) { //Create the video track Track theTrack = NewMovieTrack (theMovie, FixRatio(width,1), FixRatio(height,1), kNoVolume); if ((noErr == GetMoviesError())&&theTrack) { Media theMedia = NewTrackMedia (theTrack, VideoMediaType, 60, // Video Time Scale NULL, 0); if ((noErr == GetMoviesError())&&theMedia) { myErr = BeginMediaEdits (theMedia); if (myErr == noErr) { //create the actual movie frames GWorldPtr lgWorld=NULL; if (! NewGWorld (&lgWorld, 0, &gRect, (CTabHandle) NULL, (GDHandle) NULL, (GWorldFlags) (pixPurge + useTempMem))) { long MaxCompressedSize; ImageSequence seqID; ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(4); PixMapHandle myPixMap = GetPortPixMap(lgWorld); LockPixels (myPixMap); myErr = CompressSequenceBegin(&seqID, myPixMap, NULL, &gRect, &gRect, 0, mCodec, bestCompressionCodec, codecNormalQuality, codecNormalQuality, keyFrameRate, NULL, codecFlagUpdatePreviousComp, imageDesc); GetMaxCompressionSize (myPixMap, &gRect, 0, codecNormalQuality, mCodec, (CompressorComponent) anyCodec, &MaxCompressedSize); Handle Buffer = TempNewHandle(MaxCompressedSize, &myErr); if (!Buffer) Buffer = NewHandle(MaxCompressedSize); if (Buffer) { qtData myqtData = {theMedia, imageDesc, seqID, lDisplayRect, gRect}; if (MovieType == 0) { CreateFrameMovie(lgWorld, Buffer, myqtData, IncludeEPlot); } else { CreateModeMovie(lgWorld, Buffer, myqtData); } DisposeHandle(Buffer); } myErr = CDSequenceEnd(seqID); if (lgWorld != NULL) DisposeGWorld (lgWorld); if (imageDesc) DisposeHandle((Handle) imageDesc); } myErr = EndMediaEdits (theMedia); } myErr = InsertMediaIntoTrack (theTrack, 0,/* track start time */ 0, /* media start time */ GetMediaDuration (theMedia), FixRatio(1,1)); } myErr = AddMovieResource (theMovie, resRefNum, &resId, NULL); } if (resRefNum) { //Create the actual file as a flat data fork so it can be placed on the www ProgressInd->ChangeText("Flattening movieĆ"); FlattenMovie(theMovie, flattenAddMovieToDataFork, &targetSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resId, NULL); CloseMovieFile (resRefNum); } DisposeWindow(TempWindow); } DisposeMovie (theMovie); DeleteMovieFile (&tempSpec); //delete the temp file after disposing of the movie if (energyPlotWindow) { if (KillEPlot) { delete energyPlotWindow; energyPlotWindow = NULL; } else { energyPlotWindow->SetSize(savedEPlotWidth, savedEPlotHeight); energyPlotWindow->FrameChanged(); energyPlotWindow->Show(true); } } } ExitMovies(); //Close out quicktime as we are done with it for now FinishOperation(); }