It seems that Opencv + FFMPEG is corrupting lossless video frames.
First I establish that the video is lossless with this test
gst-launch-1.0.exe {RAW_IMAGE_SOURCE} ! video/x-raw,width=1280,height=480,format=I420 ! x264enc pass=quant quantizer=0 byte-stream=true cabac=false ! video/x-h264, stream-format=byte-stream ! avdec_h264 ! jpegenc quality=100 ! multifilesink location=frames/image_%06d.jpg
The images correctly replicate very small RGB values (16,16,16) in large regions of the background. However, whenever I replace the multifilesink with an udpsink as below
gst-launch-1.0.exe {RAW_IMAGE_SOURCE} ! video/x-raw,width=1280,height=480,format=I420 ! x264enc pass=quant quantizer=0 byte-stream=true ! video/x-h264, stream-format=byte-stream ! rtph264pay name=pay0 pt=96 ! udpsink host=127.0.0.1 port=6666 sync=false
and try to open it with OpenCV + Python with the SDP "h264rtp.sdp" below
c=IN IP4 127.0.0.1
m=video 6666 RTP/AVP 96
a=rtpmap:96 H264/90000
and this code
url = "h264rtp.sdp"
cap_receive = cv2.VideoCapture(url, cv2.CAP_FFMPEG)
The frames returned by this video capture are different than the images saved by jpegenc. More specifically, the large dark regions go from (16,16,16) and (17,17,17) to (0,0,0)!!!
I am required to provide 100% lossless video... any suggestions?
As mentioned by @Rotem, the format I was passing as a CAPS string was wrong. Correcting the format solved the issue.
As he did not post an answer after a certain amount of time I'll simply leave this here.