Preview error - Frame format / Color space error - could not negotiate with camera:err=-51
Closed this issue · 3 comments
While trying to make this package work with a boroscope camera on my phone, I figured that the preview wasn't opening because of a frame format error.
Error: could not negotiate with camera:err=-51
.
Related issues in jiangdongguo AndroidUSBCamera:
So my fix was to alter line 154 in the CustomCameraUVC.kt source. The try catch block wasn't working in my wrong frame format case.
CustomCameraUVC.kt
:
try {
Logger.i(TAG, "getSuitableSize: $previewSize")
if (! isPreviewSizeSupported(previewSize)) {
closeCamera()
postStateEvent(ICameraStateCallBack.State.ERROR, "unsupported preview size")
Logger.e(TAG, "open camera failed, preview size($previewSize) unsupported-> ${mUvcCamera?.supportedSizeList}")
return
}
initEncodeProcessor(previewSize.width, previewSize.height)
// if give custom minFps or maxFps or unsupported preview size
// this method will fail
mUvcCamera?.setPreviewSize(
previewSize.width,
previewSize.height,
MIN_FS,
MAX_FPS,
UVCCamera.FRAME_FORMAT_YUYV, // ALTERED HERE !!!
UVCCamera.DEFAULT_BANDWIDTH
)
} catch (e: Exception) {
try {
previewSize = getSuitableSize(request.previewWidth, request.previewHeight).apply {
mCameraRequest!!.previewWidth = width
mCameraRequest!!.previewHeight = height
}
if (! isPreviewSizeSupported(previewSize)) {
postStateEvent(ICameraStateCallBack.State.ERROR, "unsupported preview size")
closeCamera()
Logger.e(TAG, "open camera failed, preview size($previewSize) unsupported-> ${mUvcCamera?.supportedSizeList}")
return
}
Logger.e(TAG, " setPreviewSize failed, try to use yuv format...")
mUvcCamera?.setPreviewSize(
previewSize.width,
previewSize.height,
MIN_FS,
MAX_FPS,
UVCCamera.FRAME_FORMAT_YUYV,
UVCCamera.DEFAULT_BANDWIDTH
)
} catch (e: Exception) {
closeCamera()
postStateEvent(ICameraStateCallBack.State.ERROR, "err: ${e.localizedMessage}")
Logger.e(TAG, " setPreviewSize failed, even using yuv format", e)
return
}
}
It appears that some devices need more configuration options: Frame format, min/max Fps and Bandwidth. I think it would be great to pass these parameters from flutter to android and using them to instantiate the camera.
Thank you very much for the suggestion, I don't have time to adjust the testing at the moment, so I'll consider adding it to subsequent versions.😁
Updated to version 0.0.3, thanks!
Thanks!