I want to add a filter to android webrtc.For example, I want to give a Blur effect to the Video Frame

Viewed 699

While looking for an example of applying a filter to webrtc, I followed the part that transforms a VideoFrame.

   @Override
    public void onFrameCaptured(VideoFrame frame) {
        if (this.videoEffector.needToProcessFrame()) {
            VideoFrame.I420Buffer originalI420Buffer = frame.getBuffer().toI420();
            VideoFrame.I420Buffer effectedI420Buffer =
                    this.videoEffector.processByteBufferFrame(
                            originalI420Buffer, frame.getRotation(), frame.getTimestampNs());
            VideoFrame effectedVideoFrame = new VideoFrame(
                    effectedI420Buffer, frame.getRotation(), frame.getTimestampNs());
            originalI420Buffer.release();
            frame.release();
            this.originalObserver.onFrameCaptured(effectedVideoFrame);
        } else {
            this.originalObserver.onFrameCaptured(frame);
        }
    }

I succeeded in applying the blur filter using the onFrameCapturerd function. However, GC is happening too much. So the camera works too slowly. I went to a lot of places and found

ByteBuffer outRgbaBuffer = ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder());
ByteBuffer dataYBuffer = ByteBuffer.allocateDirect(strideY * height).order(ByteOrder.nativeOrder());
ByteBuffer dataUBuffer = ByteBuffer.allocateDirect(strideU * height).order(ByteOrder.nativeOrder());
ByteBuffer dataVBuffer = ByteBuffer.allocateDirect(strideV * height).order(ByteOrder.nativeOrder());

GC continues to run on this line. allocateDirect method How to solve it? Or could you please tell me another way to apply a filter to webrtc?

0 Answers
Related