{"id":28000,"library":"nvidia-nvjpeg2k-cu12","title":"NVIDIA nvJPEG2000 CUDA 12","description":"NVIDIA native runtime libraries for JPEG 2000 encoding and decoding using GPU acceleration via CUDA 12. The current version is 0.10.0.49, requires Python >=3. It provides a Python wrapper around the nvJPEG2000 library. Release cadence is linked to NVIDIA driver updates.","status":"active","version":"0.10.0.49","language":"python","source_language":"en","source_url":"https://github.com/NVIDIA/nvJPEG2K","tags":["nvidia","jpeg2000","cuda","gpu","image-processing","encoding","decoding"],"install":[{"cmd":"pip install nvidia-nvjpeg2k-cu12","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for CUDA context management and device handling","package":"cuda-python","optional":false},{"reason":"Used for array conversion when decoding/encoding image data","package":"numpy","optional":false}],"imports":[{"note":"Top-level import fails; must import from nvidia subpackage.","wrong":"import nvjpeg2k","symbol":"nvjpeg2k","correct":"from nvidia import nvjpeg2k"},{"note":"Wrong module path: omit 'nvidia.' prefix.","wrong":"from nvjpeg2k import Jpeg2kDecoder","symbol":"Jpeg2kDecoder","correct":"from nvidia.nvjpeg2k import Jpeg2kDecoder"},{"note":"Correct import path.","wrong":null,"symbol":"Jpeg2kEncoder","correct":"from nvidia.nvjpeg2k import Jpeg2kEncoder"}],"quickstart":{"code":"import numpy as np\nfrom nvidia import nvjpeg2k\nfrom nvidia.nvjpeg2k import Jpeg2kDecoder, Jpeg2kEncoder\n\n# Decode a JPEG2000 file\nwith open('input.j2k', 'rb') as f:\n    compressed_data = f.read()\n\ndecoder = Jpeg2kDecoder()\ndecoded = decoder.decode(compressed_data)\nprint(f\"Decoded shape: {decoded.shape}, dtype: {decoded.dtype}\")\n\n# Encode an image (e.g., random grayscale)\nimage = np.random.randint(0, 256, (256, 256), dtype=np.uint8)\nencoder = Jpeg2kEncoder()\ncompressed = encoder.encode(image, quality=95)\nprint(f\"Compressed size: {len(compressed)} bytes\")","lang":"python","description":"Demonstrates basic JPEG2000 decode and encode operations using numpy arrays."},"warnings":[{"fix":"Verify with `nvidia-smi` that CUDA version >=12.0 and a supported GPU are present.","message":"Ensure you have a compatible NVIDIA GPU and CUDA 12 driver installed. The library does not include the CUDA driver; it expects a system-wide installation.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `from nvidia import nvjpeg2k` instead of `import nvjpeg2k`.","message":"The import path changed from `import nvjpeg2k` (older versions) to `from nvidia import nvjpeg2k` starting with the nvidia-nvjpeg2k-cu12 package. Direct top-level import will raise ModuleNotFoundError.","severity":"breaking","affected_versions":"0.10.0.x"},{"fix":"Always read file as binary (`open(path, 'rb').read()`) or use bytes object.","message":"The library expects compressed data as bytes for decoding. Passing a numpy array or file handle without reading binary will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Wrap decoder usage in `with Jpeg2kDecoder() as decoder:` if available; otherwise call `decoder.destroy()` after use.","message":"Direct use of `nvjpeg2k.Jpeg2kDecoder` without context manager might cause resource leaks in long-running applications. Consider using context managers or explicit `destroy()`.","severity":"deprecated","affected_versions":"0.10.0.x"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use `from nvidia import nvjpeg2k` or `from nvidia.nvjpeg2k import Jpeg2kDecoder`.","cause":"Importing without the 'nvidia' prefix.","error":"ModuleNotFoundError: No module named 'nvjpeg2k'"},{"fix":"Ensure image is a numpy array of uint8, uint16, or float32, and dimensions are multiples of 1 (check encoder docs for specific constraints). For quality, use integer 0-100.","cause":"Invalid image dimensions or quality parameters (e.g., non-integer quality, or image not on GPU memory when required).","error":"RuntimeError: nvJPEG2K error: Invalid parameter value"},{"fix":"Reduce image size or use a GPU with more memory. Alternatively, decode in strips if supported.","cause":"Image resolution too high for available GPU memory.","error":"RuntimeError: nvJPEG2K error: Insufficient memory"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}