RGB to NV12

Hi all!
In npp there is the function


, which converts from NV12 to RGB, but as far as I can tell, there is no RGB to NV12 conversion, but I am missing something?
NV12 is YUV with the UV plane interlaced into one, but all the color conversions in npp send RGB into 3 planes instead of 2.
Please let me know if there is an easy way to convert RGB into NV12.

There isn’t a direct conversion, currently, in NPP as far as I know.

Possibly the closest option would be to use nppiRGBToYUV420_8u_C3P3R, and then to pack the resultant U,V planes. You could pack the U, V planes with a simple CUDA kernel, something like this:

template <typename T>
__global__ void pack_uv(T * __restrict__ u, T * __restrict__ v, T * __restrict__ uv, const int w, const int h, const int pitch_uv, const int pitch_u, const int pitch_v){

  int idx = threadIdx.x+blockDim.x*blockIdx.x;
  int idy = threadIdx.y+blockDim.y*blockIdx.y;
  if ((idx < w) && (idy < h)){
    T *o  = (T *)(((char *)uv) + idy*pitch_uv);
    T *iu = (T *)(((char *)u)  + idy*pitch_u);
    T *iv = (T *)(((char *)v)  + idy*pitch_v);
    int idx2 = idx >> 1;
    o[idx] = (idx&1)?iv[idx2]:iu[idx2];}

Thanks Robert,
Answer is awesome, also I have learned a new trick (idx&1), thanks again :)