Quicktime-cocoa : fix file busy issue when rendering a second time with quicktime...
[blender.git] / source / blender / quicktime / apple / qtkit_export.m
index c5e878c6ebc2180a9049d12f7ac750346b99a68a..460b35a05924fe95d2a656a6b5cc751c6e845267 100644 (file)
@@ -1,5 +1,5 @@
 /**
 /**
- * $Id: qtkit_export.m 24424 2009-11-09 17:06:48Z damien78 $
+ * $Id$
  *
  * qtkit_export.m
  *
  *
  * qtkit_export.m
  *
@@ -32,6 +32,9 @@
 #ifdef WITH_QUICKTIME
 #if defined(_WIN32) || defined(__APPLE__)
 
 #ifdef WITH_QUICKTIME
 #if defined(_WIN32) || defined(__APPLE__)
 
+#include <stdio.h>
+#include <string.h>
+
 #include "DNA_scene_types.h"
 
 #include "BKE_global.h"
 #include "DNA_scene_types.h"
 
 #include "BKE_global.h"
 #ifndef __AIFF__
 #define __AIFF__
 #endif
 #ifndef __AIFF__
 #define __AIFF__
 #endif
+#import <Cocoa/Cocoa.h>
+#import <QTKit/QTKit.h>
 #endif /* __APPLE__ */
 
 #endif /* __APPLE__ */
 
-#define        kMyCreatorType  FOUR_CHAR_CODE('TVOD')
-#define        kTrackStart             0
-#define        kMediaStart             0
-
-//static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, int recty);
-static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int recty);
-static void QT_EndAddVideoSamplesToMedia (void);
-static void QT_CreateMyVideoTrack (int rectx, int recty);
-static void QT_EndCreateMyVideoTrack (void);
-static void check_renderbutton_framerate(struct RenderData *rd);
-
 typedef struct QuicktimeExport {
 typedef struct QuicktimeExport {
+       QTMovie *movie;
+       
+       NSString *filename;
 
 
-       /*FSSpec                theSpec;
-       short           resRefNum;
-       Str255          qtfilename;
-
-       Media           theMedia;
-       Movie           theMovie;
-       Track           theTrack;
-
-       GWorldPtr                       theGWorld;
-       PixMapHandle            thePixMap;
-       ImageDescription        **anImageDescription;*/
-
-       ImBuf           *ibuf;  //imagedata for Quicktime's Gworld
-       ImBuf           *ibuf2; //copy of renderdata, to be Y-flipped
-
+       QTTime frameDuration;
+       NSDictionary *frameAttributes;
 } QuicktimeExport;
 
 } QuicktimeExport;
 
-typedef struct QuicktimeComponentData {
-
-       /*ComponentInstance     theComponent;
-       SCTemporalSettings  gTemporalSettings;
-       SCSpatialSettings   gSpatialSettings;
-       SCDataRateSettings  aDataRateSetting;
-       TimeValue                       duration;
-       long                            kVideoTimeScale;*/
-
-} QuicktimeComponentData;
-
 static struct QuicktimeExport *qtexport;
 static struct QuicktimeExport *qtexport;
-static struct QuicktimeComponentData *qtdata;
-
-static int     sframe;
-
-#if 0
-
-static OSErr QT_SaveCodecSettingsToScene(RenderData *rd)
-{      
-       QTAtomContainer         myContainer = NULL;
-       ComponentResult         myErr = noErr;
-       Ptr                                     myPtr;
-       long                            mySize = 0;
-
-       CodecInfo                       ci;
-       char str[255];
-
-       QuicktimeCodecData *qcd = rd->qtcodecdata;
-
-       // check if current scene already has qtcodec settings, and clear them
-       if (qcd) {
-               free_qtcodecdata(qcd);
-       } else {
-               qcd = rd->qtcodecdata = MEM_callocN(sizeof(QuicktimeCodecData), "QuicktimeCodecData");
-       }
-
-       // obtain all current codec settings
-       SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
-       SCSetInfo(qtdata->theComponent, scSpatialSettingsType,  &qtdata->gSpatialSettings);
-       SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting);
-
-       // retreive codecdata from quicktime in a atomcontainer
-       myErr = SCGetSettingsAsAtomContainer(qtdata->theComponent,  &myContainer);
-       if (myErr != noErr) {
-               printf("Quicktime: SCGetSettingsAsAtomContainer failed\n"); 
-               goto bail;
-       }
-
-       // get the size of the atomcontainer
-       mySize = GetHandleSize((Handle)myContainer);
-
-       // lock and convert the atomcontainer to a *valid* pointer
-       QTLockContainer(myContainer);
-       myPtr = *(Handle)myContainer;
-
-       // copy the Quicktime data into the blender qtcodecdata struct
-       if (myPtr) {
-               qcd->cdParms = MEM_mallocN(mySize, "qt.cdParms");
-               memcpy(qcd->cdParms, myPtr, mySize);
-               qcd->cdSize = mySize;
-
-               GetCodecInfo (&ci, qtdata->gSpatialSettings.codecType, 0);
-               CopyPascalStringToC(ci.typeName, str);
-               sprintf(qcd->qtcodecname, "Codec: %s", str);
-       } else {
-               printf("Quicktime: QT_SaveCodecSettingsToScene failed\n"); 
-       }
-
-       QTUnlockContainer(myContainer);
-
-bail:
-       if (myContainer != NULL)
-               QTDisposeAtomContainer(myContainer);
-               
-       return((OSErr)myErr);
-}
 
 
 
 
-static OSErr QT_GetCodecSettingsFromScene(RenderData *rd)
-{      
-       Handle                          myHandle = NULL;
-       ComponentResult         myErr = noErr;
-//     CodecInfo ci;
-//     char str[255];
-
-       QuicktimeCodecData *qcd = rd->qtcodecdata;
-
-       // if there is codecdata in the blendfile, convert it to a Quicktime handle 
-       if (qcd) {
-               myHandle = NewHandle(qcd->cdSize);
-               PtrToHand( qcd->cdParms, &myHandle, qcd->cdSize);
-       }
-               
-       // restore codecsettings to the quicktime component
-       if(qcd->cdParms && qcd->cdSize) {
-               myErr = SCSetSettingsFromAtomContainer((GraphicsExportComponent)qtdata->theComponent, (QTAtomContainer)myHandle);
-               if (myErr != noErr) {
-                       printf("Quicktime: SCSetSettingsFromAtomContainer failed\n"); 
-                       goto bail;
-               }
-
-               // update runtime codecsettings for use with the codec dialog
-               SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting);
-               SCGetInfo(qtdata->theComponent, scSpatialSettingsType,  &qtdata->gSpatialSettings);
-               SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
-
-//             GetCodecInfo (&ci, qtdata->gSpatialSettings.codecType, 0);
-//             CopyPascalStringToC(ci.typeName, str);
-//             printf("restored Codec: %s\n", str);
-       } else {
-               printf("Quicktime: QT_GetCodecSettingsFromScene failed\n"); 
-       }
-bail:
-       if (myHandle != NULL)
-               DisposeHandle(myHandle);
-               
-       return((OSErr)myErr);
-}
-
-
-static OSErr QT_AddUserDataTextToMovie (Movie theMovie, char *theText, OSType theType)
-{
-       UserData                                        myUserData = NULL;
-       Handle                                          myHandle = NULL;
-       long                                            myLength = strlen(theText);
-       OSErr                                           myErr = noErr;
-
-       // get the movie's user data list
-       myUserData = GetMovieUserData(theMovie);
-       if (myUserData == NULL)
-               return(paramErr);
-       
-       // copy the specified text into a new handle
-       myHandle = NewHandleClear(myLength);
-       if (myHandle == NULL)
-               return(MemError());
-
-       BlockMoveData(theText, *myHandle, myLength);
-
-       // add the data to the movie's user data
-       myErr = AddUserDataText(myUserData, myHandle, theType, 1, (short)GetScriptManagerVariable(smRegionCode));
-
-       // clean up
-       DisposeHandle(myHandle);
-       return(myErr);
-}
-
-
-static void QT_CreateMyVideoTrack(int rectx, int recty)
-{
-       OSErr err = noErr;
-       Rect trackFrame;
-//     MatrixRecord myMatrix;
-
-       trackFrame.top = 0;
-       trackFrame.left = 0;
-       trackFrame.bottom = recty;
-       trackFrame.right = rectx;
-       
-       qtexport->theTrack = NewMovieTrack (qtexport->theMovie, 
-                                                       FixRatio(trackFrame.right,1),
-                                                       FixRatio(trackFrame.bottom,1), 
-                                                       0);
-       CheckError( GetMoviesError(), "NewMovieTrack error" );
-
-//     SetIdentityMatrix(&myMatrix);
-//     ScaleMatrix(&myMatrix, fixed1, Long2Fix(-1), 0, 0);
-//     TranslateMatrix(&myMatrix, 0, Long2Fix(trackFrame.bottom));
-//     SetMovieMatrix(qtexport->theMovie, &myMatrix);
-
-       qtexport->theMedia = NewTrackMedia (qtexport->theTrack,
-                                                       VideoMediaType,
-                                                       qtdata->kVideoTimeScale,
-                                                       nil,
-                                                       0);
-       CheckError( GetMoviesError(), "NewTrackMedia error" );
-
-       err = BeginMediaEdits (qtexport->theMedia);
-       CheckError( err, "BeginMediaEdits error" );
-
-       QT_StartAddVideoSamplesToMedia (&trackFrame, rectx, recty);
-} 
-
-
-static void QT_EndCreateMyVideoTrack(void)
-{
-       OSErr err = noErr;
-
-       QT_EndAddVideoSamplesToMedia ();
-
-       err = EndMediaEdits (qtexport->theMedia);
-       CheckError( err, "EndMediaEdits error" );
-
-       err = InsertMediaIntoTrack (qtexport->theTrack,
-                                                               kTrackStart,/* track start time */
-                                                               kMediaStart,/* media start time */
-                                                               GetMediaDuration (qtexport->theMedia),
-                                                               fixed1);
-       CheckError( err, "InsertMediaIntoTrack error" );
-} 
-
-
-static void QT_StartAddVideoSamplesToMedia (const Rect *trackFrame, int rectx, int recty)
-{
-       SCTemporalSettings gTemporalSettings;
-       OSErr err = noErr;
-
-       qtexport->ibuf = IMB_allocImBuf (rectx, recty, 32, IB_rect, 0);
-       qtexport->ibuf2 = IMB_allocImBuf (rectx, recty, 32, IB_rect, 0);
-
-       err = NewGWorldFromPtr( &qtexport->theGWorld,
-                                                       k32ARGBPixelFormat,
-                                                       trackFrame,
-                                                       NULL, NULL, 0,
-                                                       (Ptr)qtexport->ibuf->rect,
-                                                       rectx * 4 );
-       CheckError (err, "NewGWorldFromPtr error");
-
-       qtexport->thePixMap = GetGWorldPixMap(qtexport->theGWorld);
-       LockPixels(qtexport->thePixMap);
-
-       SCDefaultPixMapSettings (qtdata->theComponent, qtexport->thePixMap, true);
-
-       // workaround for crash with H.264, which requires an upgrade to
-       // the new callback based api for proper encoding, but that's not
-       // really compatible with rendering out frames sequentially
-       gTemporalSettings = qtdata->gTemporalSettings;
-       if(qtdata->gSpatialSettings.codecType == kH264CodecType) {
-               if(gTemporalSettings.temporalQuality != codecMinQuality) {
-                       fprintf(stderr, "Only minimum quality compression supported for QuickTime H.264.\n");
-                       gTemporalSettings.temporalQuality = codecMinQuality;
-               }
-       }
-
-       SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &gTemporalSettings);
-       SCSetInfo(qtdata->theComponent, scSpatialSettingsType,  &qtdata->gSpatialSettings);
-       SCSetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting);
-
-       err = SCCompressSequenceBegin(qtdata->theComponent, qtexport->thePixMap, NULL, &qtexport->anImageDescription); 
-       CheckError (err, "SCCompressSequenceBegin error" );
-}
-
-
-static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int recty)
-{
-       OSErr   err = noErr;
-       Rect    imageRect;
-
-       int             index;
-       int             boxsize;
-       unsigned char *from, *to;
-
-       short   syncFlag;
-       long    dataSize;
-       Handle  compressedData;
-       Ptr             myPtr;
-
-
-       //copy and flip renderdata
-       memcpy(qtexport->ibuf2->rect, pixels, 4*rectx*recty);
-       IMB_flipy(qtexport->ibuf2);
-
-       //get pointers to parse bitmapdata
-       myPtr = GetPixBaseAddr(qtexport->thePixMap);
-       imageRect = (**qtexport->thePixMap).bounds;
-
-       from = (unsigned char *) qtexport->ibuf2->rect;
-       to = (unsigned char *) myPtr;
-
-       //parse RGBA bitmap into Quicktime's ARGB GWorld
-       boxsize = rectx * recty;
-       for( index = 0; index < boxsize; index++) {
-               to[0] = from[3];
-               to[1] = from[0];
-               to[2] = from[1];
-               to[3] = from[2];
-               to +=4, from += 4;
-       }
-
-       err = SCCompressSequenceFrame(qtdata->theComponent,
-               qtexport->thePixMap,
-               &imageRect,
-               &compressedData,
-               &dataSize,
-               &syncFlag);
-       CheckError(err, "SCCompressSequenceFrame error");
-
-       err = AddMediaSample(qtexport->theMedia,
-               compressedData,
-               0,
-               dataSize,
-               qtdata->duration,
-               (SampleDescriptionHandle)qtexport->anImageDescription,
-               1,
-               syncFlag,
-               NULL);
-       CheckError(err, "AddMediaSample error");
-
-       printf ("added frame %3d (frame %3d in movie): ", frame, frame-sframe);
-}
-
-
-static void QT_EndAddVideoSamplesToMedia (void)
-{
-       SCCompressSequenceEnd(qtdata->theComponent);
-
-       UnlockPixels(qtexport->thePixMap);
-       if (qtexport->theGWorld)
-               DisposeGWorld (qtexport->theGWorld);
-
-       if (qtexport->ibuf)
-               IMB_freeImBuf(qtexport->ibuf);
-
-       if (qtexport->ibuf2)
-               IMB_freeImBuf(qtexport->ibuf2);
-} 
-#endif //0
-
 void makeqtstring (RenderData *rd, char *string) {
        char txt[64];
 
 void makeqtstring (RenderData *rd, char *string) {
        char txt[64];
 
-       if (string==0) return;
-
        strcpy(string, rd->pic);
        BLI_convertstringcode(string, G.sce);
 
        strcpy(string, rd->pic);
        BLI_convertstringcode(string, G.sce);
 
@@ -423,167 +89,127 @@ void makeqtstring (RenderData *rd, char *string) {
 }
 
 
 }
 
 
-void start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty) {
-#if 0
-       OSErr err = noErr;
-
+void start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty)
+{
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       NSError *error;
        char name[2048];
        char name[2048];
-       char theFullPath[255];
-
 
 
+       
        if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport");
 
        if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport");
 
-       if(qtdata) {
-               if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
-               free_qtcomponentdata();
-       }
-
-       qtdata = MEM_callocN(sizeof(QuicktimeComponentData), "QuicktimeCodecDataExt");
-
-       if(rd->qtcodecdata == NULL || rd->qtcodecdata->cdParms == NULL) {
-               get_qtcodec_settings(rd);
-       } else {
-               qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
-
-               QT_GetCodecSettingsFromScene(rd);
-               check_renderbutton_framerate(rd);
-       }
-       
        if (G.afbreek != 1) {
        if (G.afbreek != 1) {
-               sframe = (rd->sfra);
-
-               makeqtstring(rd, name);
-
-               sprintf(theFullPath, "%s", name);
-
-               /* hack: create an empty file to make FSPathMakeRef() happy */
-               myFile = open(theFullPath, O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRUSR|S_IWUSR);
-               if (myFile < 0) {
-                       printf("error while creating file!\n");
-                       /* do something? */
-               }
-               close(myFile);
-               err = FSPathMakeRef((const UInt8 *)theFullPath, &myRef, 0);
-               CheckError(err, "FsPathMakeRef error");
-               err = FSGetCatalogInfo(&myRef, kFSCatInfoNone, NULL, NULL, &qtexport->theSpec, NULL);
-               CheckError(err, "FsGetCatalogInfoRef error");
-
-               err = CreateMovieFile (&qtexport->theSpec, 
-                                                       kMyCreatorType,
-                                                       smCurrentScript, 
-                                                       createMovieFileDeleteCurFile | createMovieFileDontCreateResFile,
-                                                       &qtexport->resRefNum, 
-                                                       &qtexport->theMovie );
-               CheckError(err, "CreateMovieFile error");
-
-               if(err != noErr) {
+               /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */
+               if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) {
                        G.afbreek = 1;
                        G.afbreek = 1;
-// XXX                 error("Unable to create Quicktime movie: %s", name);
-               } else {
-                       printf("Created QuickTime movie: %s\n", name);
-
-                       QT_CreateMyVideoTrack(rectx, recty);
+                       fprintf(stderr, "\nUnable to create quicktime movie, need Quicktime rev 7.2.1 or later");
+               }
+               else {
+                       makeqtstring(rd, name);
+                       qtexport->filename = [NSString stringWithCString:name
+                                                                         encoding:[NSString defaultCStringEncoding]];
+                       qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error];
+                               
+                       if(qtexport->movie == nil) {
+                               G.afbreek = 1;
+                               NSLog(@"Unable to create quicktime movie : %@",[error localizedDescription]);
+                       } else {
+                               [qtexport->movie retain];
+                               [qtexport->filename retain];
+                               [qtexport->movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
+                               [qtexport->movie setAttribute:@"Made with Blender" forKey:QTMovieCopyrightAttribute];
+                               
+                               qtexport->frameDuration = QTMakeTime(rd->frs_sec_base*1000, rd->frs_sec*1000);
+                               
+                               /* specifying the codec attributes
+                               TODO: get these values from RenderData/scene*/
+                               qtexport->frameAttributes = [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg",
+                                                                                        QTAddImageCodecType,
+                                                                                        [NSNumber numberWithLong:codecHighQuality],
+                                                                                        QTAddImageCodecQuality,
+                                                                                        nil];
+                               [qtexport->frameAttributes retain];
+                       }
                }
        }
                }
        }
-#endif
+       
+       [pool drain];
 }
 
 
 }
 
 
-void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty) {
-       //QT_DoAddVideoSamplesToMedia(frame, pixels, rectx, recty);
+void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty)
+{
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       NSBitmapImageRep *blBitmapFormatImage;
+       NSImage *frameImage;
+       unsigned char *from_Ptr,*to_Ptr;
+       int y,from_i,to_i;
+       
+       
+       /* Create bitmap image rep in blender format (32bit RGBA) */
+       blBitmapFormatImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+                                                                                                                                 pixelsWide:rectx 
+                                                                                                                                 pixelsHigh:recty
+                                                                                                                          bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
+                                                                                                                         colorSpaceName:NSCalibratedRGBColorSpace 
+                                                                                                                               bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
+                                                                                                                                bytesPerRow:rectx*4
+                                                                                                                               bitsPerPixel:32];
+       if (!blBitmapFormatImage) {
+               [pool drain];
+               return;
+       }
+       
+       from_Ptr = (unsigned char*)pixels;
+       to_Ptr = (unsigned char*)[blBitmapFormatImage bitmapData];
+       for (y = 0; y < recty; y++) {
+               to_i = (recty-y-1)*rectx;
+               from_i = y*rectx;
+               memcpy(to_Ptr+4*to_i, from_Ptr+4*from_i, 4*rectx);
+       }
+       
+       frameImage = [[NSImage alloc] initWithSize:NSMakeSize(rectx, recty)];
+       [frameImage addRepresentation:blBitmapFormatImage];
+       
+       /* Add the image to the movie clip */
+       [qtexport->movie addImage:frameImage
+                                 forDuration:qtexport->frameDuration
+                          withAttributes:qtexport->frameAttributes];
+
+       [blBitmapFormatImage release];
+       [frameImage release];
+       [pool drain];   
 }
 
 
 }
 
 
-void end_qt(void) {
-/*     OSErr err = noErr;
-       short resId = movieInDataForkResID;
-
-       if(qtexport->theMovie) {
-               QT_EndCreateMyVideoTrack();
-
-               err = AddMovieResource (qtexport->theMovie, qtexport->resRefNum, &resId, qtexport->qtfilename);
-               CheckError(err, "AddMovieResource error");
-
-               err = QT_AddUserDataTextToMovie(qtexport->theMovie, "Made with Blender", kUserDataTextInformation);
-               CheckError(err, "AddUserDataTextToMovie error");
-
-               err = UpdateMovieResource(qtexport->theMovie, qtexport->resRefNum, resId, qtexport->qtfilename);
-               CheckError(err, "UpdateMovieResource error");
-
-               if(qtexport->resRefNum) CloseMovieFile(qtexport->resRefNum);
-
-               DisposeMovie(qtexport->theMovie);
-
-               printf("Finished QuickTime movie.\n");
-       }
+void end_qt(void)
+{
+       if (qtexport->movie) {
+               /* Flush update of the movie file */
+               [qtexport->movie updateMovieFile];
+               
+               [qtexport->movie invalidate];
+               
+               /* Clean up movie structure */
+               [qtexport->filename release];
+               [qtexport->frameAttributes release];
+               [qtexport->movie release];
+               }
 
        if(qtexport) {
                MEM_freeN(qtexport);
                qtexport = NULL;
 
        if(qtexport) {
                MEM_freeN(qtexport);
                qtexport = NULL;
-       }*/
+       }
 }
 
 
 void free_qtcomponentdata(void) {
 }
 
 
 void free_qtcomponentdata(void) {
-       /*if(qtdata) {
-               if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
-               MEM_freeN(qtdata);
-               qtdata = NULL;
-       }*/
-}
-
-
-static void check_renderbutton_framerate(RenderData *rd) 
-{
-       // to keep float framerates consistent between the codec dialog and frs/sec button.
-/*     OSErr   err;    
-
-       //err = SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
-       CheckError(err, "SCGetInfo fr error");
-
-       if( (rd->frs_sec == 24 || rd->frs_sec == 30 || rd->frs_sec == 60) &&
-               (qtdata->gTemporalSettings.frameRate == 1571553 ||
-                qtdata->gTemporalSettings.frameRate == 1964113 ||
-                qtdata->gTemporalSettings.frameRate == 3928227)) {;} 
-       else {
-               if (rd->frs_sec_base > 0)
-                       qtdata->gTemporalSettings.frameRate = 
-                       (rd->frs_sec << 16) / rd->frs_sec_base ;
-       }
-       
-       //err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
-       CheckError( err, "SCSetInfo error" );
-
-       if(qtdata->gTemporalSettings.frameRate == 1571553) {                    // 23.98 fps
-               qtdata->kVideoTimeScale = 24000;
-               qtdata->duration = 1001;
-       } else if (qtdata->gTemporalSettings.frameRate == 1964113) {    // 29.97 fps
-               qtdata->kVideoTimeScale = 30000;
-               qtdata->duration = 1001;
-       } else if (qtdata->gTemporalSettings.frameRate == 3928227) {    // 59.94 fps
-               qtdata->kVideoTimeScale = 60000;
-               qtdata->duration = 1001;
-       } else {
-               qtdata->kVideoTimeScale = (qtdata->gTemporalSettings.frameRate >> 16) * 100;
-               qtdata->duration = 100;
-       }*/
 }
 
 
 int get_qtcodec_settings(RenderData *rd) 
 {
 }
 
 
 int get_qtcodec_settings(RenderData *rd) 
 {
-/*     OSErr   err = noErr;
-
-       // erase any existing codecsetting
-       if(qtdata) {
-               if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
-               free_qtcomponentdata();
-       }
-
-       // allocate new
-       qtdata = MEM_callocN(sizeof(QuicktimeComponentData), "QuicktimeComponentData");
-       qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
-
+/*
        // get previous selected codecsetting, if any 
        if(rd->qtcodecdata && rd->qtcodecdata->cdParms) {
                QT_GetCodecSettingsFromScene(rd);
        // get previous selected codecsetting, if any 
        if(rd->qtcodecdata && rd->qtcodecdata->cdParms) {
                QT_GetCodecSettingsFromScene(rd);
@@ -623,41 +249,40 @@ int get_qtcodec_settings(RenderData *rd)
        QT_SaveCodecSettingsToScene(rd);
 
        // framerate jugglin'
        QT_SaveCodecSettingsToScene(rd);
 
        // framerate jugglin'
-       if(qtdata->gTemporalSettings.frameRate == 1571553) {                    // 23.98 fps
-               qtdata->kVideoTimeScale = 24000;
-               qtdata->duration = 1001;
-
-               rd->frs_sec = 24;
-               rd->frs_sec_base = 1.001;
-       } else if (qtdata->gTemporalSettings.frameRate == 1964113) {    // 29.97 fps
-               qtdata->kVideoTimeScale = 30000;
-               qtdata->duration = 1001;
-
-               rd->frs_sec = 30;
-               rd->frs_sec_base = 1.001;
-       } else if (qtdata->gTemporalSettings.frameRate == 3928227) {    // 59.94 fps
-               qtdata->kVideoTimeScale = 60000;
-               qtdata->duration = 1001;
-
-               rd->frs_sec = 60;
-               rd->frs_sec_base = 1.001;
-       } else {
-               double fps = qtdata->gTemporalSettings.frameRate;
-
-               qtdata->kVideoTimeScale = 60000;
-               qtdata->duration = qtdata->kVideoTimeScale / (qtdata->gTemporalSettings.frameRate / 65536);
-
-               if ((qtdata->gTemporalSettings.frameRate & 0xffff) == 0) {
-                       rd->frs_sec = fps / 65536;
-                       rd->frs_sec_base = 1;
-               } else {
-                       // we do our very best... 
-                       rd->frs_sec = (fps * 10000 / 65536);
-                       rd->frs_sec_base = 10000;
+       switch (qtexport->frameRate) {
+               case 1571553: // 23.98 fps
+                       qtexport->frameDuration = QTMakeTime(1001, 24000);
+                       rd->frs_sec = 24;
+                       rd->frs_sec_base = 1.001;
+                       break;
+               case 1964113: // 29.97 fps
+                       qtexport->frameDuration = QTMakeTime(1001, 30000);
+                       rd->frs_sec = 30;
+                       rd->frs_sec_base = 1.001;
+                       break;
+               case 3928227: // 59.94 fps
+                       qtexport->frameDuration = QTMakeTime(1001, 60000);
+                       rd->frs_sec = 60;
+                       rd->frs_sec_base = 1.001;
+                       break;
+               default:
+               {
+                       double fps = qtexport->frameRate;
+                       qtexport->frameDuration = QTMakeTime(60000/(qtexport->frameRate / 65536), 60000);
+                       
+                       if ((qtexport->frameRate & 0xffff) == 0) {
+                               rd->frs_sec = fps / 65536;
+                               rd->frs_sec_base = 1;
+                       } else {
+                               // we do our very best... 
+                               rd->frs_sec = (fps * 10000 / 65536);
+                               rd->frs_sec_base = 10000;
+                       }
                }
                }
+                       break;
        }
 */
        }
 */
-       return 0;
+       return 1;
 }
 
 #endif /* _WIN32 || __APPLE__ */
 }
 
 #endif /* _WIN32 || __APPLE__ */