Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hold multiple Frames in Memory before sending them to AVAssetWriter
- - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection
- {
- //...
- CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
- uint8 *baseAddress = (uint8*)CVPixelBufferGetBaseAddress(imageBuffer);
- NSData *rawFrame = [[NSData alloc] initWithBytes:(void*)baseAddress length:(height * bytesPerRow)];
- [m_frameDataArray addObject:rawFrame];
- [rawFrame release];
- //...
- }
- -(void)writeFramesToFile
- {
- //...
- NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithInt:640], AVVideoWidthKey,
- [NSNumber numberWithInt:480], AVVideoHeightKey,
- AVVideoCodecH264, AVVideoCodecKey,
- nil ];
- AVAssetWriterInput *bufferAssetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:outputSettings];
- AVAssetWriter *bufferAssetWriter = [[AVAssetWriter alloc]initWithURL:pathURL fileType:AVFileTypeQuickTimeMovie error:&error];
- [bufferAssetWriter addInput:bufferAssetWriterInput];
- [bufferAssetWriter startWriting];
- [bufferAssetWriter startSessionAtSourceTime:startTime];
- for (NSInteger i = 1; i < m_frameDataArray.count; i++){
- NSData *rawFrame = [m_frameDataArray objectAtIndex:i];
- CVImageBufferRef imgBuf = [rawFrame bytes];
- [pixelBufferAdaptor appendPixelBuffer:imgBuf withPresentationTime:CMTimeMake(1,10)]; //<-- EXC_BAD_ACCESS
- [rawFrame release];
- }
- //... (finishing video file)
- }
- CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
- CVPixelBufferLockBaseAddress(imageBuffer, 0);
- uint8 *baseAddress = (uint8*)CVPixelBufferGetBaseAddress(imageBuffer);
- NSData *rawFrame = [[NSData alloc] initWithBytes:(void*)baseAddress length:(height * bytesPerRow)];
- [m_frameDataArray addObject:rawFrame];
- CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement