Re: Issue with libyuv::ConvertToI420 on Android?

203 views
Skip to first unread message

Frank Barchard

unread,
May 28, 2015, 11:33:28 PM5/28/15
to discuss-libyuv
Here is the function API for reference:

int ConvertToI420(const uint8* src_frame, size_t src_size,
                  uint8* dst_y, int dst_stride_y,
                  uint8* dst_u, int dst_stride_u,
                  uint8* dst_v, int dst_stride_v,
                  int crop_x, int crop_y,
                  int src_width, int src_height,
                  int crop_width, int crop_height,
                  enum RotationMode rotation,
                  uint32 format);

In rotated mode, assuming the capturer still tells you 175 x 144, thats what you'd pass for src_width and height as well as crop_width and height.
Its usually the stride where people go wrong.   I'd suggest creating a variable with the destination width and height.  Which is the same as source width and height for land scape, but swapped in portrait mode.

 int retVal = libyuv::ConvertToI420(src_frame, src_size,
              pDstY, destWidth,
              pDstU, (destWidth/2),
              pDstV, (destWidth/2),
              0, 0,
              sourceWidth, sourceHeight,
              sourceWidth, sourceHeight,
              mode,
              format);

If you know for sure its NV12, you can call the lower level function:

// Rotate NV12 input and store in I420.
LIBYUV_API
int NV12ToI420Rotate(const uint8* src_y, int src_stride_y,
                     const uint8* src_uv, int src_stride_uv,
                     uint8* dst_y, int dst_stride_y,
                     uint8* dst_u, int dst_stride_u,
                     uint8* dst_v, int dst_stride_v,
                     int src_width, int src_height, enum RotationMode mode);
ConvertToI420 assumes the entire source image is contiguous memory, but the NV12ToI420Rotate does not.

src_width

On Wed, May 20, 2015 at 10:39 PM, Mohamad Azhar Inamdar <inamdar.mo...@gmail.com> wrote:

I have an onPreviewFrame callback set up. This gets a byte[] with NV21 data in it. I have set the preview size to 176*144. When device is held in landscape mode, byte[] with 176*144 dimensions is perfect but when device is held in portrait mode I still get byte[] with the same dimensions.

I want to rotate the byte[] by 90 degrees and obtain byte[] with dimensions 144*176. For this am trying to use ConvertToI420 from libyuv.

I have compiled libyuv and able to call libyuv::ConvertToI420 method but the resulting I420 that I get is all messed up in terms of color and showing lines and all..... however the dimensions that I get are now 144*176.

The code snippet am using is as follows:-

    //sourceWidth = 176 and sourceHeight = 144  
    unsigned char I420M = new unsigned char[(int)(sourceWidth*sourceHeight*1.5)];

    unsigned int YSize = sourceWidth * sourceHeight;
    // yuvPtr is the NV21 data passed from onPreviewCallback (from JAVA layer)
    const uint8* src_frame = const_cast<const uint8*>(yuvPtr);
    size_t src_size = YSize;

    uint8* pDstY = I420M;
    uint8* pDstU = I420M + YSize;
    uint8* pDstV = I420M + (YSize/4);

    libyuv::RotationMode mode;
    if(landscapeLeft){
        mode = libyuv::kRotate90;
    }else{
        mode = libyuv::kRotate270;
    }


    uint32 format = libyuv::FOURCC_NV21;
    int retVal = libyuv::ConvertToI420(src_frame, src_size,
              pDstY, sourceHeight,
              pDstU, (sourceHeight/2),
              pDstV, (sourceHeight/2),
              0, 0,
              sourceWidth, sourceHeight,
              sourceWidth, sourceHeight,
              mode,
              format);

Output I420 obtained (in I420M above) after ConvertToI420.
A single frame from the I420 obtained.

Please someone could point me where am going wrong.

--
You received this message because you are subscribed to the Google Groups "discuss-libyuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-libyu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages