basically what the topic says, started after updating the cuda toolkit with nvjpeg 12.3.5.92
minimal example:
#include <opencv2/cudaarithm.hpp>
#include <nvjpeg.h>
#include <stdexcept>
#include <cstring>
#include <iostream>
#include <fstream>
#include <string>
inline void nvjpegCheck(nvjpegStatus_t status, const char* msg)
{
if (status != NVJPEG_STATUS_SUCCESS) {
throw std::runtime_error(std::string("nvJPEG error: ") + msg + " (" + std::to_string(status) + ")");
}
}
int main(int argc, char* argv[]) {
try {
cudaSetDevice(0);
cudaFree(0); // forces context creation
cudaStream_t m_stream;
// All these are created in the constructor and destroyed in the destructor
nvjpegHandle_t m_nvjpegHandle = NULL;
nvjpegJpegState_t m_jpegState = NULL;
nvjpegEncoderState_t m_encoderState = NULL;
nvjpegEncoderParams_t m_encoderParams = NULL;
// Initialize CUDA stream
cudaStreamCreate(&m_stream);
// 1. Create nvJPEG handle with custom allocator
nvjpegCheck(
nvjpegCreateSimple(&m_nvjpegHandle),
"nvjpegCreate"
);
}
catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
}