Trying to write a 3-band JPEG using gdal_merge but keep getting the following error:

Format driver JPEG does not support creation and piecewise writing.
Please select a format that does, such as GTiff (the default) or HFA (Erdas Imagine).

I'm not understanding this as on GDAL's Raster Formats page the Creation column for JPEG says 'Yes.' Additionally, the JPEG File Format help page indicates that it is possible to create JPEG.

Here is my command:

gdal_merge.py -of JPEG -co QUALITY=90 -co EXIF_THUMBNAIL=YES -n 0 -a_nodata 0 -o /path/to/Output.jpg /path/to/inputs/band1.tif /path/to/inputs/band2.tif /path/to/inputs/band3.tif

Why am I recieving this error? I realize that my input bands are 32-bit float but I just figured they would be truncated since JPEG only supports 8-bit. Could this be my problem? I don't want to spend time fixing that if there is something else I'm missing as to why I can't create jpeg.

  • I suppose that the message does not support creation and piecewise writing is correct and the issue is in piecewise writing that gdal_merge is doing. Write output to GeoTIFF and convert it later to whatever you want. However, for most geospatial needs a tiled GeoTIFF with internal JPEG compression is better choice than JPEG. – user30184 Nov 8 '16 at 20:00

Assuming you really do need a JPEG output file, not a GeoTIFF with internal JPEG compression...

The JPEG driver supports the CreateCopy but not the Create method. It's not mentioned specifically in the gdal raster formats list (and probably should be). If you check the command line documentation using gdalinfo you'll see this.

gdalinfo --format JPEG
Format Details:
  Short Name: JPEG
  Supports: CreateCopy() - Create dataset by copying another.

And for geotiff:

gdalinfo --format GTIFF
Format Details:
  Short Name: GTiff
  Supports: Create() - Create writable dataset.
  Supports: CreateCopy() - Create dataset by copying another.

You need to output to a format like tiff then convert to jpeg with gdal_translate.

Alternatively, gdalbuildvrt is a much easier way of doing the merge as you don't need to create an intermediate dataset on disk.

gdalbuildvrt -separate /path/to/Output.vrt /path/to/inputs/band1.tif /path/to/inputs/band2.tif /path/to/inputs/band3.tif
gdal_translate -of JPEG -scale -ot byte /path/to/Output.vrt /path/to/Output.jpg
  • You are right, the error does not come from adding new files into the mosaic because the same error happens also with a singe file gdal_merge.py -of JPEG one.tif out.jpg. – user30184 Nov 9 '16 at 8:17
  • gdalbuildvrt is a good solution. I don't know why i didn't think about that. thanks! – user20408 Nov 17 '16 at 15:17

I'm late to the party and don't have enough reputation to comment on the accepted answer, but I want to add a bonus. You can avoid the two-step process with the intermediate VRT file by using the /vsistdout/ and /vsistdin/ Virtual File Systems and piping the initial command's VRT output to gdal_translate.

gdalwarp -t_srs epsg:3857 -te -8527009.1 4762026.9 -8526856.3 4762179.7 \
-ts 256 256 -of VRT /imagery/big_image.sid /vsistdout/ | \
gdal_translate -of JPEG /vsistdin/ /tiles/vrt-tile.jpg

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.