How to add custom filters to Video while recording using camera2 api

Viewed 170

I am creating an app where I need to apply filters to the my video while recording it. For example the way we apply filters to the video in Retrica app. I am using camera 2 api as I have not been able to find anything regarding this in Camera x. Right now I am using the following way to apply filters to the video

 captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);

captureRequestBuilder.set (CaptureRequest.CONTROL_EFFECT_MODE, CaptureRequest.CONTROL_EFFECT_MODE_SEPIA);

There are some deafult values that we can use to apply such filters in camera2 api. What I want to do is also add custom filter effects to the video. How can I add such filters?

1 Answers

CONTROL_EFFECT_MODE has a small list of effects that the device implements somewhere in its camera code.

If you want to create your own, you need to send the camera data to somewhere you can process it. A common choice is using OpenGL ES or Vulkan for your image processing step. For that, you need to set up an OpenGL context, create a SurfaceTexture and bind it to a GL texture, and then send camera data to the Surface created from the SurfaceTexture. Then you can write a fragment shader that edits the texture and writes that out.

You can also do the editing in Java/native code using an ImageReader to get YUV_420_888 images.

All of that requires a lot of scaffolding of your own, unfortunately.

Related