Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. - (BOOL) setupRecorder {
  2. NSError *error = nil;
  3. if([[NSFileManager defaultManager] fileExistsAtPath:[[self tempFileURL] path]])
  4. [[NSFileManager defaultManager] removeItemAtURL:[self tempFileURL] error:&error];
  5.  
  6.  
  7. assetWriter = [[AVAssetWriter alloc] initWithURL: [self tempFileURL]
  8. fileType:AVFileTypeQuickTimeMovie
  9. error:&error];
  10. if (error) {
  11. NSLog(@"Error creating asset writer: %@", error);
  12. [assetWriter release];
  13. return NO;
  14. }
  15. // writer
  16.  
  17. NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
  18. AVVideoCodecH264, AVVideoCodecKey,
  19. [NSNumber numberWithInt:videoWidth], AVVideoWidthKey,
  20. [NSNumber numberWithInt:videoHeight], AVVideoHeightKey,
  21. nil];
  22.  
  23. assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
  24. outputSettings:videoSettings];
  25.  
  26. NSDictionary *bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
  27. [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,
  28. nil];
  29.  
  30. adaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:assetWriterInput sourcePixelBufferAttributes:bufferAttributes];
  31. [adaptor retain];
  32. assetWriterInput.expectsMediaDataInRealTime = YES;
  33. [assetWriter addInput:assetWriterInput];
  34.  
  35. return YES;
  36. }
  37.  
  38. - (CVPixelBufferRef) createPixelBufferRef {
  39. CVPixelBufferPoolRef pixelBufferPool = adaptor.pixelBufferPool;
  40. CVPixelBufferRef pixelBuffer = NULL;
  41. CVReturn cvReturn = CVPixelBufferPoolCreatePixelBuffer(NULL, pixelBufferPool, &pixelBuffer);
  42. if(cvReturn != kCVReturnSuccess)
  43. NSLog(@"CVPixelBuffePoolCreatePixelBuffer: %d", cvReturn);
  44. bufferCreatedCount++;
  45. return pixelBuffer;
  46. }
Add Comment
Please, Sign In to add comment