HI All,
I am attempting to write out an image as a movie well, it will be an array of 
images but to start with I can't even get one in there.  Any help diagnosing my 
problem would be greatly appreciated.

Here is what I am doing:


//here is the image
NSString *path = [NSString 
stringWithFormat:@"%@/images/0.png",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
 NSUserDomainMask, YES) lastObject]];

NSData *imageData = [[[NSData alloc] initWithContentsOfFile:path] autorelease];
UIImage *uiimage = [UIImage imageWithData:imageData];

//configure the path for the output video
NSString *videoPath = [NSString 
stringWithFormat:@"%@/videos/currentVideo.mov",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
 NSUserDomainMask, YES) lastObject]];
    
NSError *error = nil;

//create the writer
AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL 
fileURLWithPath:videoPath] fileType:AVFileTypeQuickTimeMovie error:&error];
NSParameterAssert(videoWriter);
    
//setup the properties for the input
NSDictionary *videoSettings = [NSDictionary 
dictionaryWithObjectsAndKeys:AVVideoCodecH264, AVVideoCodecKey,[NSNumber 
numberWithInt:640], AVVideoWidthKey,[NSNumber numberWithInt:960], 
AVVideoHeightKey,nil];

//create the input    
AVAssetWriterInput* writerInput = [[AVAssetWriterInput 
assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] 
retain];
    
    NSParameterAssert(writerInput);
    NSParameterAssert([videoWriter canAddInput:writerInput]);
    [videoWriter addInput:writerInput];

//configure the properties for the buffer and create the bufferAdaptor
NSDictionary *bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
[NSNumber numberWithInt:kCVPixelFormatType_32BGRA], 
kCVPixelBufferPixelFormatTypeKey, nil];
    
AVAssetWriterInputPixelBufferAdaptor *adaptor = 
[AVAssetWriterInputPixelBufferAdaptor
                                                     
assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
                                                     
sourcePixelBufferAttributes:bufferAttributes]; 
//create the pixel buffer
    
CVPixelBufferRef pixelBuffer = NULL;
    
    CGImageRef cgImage = CGImageCreateCopy([uiimage CGImage]);
    CFDataRef image = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
    int status = CVPixelBufferCreateWithBytes(NULL,
                                              960,
                                              640,
                                              kCVPixelFormatType_32BGRA, 
                                              (void*)CFDataGetBytePtr(image), 
                                              CGImageGetBytesPerRow(cgImage), 
                                              NULL, 
                                              0, 
                                              NULL, 
                                              &pixelBuffer);

//write it out
[adaptor appendPixelBuffer:pixelBuffer withPresentationTime:CMTimeMake(2, 60)];



It crashes here reporting

*** Terminating app due to uncaught exception 
'NSInternalInconsistencyException', reason: '*** 
-[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] 
Cannot call method when status is 0'






_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to