BebopVideoView to Mat

馋奶兔 提交于 2019-12-06 09:28:48

If you use a TextureView you can simply grab a bitmap of it and convert it to a Mat. You need to use the TextureView's provided surface rather than the typical SurfaceView holder. This will require some additional refactoring of the mediaCodec lifecycle, but is a fairly trivial change.

public class BebopVideoView extends TextureView implements TextureView.SurfaceTextureListener {

    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        this.surface = new Surface(surface);
        surfaceCreated = true;
    }

...

}

And inside of configureMediaCodec use the class level surface captured in onSurfaceTextureAvailable instead....

mediaCodec.configure(format, surface, null, 0);

With a couple other minor tweaks you now have a lot more control over the view. You can do things like setTransform() and more importantly in your case getBitmap:

Mat mat = new Mat();
Utils.bitmapToMat(getBitmap(), mat);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!