Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (BOOL) setupRecorder {
- NSError *error = nil;
- if([[NSFileManager defaultManager] fileExistsAtPath:[[self tempFileURL] path]])
- [[NSFileManager defaultManager] removeItemAtURL:[self tempFileURL] error:&error];
- assetWriter = [[AVAssetWriter alloc] initWithURL: [self tempFileURL]
- fileType:AVFileTypeQuickTimeMovie
- error:&error];
- if (error) {
- NSLog(@"Error creating asset writer: %@", error);
- [assetWriter release];
- return NO;
- }
- // writer
- NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
- AVVideoCodecH264, AVVideoCodecKey,
- [NSNumber numberWithInt:videoWidth], AVVideoWidthKey,
- [NSNumber numberWithInt:videoHeight], AVVideoHeightKey,
- nil];
- assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
- outputSettings:videoSettings];
- NSDictionary *bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,
- nil];
- adaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:assetWriterInput sourcePixelBufferAttributes:bufferAttributes];
- [adaptor retain];
- assetWriterInput.expectsMediaDataInRealTime = YES;
- [assetWriter addInput:assetWriterInput];
- return YES;
- }
- - (CVPixelBufferRef) createPixelBufferRef {
- CVPixelBufferPoolRef pixelBufferPool = adaptor.pixelBufferPool;
- CVPixelBufferRef pixelBuffer = NULL;
- CVReturn cvReturn = CVPixelBufferPoolCreatePixelBuffer(NULL, pixelBufferPool, &pixelBuffer);
- if(cvReturn != kCVReturnSuccess)
- NSLog(@"CVPixelBuffePoolCreatePixelBuffer: %d", cvReturn);
- bufferCreatedCount++;
- return pixelBuffer;
- }
Add Comment
Please, Sign In to add comment