Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add core image filters to OpenTok video?

When I publish a stream on iOS, TokBox uses the default camera. Is there a way to add live filters to the publisher?

I just want some easy, sample code on how to create a filter and attach it to the opentok publisher object (OTVideoCapture).

Or, if that's not the right way to do it...attaching the filter on the subscriber side works too.

How can this be done easily?

like image 376
TIMEX Avatar asked Aug 31 '15 10:08

TIMEX


People also ask

How do I apply a filter to my video?

Click Apply Filter or Done Adjusting button to commit your changes. When you're ready to download, hit the Export button and give Kapwing some time to process your project. Once it's done, you can download your finished video or share it directly on social media. Filters for video aren't just for superficial purposes.

How does a color filter work in Core Image?

As with all color filters, this operation is performed in the working color space of the Core Image context ( CIContext) executing the filter, using unpremultiplied pixel color values. If you see unexpected results, verify that your output and working color spaces are set up as intended.

How do I use the ciheightfieldfrommask filter?

You can combine this filter with the CIHeightFieldFromMask filter to produce quick shadings of masks, such as text. This filter sets the input image as a height-field (multiplied by the scale parameter), and computes a normal vector for each pixel.

What is the cishadedmaterial filter in iOS?

You can use this filter with the CIShadedMaterial filter to produce extremely realistic shaded objects. Available in OS X v10.4 and later and in iOS 9 and later. Maps an image to colored hexagons whose color is defined by the replaced pixels. A CIImage object whose display name is Image.


1 Answers

As I understand you want to apply filters before sending video data and also in real time. There is no easy source code here but I could tell you path.

For real time video filters you could use GPUImage framework. It has ready to use camera GPUImageVideoCamera class. So you need to create class which implements GPUImageInput (it is target in terms of GPUImage) which will produce OTVideoFrame frame from input and add it to pipeline.

Something like this:

videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];

videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
videoCamera.horizontallyMirrorFrontFacingCamera = NO;
videoCamera.horizontallyMirrorRearFacingCamera = NO;

// filter
filter = [[GPUImageSepiaFilter alloc] init];
[videoCamera addTarget:filter];

// frame producer for OTVideoCapture
frameProducer = [[FrameProducer alloc] init];
[filter addTarget:frameProducer];

// camera view to show what we record
[filter addTarget:filterView];

Also you need custom implementation of OTVideoCapture protocol for OpenTok itself. You could use TBExampleVideoCapture from Lets-Build-OTPublisher sample as a start point. You need to replace camera code with above GPUImageVideoCamera camera code to use filters in real time.

like image 67
John Tracid Avatar answered Oct 12 '22 10:10

John Tracid