2011-04-10 5 views
1

AVCaptureSessionPresetMedium 이미지 크기?

// Create the session 
AVCaptureSession * newSession = [[AVCaptureSession alloc] init]; 

// Configure our capturesession 
newSession.sessionPreset = AVCaptureSessionPresetMedium; 

동적으로는 너비 x 높이로 해결할 것을 알 수있는 방법이 있습니까 AVCaptureSessionPresetMedium

를 사용하고 계십니까? 분명히 나는 ​​호출되는

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 

같은 위임 될 때까지 기다릴 수 거기를 결정하지만 성능상의 이유로 일부 값을 미리 계산 할 수 있도록 차라리 사전에 그것을 할 것입니다.

답변

4

나는 매우 행복 할 것이에 잘못 입증,하지만 다음 단계는 숫자 하드 코딩하지 않으려면 적절한 방법이 될 것 같습니다 :

-(CGSize)cameraSizeForCameraInput:(AVCaptureDeviceInput*)input 
{ 
     NSArray *ports = [input ports]; 
     AVCaptureInputPort *usePort = nil; 
     for (AVCaptureInputPort *port in ports) 
     { 
       if (usePort == nil || [port.mediaType isEqualToString:AVMediaTypeVideo]) 
       { 
         usePort = port; 
       } 
     } 

     if (usePort == nil) return CGSizeZero; 

     CMFormatDescriptionRef format = [usePort formatDescription]; 
     CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(format); 

     CGSize cameraSize = CGSizeMake(dim.width, dim.height); 

     return cameraSize; 
} 

이 호출되어야한다을 startRunning 호출 후, 결과는 0,0입니다. 나는 앞으로 무엇을 기대해야할지 모르겠다. 그래서 나는 ports 배열을 반복한다.

+0

완벽하게 작동합니다. 감사합니다. – Kyle