मैं एक आईओएस एप्लिकेशन (मेरा पहला) बना रहा हूं जो वीडियो को अभी भी फ्लाई पर फ्रेम करता है। इसमें कूदने के लिए, मैंने ऐप्पल से example from the AV* documentation का पालन किया।AVCaptureDeviceOutput प्रतिनिधि विधि कैप्चर नहीं कर रहा है आउटपुट
प्रक्रिया में एक इनपुट (कैमरा) और आउटपुट स्थापित करना शामिल है। आउटपुट एक प्रतिनिधि के साथ काम करता है, जो इस मामले में नियंत्रक स्वयं होता है (यह आवश्यक विधि को अनुरूप और लागू करता है)।
मेरी समस्या यह है कि प्रतिनिधि विधि को कभी भी बुलाया नहीं जाता है। नीचे दिया गया कोड नियंत्रक का कार्यान्वयन है और इसमें कुछ एनएसएलॉग हैं। मैं "प्रारंभ" संदेश देख सकता हूं, लेकिन "प्रतिनिधि विधि" जिसे कभी नहीं दिखाया जाता है।
यह कोड सभी एक नियंत्रक के भीतर है जो "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);
}
नोट: मैं एक लक्ष्य के रूप आईओएस 5.0 के साथ निर्माण कर रहा हूँ।
संपादित करें:
मैं एक question पाया है कि, हालांकि एक अलग समस्या का समाधान के लिए पूछ, क्या कर रही है वास्तव में क्या मेरे कोड करने के लिए माना जाता है। मैंने उस प्रश्न से कोड को रिक्त एक्सकोड ऐप में कॉपी किया है, कैप्चरऑटपुट फ़ंक्शन में NSLogs जोड़ा गया है और इसे कॉल नहीं किया जाता है। क्या यह एक विन्यास मुद्दा है? क्या मुझे कुछ याद आ रही है?
यदि आपका सत्र चलने में कोई त्रुटि हो रही है (संभवतः जब से आपको कोई फ्रेम नहीं मिल रहा है) तो यह 'AVCaptureSessionRuntimeErrorNotification' अधिसूचना पोस्ट करेगा। '[[NSNotificationCenter defaultCenter] addObserver का उपयोग करके इसके लिए सुनो: चयनकर्ता: नाम: ऑब्जेक्ट:]; 'और जब आपका चयनकर्ता कहलाता है, तो त्रुटि देखने के लिए उपयोगकर्ता शब्दकोश से' AVCaptureSessionErrorKey 'प्राप्त करें। – lnafziger
आपके इनपुट @Inafziger के लिए धन्यवाद। मैंने AVCaptureSessionRuntimeErrorNotification को संदेह किया लेकिन यह ट्रिगर नहीं लग रहा है: | – SuitedSloth
व्यू कंट्रोलर किस तरह से बनाया गया है? आउटपुट प्राप्त 'शुरू' किया है? – Tommy