2013-05-20 50 views
2

在我的应用程序中,我使用AVCaptureSession来记录video使用AVCaptureSession记录视频帧

录制完成后,我得到的视频大小为360 X 480

我已经设置的记录层大小是320 X 568

我失去了一些东西,我试过但没有得到的地方。

任何人都可以指导我,我应该在哪里换得到记录video320 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]; 

//我们创建捕获会话

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]; 

//初始化过

+0

使用'VideoSettings'属性。 – Buntylm

+0

确保你不会忘记添加iphone5 [email protected] –

+0

@Nitin,是的,我已经添加[email protected] – Nikunj

回答

0
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset320*568]) 
    { 
     [self.captureSession setSessionPreset:AVCaptureSessionPreset320*568]; 
    } 

试试这个。

+0

哪里是这个选项吗?AVCaptureSessionPreset320 * 568。它给出错误。 – Nikunj

1

请问您是否可以在此行代码的self.customLayer.frame = self.view.bounds;之前检查一下它的iphone5或不是。如果是,那么手动设置它的框架像

,您可以检查,如: -

#define isiPhone5 ([[UIScreen mainScreen] bounds].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); 

} 

希望这个帮的你我FRND

+0

感谢您的回复是的,我已经这样做了,但没有任何改变。 – Nikunj

1

AvCaptureSessionMedium不会让你的320 * 568的图像解析度。在AVCaptureSession中没有为此分辨率设置属性。

AVCaptureSessionPresetMedium使用的摄像头分辨率为360.000000和480.000000。 这是AVCaptureSessionPresetMedium的默认分辨率,因此它不适用于iPhone-5显示器。

如果你想在iPhone-5上获得更高分辨率的图像,你应该使用AVCaptureSessionPresetHigh。但它会为您提供1980 * 1080的图像分辨率。所以它可以正常工作,但会增加图像的大小字节。

您也可以通过此检查:

AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];  

    if (IS_IPHONE5) 
    {   
       newCaptureSession.sessionPreset = AVCaptureSessionPresetHigh; 
    } 
    else 
      { 
      newCaptureSession.sessionPreset = AVCaptureSessionPresetMedium; 

      }