--- Begin Message ---
- Subject: Re: Movie creation problem
- From: Roozbeh Zabihollahi <email@hidden>
- Date: Sat, 31 Mar 2007 03:32:57 -0700 (PDT)
Dear Jan,
Thank you very much. I checked your notes. Unfortanely
making strings Pascal Strings and changing
InsertMediaIntoTrack paramters did not fix the
problem. I did not know anything about Pascal strings
and QT usage. So, I attached my file to this mail.
Could you please take a look at the attched file and
let me know your opinion?
Additionally, making your changes did not change the
program bihaviour and unfortunately it still returns
-2050 Error.
Your help would be very much appreciated.
Regards,
* Roozbeh
--- "Jan E. Schotsman" <email@hidden> wrote:
>
> If NewTrackMedia fails the rest cannot possibly
> work.
>
> I can see the follow ing errors in the code:
>
> 1. I am not sure if .test.mov is a good file name.
> On MAcOS files whose
> name starts with a dot are invisible. Also you need
> a Pascal string
> (which starts with a length byte) not a C string.
>
> 2.
>
> err = InsertMediaIntoTrack (theTrack, 0, /* track
> start time */
>
> GetMediaDuration (theMedia),
> /* media start time */
>
> GetMediaDuration (theMedia),
> kFix1);
>
> should be
>
> err = InsertMediaIntoTrack (theTrack, 0, /* track
> start time */
> 0, /*
> media start time */
>
> GetMediaDuration (theMedia),
> kFix1);
>
>
> Jan E.>
_______________________________________________
> 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/email@hidden
>
> This email sent to email@hidden
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
#if !defined(_MSC_VER) && _WIN32
#include <Win32Headers.mch>
#define TARGET_OS_WIN32 1
#else
#include <ConditionalMacros.h>
#endif
#if TARGET_OS_WIN32
#include <QTML.h>
#define STRICT
#include <windows.h>
#endif
#include "MacTypes.h"
#include "MacMemory.h"
#include "MacErrors.h"
#include "Fonts.h"
#include "QuickDraw.h"
#include "Resources.h"
#include "Gestalt.h"
#include "FixMath.h"
#include "Sound.h"
#include "string.h"
#include "Movies.h"
#include "ImageCompression.h"
#include "Script.h"
#include "TextUtils.h"
#include "Processes.h"
#include <stdio.h>
////#include <Types.h>
//#include <Traps.h>
//#include <Menus.h>
//#include <Memory.h>
////#include <Errors.h>
//#include <Fonts.h>
//#include <QuickDraw.h>
//#include <Resources.h>
////#include <GestaltEqu.h>
//#include <FixMath.h>
//#include <Sound.h>
//#include <string.h>
#include "Movies.h"
#include "ImageCompression.h"
void CheckError(OSErr error, Str255 displayString)
{
if (error == noErr) return;
if (displayString[0] > 0) {
printf("%s Error: %d\n", displayString, error);
}
exit(0);
}
void InitMovieToolbox (void)
{
OSErr err;
err = InitializeQTML(0L);
CheckError (err, "InitializeQTML error" );
err = EnterMovies ();
CheckError (err, "EnterMovies" );
}
#define kMyCreatorType 'TVOD' /* Sample Player's creator type, the
movie player of choice. You can
also use your own creator type. */
#define kPrompt "Enter movie file name"
#define kVideoTimeScale 600
#define kTrackStart 0
#define kMediaStart 0
#define kFix1 0x00010000
#define kSampleDuration 240
/* video frames last 240 * 1/600th of a second */
#define kNumVideoFrames 29
#define kNoOffset 0
#define kMgrChoose 0
#define kSyncSample 0
#define kAddOneVideoSample 1
#define kPixelDepth 16
#define SAMPLE_FILE_NAME "test.mov"
void DrawFrame (const Rect *trackFrame, long curSample)
{
Str255 numStr;
ForeColor( redColor );
PaintRect( trackFrame );
ForeColor( blueColor );
NumToString (curSample, numStr);
MoveTo ( trackFrame->right / 2, trackFrame->bottom / 2);
TextSize ( trackFrame->bottom / 3);
DrawString (numStr);
}
void AddVideoSamplesToMedia (Media theMedia,
const Rect *trackFrame)
{
long maxCompressedSize;
GWorldPtr theGWorld = nil;
long curSample;
Handle compressedData = nil;
Ptr compressedDataPtr;
ImageDescriptionHandle imageDesc = nil;
CGrafPtr oldPort;
GDHandle oldGDeviceH;
OSErr err = noErr;
err = NewGWorld (&theGWorld,
16, /* pixel depth */
trackFrame,
nil,
nil,
(GWorldFlags) 0 );
CheckError (err, "NewGWorld");
LockPixels (theGWorld->portPixMap);
err = GetMaxCompressionSize (theGWorld->portPixMap,
trackFrame,
0, /* let ICM choose depth */
codecNormalQuality,
kJPEG2000CodecType,
(CompressorComponent) anyCodec,
&maxCompressedSize);
CheckError (err, "GetMaxCompressionSize" );
compressedData = NewHandle(maxCompressedSize);
CheckError( MemError(), "NewHandle" );
MoveHHi( compressedData );
HLock( compressedData );
compressedDataPtr = StripAddress( *compressedData );
imageDesc = (ImageDescriptionHandle)NewHandle(4);
CheckError( MemError(), "NewHandle" );
GetGWorld (&oldPort, &oldGDeviceH);
SetGWorld (theGWorld, nil);
for (curSample = 1; curSample < 30; curSample++)
{
EraseRect (trackFrame);
DrawFrame(trackFrame, curSample);
err = CompressImage (theGWorld->portPixMap,
trackFrame,
codecNormalQuality,
kJPEG2000CodecType,
imageDesc,
compressedDataPtr );
CheckError( err, "CompressImage" );
err = AddMediaSample(theMedia,
compressedData,
0, /* no offset in data */
(**imageDesc).dataSize,
60, /* frame duration = 1/10 sec */
(SampleDescriptionHandle)imageDesc,
1, /* one sample */
0, /* self-contained samples */
nil);
CheckError( err, "AddMediaSample" );
}
SetGWorld (oldPort, oldGDeviceH);
if (imageDesc) DisposeHandle ((Handle)imageDesc);
if (compressedData) DisposeHandle (compressedData);
if (theGWorld) DisposeGWorld (theGWorld);
}
void CreateMyVideoTrack (Movie theMovie)
{
Track theTrack;
Media theMedia;
OSErr err = noErr;
Rect trackFrame = {0,0,100,320};
theTrack = NewMovieTrack (theMovie,
FixRatio(trackFrame.right,1),
FixRatio(trackFrame.bottom,1),
kNoVolume);
CheckError( GetMoviesError(), "NewMovieTrack" );
theMedia = NewTrackMedia (theTrack, VideoMediaType,
600, // Video Time Scale
nil, nil);
CheckError( GetMoviesError(), "NewTrackMedia" );
err = BeginMediaEdits (theMedia);
CheckError( err, "BeginMediaEdits" );
AddVideoSamplesToMedia (theMedia, &trackFrame);
err = EndMediaEdits (theMedia);
CheckError( err, "EndMediaEdits" );
err = InsertMediaIntoTrack (theTrack, 0, /* track start time */
0, /* media start time */
GetMediaDuration (theMedia),
kFix1);
CheckError( err, "InsertMediaIntoTrack" );
}
void CreateMyCoolMovie (void)
{
Point where = {100,100};
Movie theMovie = nil;
FSSpec mySpec;
short resRefNum = 0;
short resId = 0;
OSErr err = noErr;
char filename[256];
sprintf(filename, "%c%s", strlen(SAMPLE_FILE_NAME), SAMPLE_FILE_NAME);
mySpec.vRefNum = 0;
mySpec.parID = 0;
strcpy(mySpec.name, filename); /* a Str63 on MacOS*/
err = CreateMovieFile (&mySpec,
FOUR_CHAR_CODE('TVOD'),
smCurrentScript,
createMovieFileDeleteCurFile,
&resRefNum,
&theMovie );
CheckError(err, "CreateMovieFile");
CreateMyVideoTrack (theMovie);
err = AddMovieResource (theMovie, resRefNum, &resId,
filename);
CheckError(err, "AddMovieResource");
if (resRefNum) CloseMovieFile (resRefNum);
DisposeMovie (theMovie);
}
int main(int agrv, char **argc)
{
printf("Initalizing Toolbox . . .\n");
InitMovieToolbox ();
printf("Creating movie . . .\n");
CreateMyCoolMovie ();
printf("Finished!\n");
return 0;
}
--- End Message ---