Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Programmatically Take Photos While Recording Video

The iPhone 5S is capable of taking pictures while recording video and I am trying to figure out how I would do this programatically. I know I would be utilizing AVFoundation, however, I couldn't find anything in the programming guide regarding this. I have also checked the sample projects (AVFoundation-related) and it doesn't look like there is anything there that does what I am looking for. if you could help point me in the right direction that would be great.

like image 868
Stunner Avatar asked Dec 26 '22 10:12

Stunner


2 Answers

Actually you can do it with any device that can record video:

  • Create and configure a AVCaptureVideoDataOutput.
  • Add it to your AVCaptureSession.
  • Add a AVCaptureVideoDataOutputSampleBufferDelegate.
  • Implement captureOutput:didOutputSampleBuffer:fromConnection: in the delegate and get the image with imageFromSampleBuffer:.

Some similar code can be found here, where images are captured at a given interval, but you only want one image.

like image 68
Rivera Avatar answered Dec 28 '22 10:12

Rivera


In iOS7 there has a new api to capture UIView, we can get image and do something.

eg:

UIView+Screenshot.h
-(UIImage *)convertViewToImage;

UIView+Screenshot.m

-(UIImage *)convertViewToImage
{
    UIGraphicsBeginImageContext(self.bounds.size);
    [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

Apple's Document: drawViewHierarchyInRect:afterScreenUpdates:

like image 44
eason Avatar answered Dec 28 '22 09:12

eason