begeekmyfriend / yasea

RTMP live streaming client for Android
MIT License
4.87k stars 1.32k forks source link

Stream with Camera2 #398

Open alviss2108 opened 7 years ago

alviss2108 commented 7 years ago

I tested with camera2. But output bytearray from ImageReader can't convert to yuv420. Result from stream has many green lines. How can I convert to yuv420 or nv21? ImageReader init: ImageReader mImageReader = ImageReader.newInstance(1280, 720, ImageFormat.YUV_420_888, /maxImages/2); OnImageAvailableListener private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {

    @Override
    public void onImageAvailable(ImageReader reader) {
        Image image = null;
        try {
            if (reader != null) {
                image = reader.acquireLatestImage();
                if (test != null) {
                    ByteBuffer byteBuffer = image.getPlanes()[0].getBuffer();
                    byte[] data = new byte[byteBuffer.capacity()];
                    ((ByteBuffer) byteBuffer.duplicate().clear()).get(data);
                    mPrevCb.onGetYuvFrame(bytes);
                    test.close();
                }
            }
        } catch (IllegalStateException e) {
            //
        }
    }
};
Easyhong commented 5 years ago

I also encountered the same problem, may I ask whether you have solved it?

begeekmyfriend commented 5 years ago

For the original master branch (GLSurfaceView) the default image format is RGBA containing 32bits that means 8888.

begeekmyfriend commented 5 years ago

By the way, I am unavailable for Android development. Any PR is welcome.