-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
VideoCapture::read() fails at 1080p on Android #22101
Description
As you know, the AIMAGE_FORMAT_YUV_420_888 format can be planar (YV12) or semi-planar (NV21):
This format is a generic YCbCr format, capable of describing any 4:2:0 chroma-subsampled planar or semiplanar buffer (but not fully interleaved), with 8 bits per color sample.
For example, on my phone I'm pretty sure the image is planar at <=720p and semi-planar at 1080p.
This logic in cap_android_camera.cpp fails to detect the format at 1080p:
if ( (uvPixelStride == 2) && (uPixel == vPixel + 1) && (yLen == frameWidth * frameHeight) && (uLen == ((yLen / 2) - 1)) && (vLen == uLen) ) {
colorFormat = COLOR_FormatYUV420SemiPlanar;
if (fourCC == FOURCC_UNKNOWN) {
fourCC = FOURCC_NV21;
}
} else if ( (uvPixelStride == 1) && (uPixel == vPixel + vLen) && (yLen == frameWidth * frameHeight) && (uLen == yLen / 4) && (vLen == uLen) ) {
colorFormat = COLOR_FormatYUV420Planar;
if (fourCC == FOURCC_UNKNOWN) {
fourCC = FOURCC_YV12;
}
} else {
colorFormat = COLOR_FormatUnknown;
fourCC = FOURCC_UNKNOWN;
LOGE("Unsupported format");
return false;
}
Here are values for these AImage variables for different resolutions:
| width | height | yPixel | yLen | uPixel | uLen | vPixel | vLen | yStride | uvStride | uvPixelStride |
|---|---|---|---|---|---|---|---|---|---|---|
| 640 | 480 | 0x7ab0094000 | 307200 | 0x7ab00e4000 | 153599 | 0x7ab00e4001 | 153599 | 640 | 640 | 2 |
| 960 | 720 | 0x7ab573d000 | 691200 | 0x7ab57f1000 | 345599 | 0x7ab57f1001 | 345599 | 960 | 960 | 2 |
| 1280 | 720 | 0x7ab4861000 | 921600 | 0x7ab4951000 | 460799 | 0x7ab4951001 | 460799 | 1280 | 1280 | 2 |
| 1440 | 1080 | 0x7aaef86000 | 1589728 | 0x7aaf10d000 | 794847 | 0x7aaf10d001 | 794847 | 1472 | 1472 | 2 |
| 1920 | 1080 | 0x7ab1c28000 | 2073600 | 0x7ab1e26000 | 1036799 | 0x7ab1e26001 | 1036799 | 1920 | 1920 | 2 |
So at least one condition (yLen == frameWidth * frameHeight) is not always correct.
I came across this bug because setting CAP_PROP_FOURCC to NV21 or YV12 always fails, only RGB is successful; and read() always fails for 1080p no matter the format.
System information (version)
- OpenCV => ❔
- Operating System / Platform => ❔
- Compiler => ❔
Detailed description
Steps to reproduce
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc