Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

max2u

macrumors newbie
Original poster
Dec 1, 2008
2
0
i want to create a movie file from images using the QuickTime SDK that works on both mac and windows, after some investigation i came up with this code but i dont know what the hell is wrong with it.

the problem seems to be in filling the grapics worlld with the image but i can't fix it, if any one can help me(please hurry, i need it as soon as possible)

thanks alot.

*i wrote this code on windows and havent tested it yet on mac.



#include <qtml.h>
#include <movies.h>
#include <ImageCompression.h>
#include <QuickTimeComponents.h>
#include <stdio.h>


void main()
{
if(InitializeQTML(0)!=noErr)
{
TerminateQTML();
return;
}

EnterMovies();

GWorldPtr theWorld=NULL;
FSSpec fileSpec;
OSErr anErr = noErr;
short myRefNum = -1;
Movie myDstMovie =NULL;
Track pTrack=NULL;
Media pMedia=NULL;
long maxCompressedSize;
Handle m_compressedData;
Ptr m_compressedDataPtr;
ImageDescriptionHandle m_imageDesc;

Rect bounds;
bounds.left=0;
bounds.top=0;
bounds.right=320;
bounds.top=240;

for (int i=0 ;i<10;i++)
{
FSSpec imgFileSpec;
ComponentInstance gi;
char* fn=new char[256];
sprintf(fn,"%03d.bmp",i);
NativePathNameToFSSpec(fn, &imgFileSpec, 0L);
if (GetGraphicsImporterForFile(&imgFileSpec,&gi)!=noErr)
continue;

if (i==0)
{
NativePathNameToFSSpec("output.mov", &fileSpec, 0L);

NewGWorld(&theWorld,32,&bounds,NULL,NULL,0);

CreateMovieFile(&fileSpec, FOUR_CHAR_CODE('TVOD'), smCurrentScript,
createMovieFileDeleteCurFile | createMovieFileDontCreateResFile,
&myRefNum, &myDstMovie);

GraphicsImportGetNaturalBounds(gi,&bounds);


pTrack = NewMovieTrack (myDstMovie,
FixRatio(((bounds.right>bounds.left)? (bounds.right-bounds.left) :(bounds.left-bounds.right)) ,1),//Do not cast to (short) - Overflow occurs
FixRatio(((bounds.bottom >bounds.top)? (bounds.bottom-bounds.top) :(bounds.top-bounds.bottom)),1),
0);
pMedia = NewTrackMedia (pTrack, VideoMediaType,
600,
nil, 0);
}

PixMapHandle h=GetGWorldPixMap(theWorld);
LockPixels(h);
GraphicsImportSetGWorld(gi, theWorld , NULL);
GraphicsImportSetBoundsRect(gi, &bounds);
GraphicsImportDraw(gi);


if (i==0)
{
if ( GetMaxCompressionSize(h,
&bounds,
0,
codecNormalQuality,
kJPEGCodecType ,
(CompressorComponent) anyCodec,
&maxCompressedSize)!= noErr)
break;
m_compressedData = NewHandle(maxCompressedSize);
MoveHHi( m_compressedData );
HLock( m_compressedData );
m_compressedDataPtr = StripAddress( *m_compressedData );

m_imageDesc = (ImageDescriptionHandle)NewHandle(4);
BeginMediaEdits (pMedia);

}

CompressImage (h,&bounds, codecNormalQuality,kJPEGCodecType,m_imageDesc, m_compressedDataPtr );

AddMediaSample(pMedia,
m_compressedData,
0,
(**m_imageDesc).dataSize,
60,
(SampleDescriptionHandle)m_imageDesc,
1,
0,
nil);


}
anErr = GetMoviesError();

ExitMovies();
TerminateQTML();

}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.