2012-03-13 3 views
0

내 iPad에서 비디오에서 그림을 캡처하려고합니다. Apple의 AVCam 예제를 시작점으로 사용했습니다.AVFoundation을 사용하여 비디오에서 그림 캡처

내 응용 프로그램에서 비디오를보고 비디오에서 사진을 찍을 수있었습니다. 내 문제는 결과 이미지의 픽셀 크기가 잘못되었습니다. 나는 전체 화면 그림 (1024x768)을 원하지만 작은 화면 (1024x720)을 얻는다. 여기

@property (retain) AVCaptureStillImageOutput *stillImageOutput; 
@property (retain) AVCaptureVideoPreviewLayer *previewLayer; 
@property (retain) AVCaptureSession *captureSession; 
@property (retain) AVCaptureConnection *captureConnection; 
@property (retain) UIImage *stillImage; 

코드가 사진을 찍을 수 :

내 인스턴스 변수

- (void)takePicture 
{ 
    AVCaptureConnection *videoConnection = nil; 
    for (AVCaptureConnection *connection in [[self stillImageOutput] connections]) { 
     for (AVCaptureInputPort *port in [connection inputPorts]) { 
      if ([[port mediaType] isEqual:AVMediaTypeVideo]) { 
       videoConnection = connection; 
       break; 
      } 
     } 
     if (videoConnection) { 
      break; 
     } 
    } 
    NSLog(@"about to request a capture from: %@", [self stillImageOutput]); 
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection 
                 completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { 
                  CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL); 
                  if (exifAttachments) { 
                   NSLog(@"attachements: %@", exifAttachments); 
                  } else { 
                   NSLog(@"no attachments"); 
                  } 
                  NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; 
                  UIImage *image = [[UIImage alloc] initWithData:imageData]; 
                  [self setStillImage:image]; 
                  [image release]; 
                  [[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil]; 
                 }]; 
} 

나는 마지막 사진의 크기를 조절 생각하지만,이 솔루션은 이미지의 품질을 줄일 것입니다. 나는 또한 사전에 값 PixelYDimension = 720;이 포함되어 있다는 것을 알았지 만, 그와 상호 작용할 수있는 방법을 찾지 못하는 것 같습니다.

도움이 될 것입니다. 미리 감사 드리며 좋은 하루 되십시오.

Alex.

편집 : 내가 말할 때 "비디오에서 사진을 촬영"고 지적하고 싶습니다 내가 비디오가 아이 패드의 카메라에서 라이브오고 및 녹음되지 않습니다 것을 의미했다.

답변

2

문제점에 대한 해결책을 찾았습니다. 여기 누군가가 장래에 이것을 찾으면됩니다.

AVFoundation을 사용하여 카메라와 상호 작용하려면 AVCaptureSession 변수를 시작해야합니다. 이렇게하면 출력의 품질 수준 또는 비트 전송률을 나타내는 sessionPreset을 수정할 수 있습니다. set of different constants이 있습니다. 내가 사용한 1024x768 사진을 찍으려면 AVCaptureSessionPresetPhoto

관련 문제