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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With