在我的应用程序中,我使用 AVCaptureSession
来录制视频
。
录制完成后,我得到的视频尺寸为360 X 480
。
我已将录制层大小设置为320 X 568
。
我遗漏了一些东西,我尝试过但没有得到结果。
谁能指导我应该在哪里更改才能录制大小为 320 X 568
的视频
这是我的代码,
初始化
AVCaptureDevice* device = nil;
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
captureOutput.alwaysDiscardsLateVideoFrames = YES;
dispatch_queue_t queue;
queue = dispatch_queue_create("cameraQueue", NULL);
[captureOutput setSampleBufferDelegate:self queue:queue];
dispatch_release(queue);
//设置视频输出将帧存储在BGRA中
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[captureOutput setVideoSettings:videoSettings];
//我们创建一个捕获 session
self.captureSession = [[AVCaptureSession alloc] init];
self.captureSession.sessionPreset = AVCaptureSessionPresetMedium;
if([self.captureSession respondsToSelector:@selector(addInput:)])
[self.captureSession addInput:captureInput];
if([self.captureSession respondsToSelector:@selector(addOutput:)])
[self.captureSession addOutput:captureOutput];
/*We add the Custom Layer (We need to change the orientation of the layer so that the video is displayed correctly)*/
self.customLayer = [CALayer layer];
self.customLayer.frame = self.view.bounds;
self.customLayer.transform = CATransform3DRotate(CATransform3DIdentity, M_PI/2.0f, 0, 0, 1);
self.customLayer.transform = CATransform3DScale(self.customLayer.transform,.7,.7,1);
self.customLayer.transform = CATransform3DTranslate(self.customLayer.transform,-23,0,0);
self.customLayer.contentsGravity = kCAGravityResizeAspectFill;
[self.view.layer addSublayer:self.customLayer];
[self.captureSession startRunning];
//初始化结束
最佳答案
您能否尝试在代码的此行 self.customLayer.frame = self.view.bounds;
之前检查是否是 iphone5。如果是,则手动设置其框架,如
您可以检查如下:-
#define isiPhone5 ([[UIScreen mainScreen] 边界].size.height == 568)?TRUE:FALSE
//We add the Custom Layer (We need to change the orientation of the layer so that the video is displayed correctly)*/
self.customLayer = [CALayer layer];
if(isIphone5)
{
self.customLayer.frame = CGRectMake(0, 0, 320, 568);
}
else
{
self.customLayer.frame = CGRectMake(0, 0, 320, 480);
}
希望这对你有帮助,我的 friend
关于iphone - 使用 AVCaptureSession 录制的视频帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650356/