saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
2.99k stars 1.2k forks source link

documentation error for NV21 and YUV420 modes #207

Open RogerHardiman opened 7 years ago

RogerHardiman commented 7 years ago

Hi This is a great library and works really well.

Small issue with the code and YUV420 and NV21 outputs from cameras in YUYV mode

In frame.c it are some comments that says that 'iyuv420sp' (first character is 'i') is for NV21. ''' @brief Convert a frame to iyuv420sp(NV21) '''

But in UVCPreview.cpp the PIXEL_FORMAT_NV21 does not call 'iyuv420sp'. It calls a different function ''' case PIXEL_FORMAT_YUV20SP: LOGI("PIXEL_FORMAT_YUV20SP:"); mFrameCallbackFunc = uvc_yuyv2iyuv420SP; callbackPixelBytes = (sz 3) / 2; break; case PIXEL_FORMAT_NV21: LOGI("PIXEL_FORMAT_NV21:"); mFrameCallbackFunc = uvc_yuyv2yuv420SP; // <- this does not match frame.c comments callbackPixelBytes = (sz 3) / 2; break; '''

I'll try and look at the output data and then see if the code is wrong or if it is just the comments that are wrong.

Thanks again for the library. It is really good.

fengbenpaao commented 7 years ago

do you know how to show h264 preview ? Let's learn from each other!!!

RogerHardiman commented 7 years ago

I do not know how to get the video in H264 format from the camera and do not have any cameras that have that feature.

sappho192 commented 7 years ago

Was the output data different? I think this is his mistake since when I load frame data with NV21, red and blue data order is swapped so I need to swap them. AFAIK reversed RGB order of NV21 is YUV20SP.

RogerHardiman commented 7 years ago

Hi @sappho192 If I remember correctly the yuv data returned does not match Enum name.

sappho192 commented 7 years ago

Then I will try to modify the code if it's his mistake.

RogerHardiman commented 7 years ago

We need to watch that existing users will have written their code around the incorrect functionality. So we may want some extra enums.

Sent from my Samsung device

-------- Original message -------- From: Sappho notifications@github.com Date: 27/08/2017 11:54 (GMT+00:00) To: saki4510t/UVCCamera UVCCamera@noreply.github.com Cc: Roger Hardiman roger@rjh.org.uk, Author author@noreply.github.com Subject: Re: [saki4510t/UVCCamera] documentation error for NV21 and YUV420 modes (#207)

Then I will try to modify the code if it's his mistake.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/saki4510t/UVCCamera","title":"saki4510t/UVCCamera","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/saki4510t/UVCCamera"}},"updates":{"snippets":[{"icon":"PERSON","message":"@sappho192 in #207: Then I will try to modify the code if it's his mistake."}],"action":{"name":"View Issue","url":"https://github.com/saki4510t/UVCCamera/issues/207#issuecomment-325191142"}}}

wlxyhy commented 3 years ago

I found the same problem, nv21 and 420sp should be changed.
in UVCPreview.cpp case PIXEL_FORMAT_YUV20SP: LOGI("PIXEL_FORMAT_YUV20SP:"); mFrameCallbackFunc = uvc_yuyv2iyuv420SP; callbackPixelBytes = (sz * 3) / 2; break; case PIXEL_FORMAT_NV21: LOGI("PIXEL_FORMAT_NV21:"); mFrameCallbackFunc = uvc_yuyv2yuv420SP; callbackPixelBytes = (sz * 3) / 2; break;

while in frame.c uvc_error_t uvc_yuyv2iyuv420SP(uvc_frame_t *in, uvc_frame_t *out) { ...... for (h = 0; h < hh - 1; h += 2) { uint8_t *y0 = dest + width * h; uint8_t *y1 = y0 + width; const uint8_t *yuv = src + src_width * h; for (w = 0; w < width; w += 4) { *(y0++) = yuv[0]; // y *(y0++) = yuv[2]; // y' *(y0++) = yuv[4]; // y'' *(y0++) = yuv[6]; // y''' *(uv++) = yuv[3]; // v *(uv++) = yuv[1]; // u *(uv++) = yuv[7]; // v *(uv++) = yuv[5]; // u *(y1++) = yuv[src_width+0]; // y on next low *(y1++) = yuv[src_width+2]; // y' on next low *(y1++) = yuv[src_width+4]; // y'' on next low *(y1++) = yuv[src_width+6]; // y''' on next low yuv += 8; // (1pixel=2bytes)x4pixels=8bytes } } 'yyyyvuvu', it's obviously NV21