2

I want to convert a .jp2 file from the Sentinel 2 project to .tif with gdal. For some bands it works (e.g. B01) and for some bands it always fails (e.g. B04). I use the sentinel public image browser data (e.g this product).

When I run gdal_translate B04.jp2 B04.tif I get the following output:

Input file size is 10980, 10980 0maximum number of samples exceeded (120560400 > 67108864) error: cannot decode code stream ERROR 1: B04.jp2, band 1: IReadBlock failed at X offset 0, Y offset 0

My gdal version is 2.3.0, released 2018/05/04

  • Converting file B04.jp2 works for me with GDAL 2.4.0dev and the OpenJPEG driver. Which JPEG 2000 drivers do you have? Check with gdalinfo --formats. – user30184 Jun 11 '18 at 14:11
  • JPEG -raster- (rwv): JPEG JFIF \n JPEG2000 -raster,vector- (rwv): JPEG-2000 part 1 (ISO/IEC 15444-1), based on Jasper library – user6845507 Jun 11 '18 at 14:15
  • There is no issue in conversion of B04.jp2 to B04.tif using the above command. I used gdal 2.3.0 released 2018/05/04. It worked well. Try opening the data in a viewer. It might be corrupted. – GeoSpatialEarth.in Jun 11 '18 at 14:19
  • 1
    Jasper driver is useless. Find GDAL version that is compiled with some good driver: OpenJPEG, JP2ECW, Kakadu, or JP2MrSID. – user30184 Jun 11 '18 at 14:55
  • I used Homebrew to install GDAL (brew install gdal --with-complete). I don't know how to change the JP2 drivers. I tried the gdal docker image (geodata/gdal) which comes with GDAL 2.3.0dev, released 2017/99/99 and has the JP2OpenJPEG driver. Everything works with that combination. – user6845507 Jun 12 '18 at 8:03
1

There is no issue in conversion of B04.jp2 (you posted in question) to B04.tif using the above command.

I used gdal 2.3.0 released 2018/05/04. It worked well.

Try opening the data in a viewer. It might be corrupted/not fully download.

The error IReadBlock failed generally occurs when the file is not complete.

  • 1
    GDAL version is not important. GDAL is reading and writing data through drivers and for JPEG 2000 there are many drivers available. OpenJPEG driver page gdal.org/frmt_jp2openjpeg.html has links to other JPEG 2000 drivers. Jasper cannot be recommended for handling big geospatial images. Only reason to have it in GDAL is that it is open source. – user30184 Jun 11 '18 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.