[GIS] Converting large jp2 files using GDAL

gdalgdal-translate

I have a bunch of jp2 files with size going from 40MB to 1GB and I need to convert them all to GeoTiffs (.tif format). When using gdal_translate for the small files (having the jasper driver to support jp2 files), this works. But when applying this on files with size about 400MB, I get segmentation errors.

gdal_translate input.jp2 output.tif

In another attempt I've used opj_decompress (from the JP2OpenJPEG library) to convert jp2 to tif files, but again resulted in an error.

opj_decompress -i input.jp2 -o output.tif

Is there a way to handle large jp2 files with GDAL (or another library) to convert them to .tif?

Best Answer

Jasper driver is useless for big JPEG2000 files. OpenJPEG driver is OK if source JPEG2000 is tiled, otherwise you will need JP2ECW, JP2KAK, or JP2MrSID driver. Check your drivers with gdalinfo --formats and use --config GDAL_SKIP for skipping the first JP2 drivers from the list for selecting the driver you want to use.

Example output from GDAL compiled with two JP2 drivers:

gdalinfo --formats
...
JP2ECW (rov): ERDAS JPEG2000 (SDK 5.0)
JP2OpenJPEG (rwv): JPEG-2000 driver based on OpenJPEG library

If you wand to use JP2OpenJPEG driver which is the second on the list you must skip the first driver:

gdal_translate -of GTiff input.jp2 output.tif --config GDAL_SKIP JP2ECW