views:

35

answers:

1

Hey folks. Trying to get started with iPhone video capture stuff, and having a terrible time getting it going.

At the moment, working with an exact copy of the sample code from this Apple Developer Q&A: qa1702; not going to re-paste it here, since it's a relatively big blob of code.

In any case, I copied and pasted that code into an otherwise-empty project, threw in a call to setupCaptureSession into a custom UIView, and figured I should be good to go:

- (void)awakeFromNib {
    NSLog(@"init");
    [self setupCaptureSession]; 
}

Unfortunately, when I run the code, my delegate never seems to be called:

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
       fromConnection:(AVCaptureConnection *)connection
{ 
    NSLog(@"New Image!");
}

I'd expect to be seeing a flood of "New Image!" getting dumped to the log, but I'm getting absolutely nothing. I do know that all the initialization code is being run (I threw a few NSLog statements here and there within setupCaptureSession, and they all print).

So, I'd either A) like to figure out what I'm doing wrong or B) see some very simple capture code embedded into a UIView that actually works (the less code, the better). Ideally, the sample code would use the setupCaptureSession code as described in the Apple developer site above.

Note that this code is being tested on an iPhone 3GS running the newest version of iOS 4.

Thanks in advance!

+1  A: 

I copied and pasted the same code into a new project and it works fine for me. Here is what I did:

I created a View Based application in XCode.

I added the following frameworks:CoreMedia, CoreVideo,AVFoundation

I imported AVFoundation into my viewcontroller's header file

I specified my view controller to use the AVCaptureVideoDataOutputSampleBufferDelegate protocol in its interface definition

In the implementation I copied the code from the app document you specified in your question

I commented out this:

 [self setSession:session]

I commented out this:

UIImage *image = [self imageFromSampleBuffer:sampleBuffer];

and added this:

NSLog(@"here");

In the viewDidLoad method i put

 [self setupCaptureSession];

Build. Run. The "here" gets printed repeatedly to the console.

twerdster
Thanks for the help; directions were clear, and worked well. I'd still like to know why the UIView approach doesn't work, but I suppose I'll go with what works for now.
cubic1271
Hi. The UIView approach definitely does work. In fact you could quite easily make a camera previewer by setting a UIImageView's image property to the UIImage returned in the delegate function. In fact, if you follow the above instructions but dont comment out the UIImage stuff and add a UIImage to your view controller then you are set to go because a UIImageViews image property is with retain and you dont have to worry about releasing the image. Let me know if you need code
twerdster