I have the following code which work well with dimensions multiple of 480x320. But my OpenGL scene is 600x600; based on the screen layout I don't want to change.
Is it possible to encode in (kind of) free dimensions or are we bound to (480x
320)xn
writing the frame I do with the following code
Conversion of RGBA to BRGA seems ok; its really just the dimensions (I guess)
If I do that I get the following
https://www.youtube.com/watch?v=g_osJC5fTG8
if I choose like 1280x780 I get the proper output; except its not cropped the way I want
https://www.youtube.com/watch?v=luhc0xleMZ8
Any idea ?
Is it possible to encode in (kind of) free dimensions or are we bound to (480x
320)xn
Code:
self.videoSize = self.view.bounds.size;
// self.videoSize = CGSizeMake(1280 , 780);
NSMutableDictionary * outputSettings = [[NSMutableDictionary alloc] init];
[outputSettings setObject: AVVideoCodecH264 forKey: AVVideoCodecKey];
[outputSettings setObject: [NSNumber numberWithInt: self.videoSize.width] forKey: AVVideoWidthKey];
[outputSettings setObject: [NSNumber numberWithInt: self.videoSize.height] forKey: AVVideoHeightKey];
self.assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:outputSettings];
self.assetWriterInput.expectsMediaDataInRealTime = YES;
NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey,
[NSNumber numberWithInt:self.videoSize.width], kCVPixelBufferWidthKey,
[NSNumber numberWithInt:self.videoSize.height], kCVPixelBufferHeightKey,
nil];
self.assetWriterPixelBuffer = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:self.assetWriterInput sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];
[self.assetWriter addInput:_assetWriterInput];
self.assetWriter.metadata = metadata;
[self.assetWriter startWriting];
self.startTime = [NSDate dateWithTimeIntervalSinceNow:0];
[self.assetWriter startSessionAtSourceTime:kCMTimeZero];
self.videoIsRecording = TRUE;
writing the frame I do with the following code
Code:
CVPixelBufferRef pb = NULL;
CVReturn status = CVPixelBufferPoolCreatePixelBuffer (NULL, [self.assetWriterPixelBuffer pixelBufferPool], &pb);
if ((pb == NULL) || (status != kCVReturnSuccess))
{
CLLog(@"error with frame %d", status);
self.startTime = NULL;
return;
}
else
{
CVPixelBufferLockBaseAddress(pb, 0);
GLubyte *pixelBufferData = (GLubyte *)CVPixelBufferGetBaseAddress(pb);
glReadPixels(0, 0, self.videoSize.width, self.videoSize.height, GL_BGRA, GL_UNSIGNED_BYTE, pixelBufferData);
CMTime currentTime = CMTimeMakeWithSeconds([[NSDate date] timeIntervalSinceDate:_startTime],120);
if (![_assetWriterPixelBuffer appendPixelBuffer:pb withPresentationTime:currentTime])
{
CLLog(@"Problem at time: %lld", currentTime.value);
}
CVPixelBufferUnlockBaseAddress(pb, 0);
CVPixelBufferRelease(pb);
}
Conversion of RGBA to BRGA seems ok; its really just the dimensions (I guess)
If I do that I get the following
https://www.youtube.com/watch?v=g_osJC5fTG8
if I choose like 1280x780 I get the proper output; except its not cropped the way I want
https://www.youtube.com/watch?v=luhc0xleMZ8
Any idea ?