How to encode with CUDA?

When testing the maxine demo apps, I realized the encoding with Opencv is using just plain x264 from the local ffmpeg build installed on Ubuntu. I have my own Ffmpeg build that can encode with CUDA via hevc_nvenc and h264_nvenc. Is it possible to change the fourcc code on the Opencv code to encode on hardware instead of inneficient processor encoding ? Thanks