Since the original post, changed the approach to create the JPEG image - used CIContext instead of VideoToolbox
let colorSpace = CGColorSpace(name: CGColorSpace.sRGB)
let jpeg = ciContext.jpegRepresentation(of: CIImage(cvPixelBuffer: pixelBuffer), colorSpace: colorSpace!)
It was still crashing. Attached is a crash log from using the CIContext approach.
2024-04-30_20-06-22.6123_-0500-fdfd32de964b64f4c327790538b1209b76fb0572.crash
I was able to reproduce the issue locally by using "Address Sanitizer" debug diagnostic setting in Xcode. Looks like the CVPixelBuffer may have some corruption in some cases. In any case, it is clear the issue is nothing to do with VideoToolbox.