Question

I've got a basic understanding of the format of YUV420p data. I understand it's in planes and that the Y data is basically black & white luma and should be width*height pixels in length.

The U and V planes I believe to be width*height/4 in size for each plane.

So with all that knowledge, I'm trying to scale a yuv420p imag using libswscale. The output image is gray, like I'm missing the U and V planes.

Here's what I'm doing:

  int src_stride[3] = {0, 0, 0};
  src_stride[0] = mInputWidth;
  src_stride[1] = mInputWidth / 4;
  src_stride[2] = mInputWidth / 4;


  const uint8_t *input_planes[3];
  input_planes[0] = input.GetData(); // returns pointer to image data
  input_planes[1] = input_planes[0] + (mInputWidth * mInputHeight);
  input_planes[2] = input_planes[0] + (mInputWidth * mInputHeight) + (mInputWidth * mInputHeight / 4); 


  int scale_rc = sws_scale(mSwsEncodeContext, input_planes,
                       src_stride, 0, mInputHeight, mEncodeAvFrame->data,
                       mEncodeAvFrame->linesize);

Any idea if I'm botching the src_stride or the input_planes?

Was it helpful?

Solution

The code above is correct for scaling YUV420P data. It turns out my data was not YUV420P but NV21 which has the same size but the U and V data are not in different planes, they are in 1 plane and are interleaved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top