Re: How to add "filter" to capture video from the camera?
Re: How to add "filter" to capture video from the camera?
- Subject: Re: How to add "filter" to capture video from the camera?
- From: douglas welton <email@hidden>
- Date: Thu, 29 Dec 2011 11:35:12 -0500
Hi,
Step A:
In your delegate for AVCaptureVideoDataOutput, you can use the method
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
to grab CMSampleBufferRef representing each frame. You'll need to get a hold of the actual data bytes using various functions for CMSampleBufferRef and/or CMBlockBufferRef. I will assume that you are getting this data back in an RGB format. If not, you'll need to make sure that the requested pixel format attributes give you RGB data.
Step B:
Once you get the data buffer, you can get a CIImage using this method:
+ (CIImage *)imageWithBitmapData:(NSData *)d bytesPerRow:(size_t)bpr size:(CGSize)size format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs
or you can use a CIImageProvider to create a CIImage.
Step C:
Push your CIImage thru the various CIFilters that you would like to apply.
Step D:
Render your CIImage into a bitmap buffer. Take that data and make a CMSampleBufferRef or CVPixelBufferRef, then push that object thru an AVAssetWriter object to get the sample written to the destination file.
Note: This process can take a long time and when done in-line can cause captured frames to be dropped, so you'll probably want to copy the incoming CMSampleBuffers and process them on a separate thread. Also, the standard disclaimers about having written this in an e-mail apply, as well.
Hope that helps.
regards,
douglas
On Dec 28, 2011, at 11:58 PM, 吴明 wrote:
>
>
>
>
> you know that i want to use this function to my ios app.
>
>
>
> I know use AVCaptureVideoDataOutputSampleBufferDelegate can get every frame data from capture, but i dont know how to change this data with CVImageBufferRef datatype.
>
>
> 在 2011-12-29 01:32:41,"Nick Zitzmann" <email@hidden> 写道:
>>
>> On Dec 27, 2011, at 11:16 PM, 吴明 wrote:
>>
>>> HI All:
>>> I wont capture view from the camera. and add an image to every frame.then save the video to my app.
>>> How do this.
>>
>> Use QTCaptureView and implement the delegate method -view:willDisplayImage:. In that method, do what you want to do to the frame, and it will be included in the final video.
>>
>> Nick Zitzmann
>> <http://www.chronosnet.com/>
>>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden