As I know, in order to convert the footage from the camera into the picture you need to use the method

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

I also learned that it was impossible to call it explicitly, only through the delegate and through the queue. This is not clear. For example, the code from Apple, I do not know how to embed it in a project, so that it can work and play around with image processing. From a number of projects on a githaba, I saw that this method is sometimes only announced in a header file ( .h ), without implementation. (In general, the head does not fit).

Question: How to use this method correctly? In which file to write the queue correctly, and in which method itself? If there is somewhere in the network a short project in which this method works out - please give the link.

    1 answer 1

    And what exactly is wrong with the manual from eppla? Remove unnecessary release and remove outdated output.minFrameDuration = CMTimeMake (1, 15);

      -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{ //Метод вызывается при записи данных с камеры в буфер UIImage *image = [self imageFromSampleBuffer:sampleBuffer]; //Преобразовывать полученный буфер в картинку dispatch_sync(dispatch_get_main_queue(), ^{ self.imageView.image = [self applyMonoChromeWithRedColor:image]; //Применить какие-либо эффекты к изображению, // фильтр, к примеру, и добавить на экран }); } 

    When you initialize a session, you specify a delegate in the delegate class and describe the method. In general, the session here works in two streams, in fact, in the input you add the camera, to output your handler class as a delegate. simple example with blue filter overlay

    • For example, thank you very much. It works, the method works, the code is almost clear. It will be great if you do not go far. In the comments I may have to you, as a specialist questions. - Andrew Kachalin
    • But please tell me why the method -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBufferfromConnection:(AVCaptureConnection *)connection{ is placed only in the file - implementation? Why is it not present in the header (.h)? - Andrew Kachalin
    • Well, you can add, just why? To declare methods in the header file makes sense when, for example, you need to refer to them from another class. - Nerevarys
    • that is, can all methods not be placed in h , if the program is written in one class? And nothing breaks? - Andrew Kachalin
    • You can not declare, do not break. In objective, if I’m not mistaken, there are no private methods like in pluses (property can still be divided into public / private), so you scatter methods according to .h and .m in, if necessary, something like that. - Nerevarys