title: camera2 captured picture - conversion from YUV_420_888 to NV21
body: <p>Via the camera2 API we are receiving an Image object of the format <strong>YUV_420_888</strong>. We are using then the following function for conversion to <strong>NV21</strong>:</p>
  
  <pre><code>private static byte[] YUV_420_888toNV21(Image image) {
      byte[] nv21;
      ByteBuffer yBuffer = image.getPlanes()[0].getBuffer();
      ByteBuffer uBuffer = image.getPlanes()[1].getBuffer();
      ByteBuffer vBuffer = image.getPlanes()[2].getBuffer();
  
      int ySize = yBuffer.remaining();
      int uSize = uBuffer.remaining();
      int vSize = vBuffer.remaining();
  
      nv21 = new byte[ySize + uSize + vSize];
  
      //U and V are swapped
      yBuffer.get(nv21, 0, ySize);
      vBuffer.get(nv21, ySize, vSize);
      uBuffer.get(nv21, ySize + vSize, uSize);
  
      return nv21;
  }
  </code></pre>
  
  <p>While this function works fine with <code>cameraCaptureSessions.setRepeatingRequest</code>, we get a segmentation error in further processing (on the JNI side) when calling <code>cameraCaptureSessions.capture</code>. Both request YUV_420_888 format via ImageReader.</p>
  
  <p>How come the result is different for both function calls while the requested type is the same?</p>
  
  <p><strong>Update:</strong> As mentioned in the comments I get this behaviour because of different image sizes (much larger dimension for the capture request). But our further processing operations on the JNI side are the same  for both requests and don't depend on image dimensions (only on the aspect ratio, which is in both cases the same).</p>