Error initializing Nvidia encoder - cv::cudacodec::createVideoWriter

The encoder is more particular about the driver version than the decoder. Check the release notes

If you are using version 12.2 then you need

Linux: Driver version 550.54.14 or higher

If you can’t upgrade the driver then I would build with an earlier verison of the Nvidia Video Codec SDK which is compatible with your driver version.