Unable to use gstreamer programmaticaly with nvjpegenc and opencv 4.1.1 simultaneously

This may work:

gst-launch-1.0 nvarguscamerasrc num-buffers=1 ! 'video/x-raw(memory:NVMM), width=(int)3280, height=(int)2464, framerate=2/1' ! nvjpegenc ! filesink location=test.jpg -e

I cannot tell how to fix the jpeg lib mismatch with opencv. A solution may be using 2 processes (one gst-launch doing nvjpegenc, and your opencv app) communicating through shmsink/shmsrc.