나는 비디오 스틸 프레임을 즉시 처리하는 iOS 응용 프로그램을 개발하고 있습니다. 이것에 들어가기 위해서, 나는 Apple의 example from the AV* documentation을 따랐다.AVCaptureDeviceOutput 대리자 메서드를 호출하지 않습니다. captureOutput
이 프로세스에는 입력 (카메라)과 출력을 설정하는 과정이 포함됩니다. 출력은 위임자 (이 경우 제어기 자체)에서 작동합니다 (필요한 메소드를 준수하고 구현 함).
내가 겪고있는 문제는 위임 메서드가 호출되지 않는다는 것입니다. 아래의 코드는 컨트롤러의 구현이며 두 개의 NSLog가 있습니다. "시작된"메시지를 볼 수 있지만 "위임 된 메서드"는 결코 표시되지 않습니다.
이 코드는 모두 "AVCaptureVideoDataOutputSampleBufferDelegate"프로토콜을 구현하는 컨트롤러 내에 있습니다.
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize AV session
AVCaptureSession *session = [AVCaptureSession new];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[session setSessionPreset:AVCaptureSessionPreset640x480];
else
[session setSessionPreset:AVCaptureSessionPresetPhoto];
// Initialize back camera input
AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:camera error:&error];
if([session canAddInput:input]){
[session addInput:input];
}
// Initialize image output
AVCaptureVideoDataOutput *output = [AVCaptureVideoDataOutput new];
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[output setVideoSettings:rgbOutputSettings];
[output setAlwaysDiscardsLateVideoFrames:YES]; // discard if the data output queue is blocked (as we process the still image)
//[output addObserver:self forKeyPath:@"capturingStillImage" options:NSKeyValueObservingOptionNew context:@"AVCaptureStillImageIsCapturingStillImageContext"];
videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
[output setSampleBufferDelegate:self queue:videoDataOutputQueue];
if([session canAddOutput:output]){
[session addOutput:output];
}
[[output connectionWithMediaType:AVMediaTypeVideo] setEnabled:YES];
[session startRunning];
NSLog(@"started");
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
NSLog(@"delegate method called");
CGImageRef cgImage = [self imageFromSampleBuffer:sampleBuffer];
self.theImage.image = [UIImage imageWithCGImage: cgImage ];
CGImageRelease(cgImage);
}
참고 : 내가 대상으로 아이폰 OS 5.0 짓고 있어요.
편집 : 나는 다른 문제에 대한 해결책을 요구하지만, 내 코드가 어떻게해야 정확히 무엇을하고있는 것을하는 question을 발견했습니다
. 그 질문에 대한 코드를 빈 xcode 앱에 복사하고 NSLog를 captureOutput 함수에 추가했는데 호출되지 않습니다. 이것은 구성 문제입니까? 내가 빠진 것이 있습니까?
세션을 시작하는 중에 오류가 발생하면 (프레임을 가져 오지 않았기 때문에) 'AVCaptureSessionRuntimeErrorNotification' 알림을 게시합니다. '[NSNotificationCenter defaultCenter] addObserver : selector : name : object :];를 사용하여 이것을 듣고 선택기가 호출되면 사용자 사전에서 'AVCaptureSessionErrorKey'를 가져 와서 오류를 확인하십시오. – lnafziger
@Inafziger 입력 해 주셔서 감사합니다. 내가 AVCaptureSessionRuntimeErrorNotification에 suscribed하지만 트리거하지 않는 것 같습니다 : | – SuitedSloth
무슨 뜻으로 뷰 컨트롤러가 생성됩니까? '시작'에 출력이 표시됩니까? – Tommy