<div dir="ltr"><div>Hello</div><div><br></div><div>I'm trying to convert NV21 image to YUV420P, </div><div>for x264 encoder to encode it.</div><div><br></div><div>my code is:</div><div><br></div><div><div>static int scale(char* lin, x264_picture_t* pic,</div><div> int in_width, int in_height, int out_width, int out_height){</div><div>  if(convertCtx == NULL){</div><div>    convertCtx = sws_getContext(in_width, in_height, PIX_FMT_NV21, </div><div><span class="" style="white-space:pre">                         </span>out_width, out_height, PIX_FMT_YUV420P,</div><div><span class="" style="white-space:pre">                            </span>SWS_FAST_BILINEAR, NULL, NULL, NULL);</div><div>  }</div><div><br></div><div>  AVPicture src;<br></div><div>  avpicture_fill(&src, lin, PIX_FMT_NV21, in_width, in_height);</div><div>  int h = sws_scale(convertCtx, </div><div><span class="" style="white-space:pre">            </span>    (const uint8_t **)(&lin), src.linesize,</div><div><span class="" style="white-space:pre">          </span>    0, in_height, </div><div><span class="" style="white-space:pre">              </span>    (uint8_t * const*)(pic->img.plane), pic->img.i_stride);</div><div>  return h;</div><div>}</div></div><div><br></div><div>the images are recorded from android camera with such code:</div><div>params = mCamera.getParameters();</div><div>params.setPreviewFormat(ImageFormat.NV21);<br></div><div>mCamera.setParameters(params);</div><div><br></div><div>And I will get the video buffer from onPreviewFrame callback.</div><div><br></div><div>the code works well if the src image is PIX_FMT_YUYV422, </div><div>with android camera set to </div><div>params.setPreviewFormat(ImageFormat.YUY2);<br></div><div><br></div><div>but when I try to convert NV21 images on some other devices,</div><div>the image broke. the image looks like its purple and green part </div><div>of the pixels are separated.</div><div><br></div><div>please help me with this convert code. thank you.</div><br clear="all"><div><div dir="ltr">Thanks,<div>Peter</div></div></div>
</div>