2013-05-20 46 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; 

      }