• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem saving movie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem saving movie


  • Subject: Problem saving movie
  • From: David Faden <email@hidden>
  • Date: Mon, 29 Mar 2004 01:55:08 -0600

Hi,

I'm having a dickens of a time tracking down a bug in some code that saves a QuickTime movie. My QuickTime code is based off the bMoviePalette example. (I have basically just lifted the MyMovie class out of bMoviePalette.) The code used to write the movie comes from <http://cocoa.mamasam.com/COCOADEV/2001/06/2/5601.php>. (I also had this problem with the movie writing code provided in bMoviePalette.)

In my code, a movie is generated in a separate thread (using an instance of the MyMovie class for the QuickTime stuff). Everything seems to go fine until the code gets to writing the movie. Then, around 50% of the time, the -writeToFile:atomically: method returns NO and indeed the file isn't written. (Otherwise, the movie seems to be written properly.)

So far, I haven't had much luck debugging the code. When the writes fail, breakpoints set within the movie writing code are not noticed by the debugger nor do NSLogs within the writing code produce any visible output. This suggests the code isn't being called at all. Yet, I get no signals when the writing code fails. And, when it fails, its return value (NO) is apparently correctly returned by the writeToFile:atomically: method.

(Ah. Holy moly. It just occurred to me that if my MyMovie object were nil, I'd probably see the behavior I'm seeing. If you believe this is the case, do you have any suggestions on why I might be getting nil from [MyMovie emptyMovie] and how I can fix this?)

The code for the full application is at <http://www.public.iastate.edu/~dfaden/fractalanimator/ FractalAnimator_2004_03_29_146.zip>. I've pasted what I think are the relevant sections of code below (comments stripped). I'd greatly appreciate any ideas on what might be causing my code's intermittent writing problems and on how to fix this. (I'd also appreciate comments on my coding style.)

Please CC any replies to me directly as well as to the list.

Thanks much.

David
AIM: pitulx

---

From MovieGenerator.m:

//The following is called with
//[NSThread detachNewThreadSelector:@selector(generateMovie:) toTarget:self withObject:nil];

- (void)generateMovie:(id)argument
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSBitmapImageRep* bitmap =
[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: NULL
pixelsWide: dimensions.width
pixelsHigh: dimensions.height
bitsPerSample: 8
samplesPerPixel: 3 //RGB
hasAlpha: NO
isPlanar: NO
colorSpaceName: NSDeviceRGBColorSpace
bytesPerRow: 0
bitsPerPixel: 0];
unsigned char* imageData = [bitmap bitmapData];
MyMovie* movie = [MyMovie emptyMovie];
int i;

NSLog(@"filename == %@", filename);

for (i = 0; i < numberOfFrames && DFKeepGoing == userRequest; i++) {
generateMandelbrotSet(imageData, center, pixelWidth, dimensions, numberOfIterations);
[movie appendImageOrBitmap:bitmap sourceDurationTime:1];

[progressIndicator incrementBy:1];
[frameCompletedField setStringValue:
[NSString stringWithFormat:@"Completed frame %d out of %d", (i + 1), numberOfFrames]];
center.x += realDelta;
center.y += imaginaryDelta;
pixelWidth += pixelWidthDelta;
}
if (DFKeepGoing == userRequest || DFCancelButSave == userRequest) {
BOOL saved = NO;
int i;
for (i = 0; i < 5 && !saved; i++) {
saved = [movie writeToFile:filename atomically:YES];
if (!saved) {
NSLog(@"Problem writing %@", filename);
}
}
}
[bitmap release];
[self performSelectorOnMainThread:@selector(close) withObject:nil waitUntilDone:NO];
}

From MyMovie.m:

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)value
{
return WriteMovieToPath([self QTMovie], path);
}

BOOL WriteMovieToPath(Movie movie, NSString* pathname)
{
FSSpec fileSpec;
FSRef ref;
NSString* directory = [pathname stringByDeletingLastPathComponent];
NSString* filename = [pathname lastPathComponent];
UniChar characters[255];
short resId;

OSStatus status = FSPathMakeRef([directory fileSystemRepresentation], &ref, NULL);

NSLog(@"WriteMovieToPath: pathname == %@", pathname);

if (status != noErr) {
NSLog(@"FSPathMakeRef failed with %d", status);
return NO;
}
[filename getCharacters:characters];
status = FSCreateFileUnicode(&ref, [filename length], characters, kFSCatInfoNone, NULL, NULL, &fileSpec);
if (status != noErr) {
NSLog(@"FSCreateFileUnicode failed with %d", status);
return NO;
}
FlattenMovie(movie,
flattenAddMovieToDataFork|flattenForceMovieResourceBeforeMovieData,
&fileSpec,'TVOD',
smSystemScript,
createMovieFileDeleteCurFile|createMovieFileDontCreateResFile,
&resId,
nil);

CloseMovieFile(resId);
return YES;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Problem saving movie
      • From: David Faden <email@hidden>
  • Prev by Date: Re: SIGIO and AppKit main loop
  • Next by Date: Re: Setting a NSScrollView's Scroll Amount
  • Previous by thread: Re: Using IP or hostname for NSConnections rootProxyForConnectionWithRegisteredName:host:
  • Next by thread: Re: Problem saving movie
  • Index(es):
    • Date
    • Thread