Hi All,
Please see code at end of this message. I am trying to create a
movie frame by frame. I basically get called with a PNG image file
in memory, I have to render the image and write it to the movie
file as one frame.
I use the following 3 functions (listed below):
LTWQTUtilsCreateMovie
LTWQTUtilsAddFrameToMovie
LTWQTUtilsCloseMovie
When it's finished there is a 5.3 MB imovie file created, I can
open in QuickTime Movie Player but it says the movie has a
duration of 0 and doesn't play anything. When the movie opens, the
area for the frame is not displayed, only the lower controls part
of the window is displayed (like if you just play an audio file).
I'm not sure if I should be using the GWorld functions anymore and
not sure if this is why it's not working. Is there a better way of
doing this?
Any advice and help greatly appreciated.
All the Best
Dave
/
*********************************************************************
*************************
//**
//** LTWQTUtilsCreateMovie
//**
//
*********************************************************************
*************************
OSStatus LTWQTUtilsCreateMovie( char* theFilePathStringPtr,
LTWQTParameterInfoPtr theParameterInfoPtr)
{
OSStatus myOSStatus;
CFStringRef myFilePathStringCFString;
Handle myFileDataRef;
OSType myDataRefType;
//**
//** Initialize Storage
//**
//**
//** Convert the File Path to a CFString
//**
myFilePathStringCFString = CFStringCreateWithCString
(kCFAllocatorDefault,theFilePathStringPtr,kCFStringEncodingMacRoman);
if (myFilePathStringCFString == NULL)
return(kRunRevBadFileNameString);
//**
//** Make a Data Reference from a POSIX File Path String
//**
myOSStatus = QTNewDataReferenceFromFullPathCFString
(myFilePathStringCFString,kQTPOSIXPathStyle,
0,&myFileDataRef,&myDataRefType);
if (myOSStatus != noErr)
goto LTWQTUtilsCreateMovie_999;
//**
//** Create the Movie Storage
//**
myOSStatus = CreateMovieStorage
(myFileDataRef,myDataRefType,'TVOD',smCurrentScript,createMovieFileDe
leteCurFile,&theParameterInfoPtr-
>QTDataHandler,&theParameterInfoPtr->QTMovieRef);
if (myOSStatus != noErr)
goto LTWQTUtilsCreateMovie_999;
//**
//** Add the Movie to the Storage
//**
myOSStatus = AddMovieToStorage(theParameterInfoPtr-
>QTMovieRef,theParameterInfoPtr->QTDataHandler);
if (myOSStatus != noErr)
goto LTWQTUtilsCreateMovie_999;
//**
//** Create a New Movie Track
//**
theParameterInfoPtr->QTTrackRef = NewMovieTrack
(theParameterInfoPtr->QTMovieRef,
FixRatio(theParameterInfoPtr->QTFrameWidth,1),
FixRatio(theParameterInfoPtr->QTFrameHeight,1),
kNoVolume);
myOSStatus = GetMoviesError();
if (myOSStatus != noErr)
return(myOSStatus);
//**
//** Create Media for Track
//**
theParameterInfoPtr->QTMediaRef = NewTrackMedia
(theParameterInfoPtr->QTTrackRef,VideoMediaType,600,NULL,0);
myOSStatus = GetMoviesError();
if (myOSStatus != noErr)
return(myOSStatus);
//**
//** Begin Media Edits
//**
myOSStatus = BeginMediaEdits(theParameterInfoPtr->QTMediaRef);
if (myOSStatus != noErr)
return(myOSStatus);
//**
//** Clean up and Return
//**
LTWQTUtilsCreateMovie_999:
if (myFilePathStringCFString != NULL)
CFRelease(myFilePathStringCFString);
if (myOSStatus != noErr)
{
if (theParameterInfoPtr->QTMovieRef != NULL)
{
DisposeMovie(theParameterInfoPtr->QTMovieRef);
theParameterInfoPtr->QTMovieRef = NULL;
}
}
return(myOSStatus);
}
//
*********************************************************************
*************************
//**
//** LTWQTUtilsCloseMovie
//**
//
*********************************************************************
*************************
OSStatus LTWQTUtilsCloseMovie(LTWQTParameterInfoPtr
theParameterInfoPtr)
{
OSStatus myOSStatus;
TimeValue myMovieDuration;
//**
//** Initialize Storage
//**
//**
//** End Media Edits
//**
myOSStatus = EndMediaEdits(theParameterInfoPtr->QTMediaRef);
if (myOSStatus != noErr)
goto LTWQTUtilsCloseMovie_999;
//**
//** Insert the Media into the Movie Track
//**
myMovieDuration = GetMediaDuration(theParameterInfoPtr->QTMediaRef);
myOSStatus = InsertMediaIntoTrack(theParameterInfoPtr->QTTrackRef,
0,0,myMovieDuration,fixed1);
if (myOSStatus != noErr)
goto LTWQTUtilsCloseMovie_999;
//**
//** Close the Movie Storage
//**
myOSStatus = CloseMovieStorage(theParameterInfoPtr->QTDataHandler);
if (myOSStatus != noErr)
goto LTWQTUtilsCloseMovie_999;
//**
//** Clean up and Return
//**
LTWQTUtilsCloseMovie_999:
if (theParameterInfoPtr->QTMovieRef != NULL)
{
DisposeMovie(theParameterInfoPtr->QTMovieRef);
theParameterInfoPtr->QTMovieRef = NULL;
}
return(myOSStatus);
}
//
*********************************************************************
*************************
//**
//** LTWQTUtilsRenderFrame
//**
//
*********************************************************************
*************************
static OSStatus LTWQTUtilsRenderFrame( UInt32 theTrackWidth,
UInt32 theTrackHeight,
GWorldPtr theGWorld,
const char* theImageDataPtr,
UInt32 theImageDataSize)
{
ComponentResult myErr;
Rect myRect;
PointerDataRefRecord myPointerDataRefRecord;
Handle myDataRefHandle;
GraphicsImportComponent myImporter;
//**
//** Initialize
//**
myDataRefHandle = NULL;
myImporter = NULL;
myPointerDataRefRecord.data = theImageDataPtr;
myPointerDataRefRecord.dataLength = theImageDataSize;
myErr = PtrToHand(&myPointerDataRefRecord,&myDataRefHandle,sizeof
(myPointerDataRefRecord));
MacSetRect(&myRect,0,0,theTrackWidth,theTrackHeight);
myErr = OpenADefaultComponent
(GraphicsImporterComponentType,kQTFileTypePNG,&myImporter);
if (myErr != noErr)
goto LTWQTUtilsRenderFrame_999;
//**
//** Configure the Graphics Importer
//**
myErr = GraphicsImportSetGWorld(myImporter,theGWorld,NULL);
if (myErr != noErr)
goto LTWQTUtilsRenderFrame_999;
myErr = GraphicsImportSetDataReference
(myImporter,myDataRefHandle,PointerDataHandlerSubType);
if (myErr != noErr)
goto LTWQTUtilsRenderFrame_999;
myErr = GraphicsImportSetBoundsRect(myImporter,&myRect);
if (myErr != noErr)
goto LTWQTUtilsRenderFrame_999;
//**
//** Draw the Image into the GWorld
//**
myErr = GraphicsImportDraw(myImporter);
if (myErr != noErr)
goto LTWQTUtilsRenderFrame_999;
//**
//** Clean Up and Return
//**
LTWQTUtilsRenderFrame_999:
if (myImporter != NULL)
CloseComponent(myImporter);
return(myErr);
}
//
*********************************************************************
*************************
//**
//** LTWQTUtilsAddFrameToMovie
//**
//
*********************************************************************
*************************
OSStatus LTWQTUtilsAddFrameToMovie( LTWQTParameterInfoPtr
theParameterInfoPtr,
const char* theImageBufferPtr,
UInt32 theImageBufferSize)
{
OSStatus myOSStatus;
GWorldPtr myGWorld = NULL;
PixMapHandle myPixMap = NULL;
CodecType myCodecType = kJPEGCodecType;
long myMaxComprSize = 0L;
Handle myComprDataHdl = NULL;
Ptr myComprDataPtr = NULL;
ImageDescriptionHandle myImageDesc = NULL;
CGrafPtr mySavedPort = NULL;
GDHandle mySavedDevice = NULL;
Rect myRect;
CodecQ myCodecQuality;
myCodecType = kJPEGCodecType;
myCodecQuality = codecNormalQuality;
myCodecType = kVideoCodecType;
myCodecQuality = codecLosslessQuality;
MacSetRect(&myRect,0,0,theParameterInfoPtr-
>QTFrameWidth,theParameterInfoPtr->QTFrameHeight);
myOSStatus = NewGWorld(&myGWorld,32,&myRect,NULL,NULL,
(GWorldFlags) 0);
if (myOSStatus != noErr)
goto LTWQTUtilsAddFrameToMovie_999;
myPixMap = GetGWorldPixMap(myGWorld);
if (myPixMap == NULL)
goto LTWQTUtilsAddFrameToMovie_999;
LockPixels(myPixMap);
myOSStatus = GetMaxCompressionSize( myPixMap,
&myRect,
0, // let ICM choose depth
codecNormalQuality,
myCodecType,
(CompressorComponent) anyCodec,
&myMaxComprSize);
if (myOSStatus != noErr)
goto LTWQTUtilsAddFrameToMovie_999;
myComprDataHdl = NewHandle(myMaxComprSize);
if (myComprDataHdl == NULL)
goto LTWQTUtilsAddFrameToMovie_999;
HLockHi(myComprDataHdl);
myComprDataPtr = *myComprDataHdl;
myImageDesc = (ImageDescriptionHandle) NewHandle(4);
if (myImageDesc == NULL)
goto LTWQTUtilsAddFrameToMovie_999;
GetGWorld(&mySavedPort,&mySavedDevice);
SetGWorld(myGWorld,NULL);
EraseRect(&myRect);
//**
//** Render the Image
//**
myOSStatus = LTWQTUtilsRenderFrame(theParameterInfoPtr-
>QTFrameWidth,theParameterInfoPtr-
>QTFrameHeight,myGWorld,theImageBufferPtr,theImageBufferSize);
if (myOSStatus != noErr)
goto LTWQTUtilsAddFrameToMovie_999;
//**
//** Compress the Image
//**
myOSStatus = CompressImage( myPixMap,
&myRect,
myCodecQuality,
myCodecType,
myImageDesc,
myComprDataPtr);
if (myOSStatus != noErr)
goto LTWQTUtilsAddFrameToMovie_999;
//**
//** Add the Image to the Movie
//**
myOSStatus = AddMediaSample(theParameterInfoPtr->QTMediaRef,
myComprDataHdl,
0, // no offset in data
(**myImageDesc).dataSize,
kVideoFrameDuration, // frame duration
(SampleDescriptionHandle) myImageDesc,
1, // one sample
0, // self-contained samples
NULL);
if (myOSStatus != noErr)
goto LTWQTUtilsAddFrameToMovie_999;
//**
//** Clean up and Return
//**
LTWQTUtilsAddFrameToMovie_999:
SetGWorld(mySavedPort,mySavedDevice);
if (myImageDesc != NULL)
DisposeHandle((Handle)myImageDesc);
if (myComprDataHdl != NULL)
DisposeHandle(myComprDataHdl);
if (myGWorld != NULL)
DisposeGWorld(myGWorld);
return(myOSStatus);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/mark.munte%
40pobox.com
This email sent to email@hidden