NVENC Compress Sub-Frame of Source CUDA Image

I’m trying to create an encoder that will conditionally output areas of a video stream. These areas are always rectangles with width and height divisible by 16, but they do not always have their origin at the top left of the source frame.

How do I tell the nvidia encoder that I want it to start reading from a non-0 offset of the provided CUDA frame? I see that there is an inputPitch in NV_ENC_PIC_PARAMS, but I cannot see any parameters that allow me to move the read origin.

I understand that I could simply copy a cropped portion via a device to device memcpy, but I’m in a very performance constrained environment, so it would be ideal for NVENC to read at an offset.

As an update, I learned that pointer arithmetic on CUdeviceptr is possible host-side, but I can’t seem to figure out how to use that with the encoder.
I could, when the region I’m interested in encoding changes:

  1. Unregister the existing encoder resource
  2. Add an offset to the CUdeviceptr
  3. Re-register the resource using the offset CUdeviceptr

But this would likely be too computationally expensive for my application. It seems like there has to be a way to make this work, as all I’m asking the encoder to do is change the byte that it starts reading from.

Unfortunately the existing NVENCODEAPI doesn’t provide the capability to specify (left, top) and (right, bottom) coordinates for encoding.

With the shipping versions you need to copy the portions to the frame exclusively and then do the encoding.

Thanks,
Ryan Park

I believe that I now have this fully working, using the above mentioned strategy. Fortunately unregistering/reregistering the resource was surprisingly fast based on my tests thus far.