jiangdongguo / AndroidUSBCamera

🔥🔥🔥Flexible and useful UVC camera engine on Android platform, supporting multi-road cameras!
https://juejin.cn/post/7115229806844706847
Apache License 2.0
2.35k stars 801 forks source link

setOnPreviewFrameListener not working #233

Open faiz03249 opened 4 years ago

faiz03249 commented 4 years ago

mCameraHelper.setOnPreviewFrameListener this method is not getting called .Not able to get the fram of the video.

jiangdongguo commented 4 years ago

how about change you camera?

faiz03249 commented 4 years ago

i changed camera as well . this method was working before . Now frames listener is not getting called on connecting camera .

jiangdongguo commented 4 years ago

I see. Let me check it.

heaveninfosoft commented 4 years ago

I see. Let me check it.

how to do dual USB Camera??

JCCAbrunhosa commented 4 years ago

Any news regarding this issue? I can't seem to get the listener to work. I want to capture the frame but nothing happens.

kanstantsin commented 4 years ago

Got same issue. For me the problem was in following piece of code.

            try {
                mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, mPreviewMode, mBandwidthFactor);
                // 获取USB Camera预览数据,使用NV21颜色会失真
                // 无论使用YUV还是MPEG,setFrameCallback的设置效果一致
//              mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_NV21);
                mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_YUV420SP);
            } catch (final IllegalArgumentException e) {
                try {
                    // fallback to YUV mode
                    mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, UVCCamera.DEFAULT_PREVIEW_MODE, mBandwidthFactor);
                } catch (final IllegalArgumentException e1) {
                    callOnError(e1);
                    return;
                }
            }

I got exception at mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, mPreviewMode, mBandwidthFactor); and jumped to catch block: mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, UVCCamera.DEFAULT_PREVIEW_MODE, mBandwidthFactor); which uses UVCCamera.DEFAULT_PREVIEW_MODE but does not set frame callback. Inserting mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_YUV420SP); after this line fixed callback issue for me.

@jiangdongguo, looks like a bug. If so, is my fix correct?

wcj85422107 commented 2 years ago

Got same issue. For me the problem was in following piece of code.

            try {
                mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, mPreviewMode, mBandwidthFactor);
                // 获取USB Camera预览数据,使用NV21颜色会失真
                // 无论使用YUV还是MPEG,setFrameCallback的设置效果一致
//                mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_NV21);
                mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_YUV420SP);
            } catch (final IllegalArgumentException e) {
                try {
                    // fallback to YUV mode
                    mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, UVCCamera.DEFAULT_PREVIEW_MODE, mBandwidthFactor);
                } catch (final IllegalArgumentException e1) {
                    callOnError(e1);
                    return;
                }
            }

I got exception at mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, mPreviewMode, mBandwidthFactor); and jumped to catch block: mUVCCamera.setPreviewSize(mWidth, mHeight, 1, 31, UVCCamera.DEFAULT_PREVIEW_MODE, mBandwidthFactor); which uses UVCCamera.DEFAULT_PREVIEW_MODE but does not set frame callback. Inserting mUVCCamera.setFrameCallback(mIFrameCallback, UVCCamera.PIXEL_FORMAT_YUV420SP); after this line fixed callback issue for me.

@jiangdongguo, looks like a bug. If so, is my fix correct?

Have you solved it