4

We are using FFMPEG in our java application and I am trying to convert a tiff file to jpg but the requirement is to keep the SAME DPI as it has in original tiff file.

I am new to FFMPEG and tried following failed attempts to achieve this:

  1. ffmpeg -y -i test.tif test.jpg: Successfully converted to jpg but DPI has reduced from 300 to 96. (Verified by pressing Right click on image --> properties--> details tab --> horizontal and vertical resolution attributes)
  2. ffmpeg -y -i test.tif -c:v copy test.jpg: Converted to jpg with 300 dpi but actual file format is still tif. It seems like only extension is changed to jpg.
  3. ffmpeg -y -i test.tif -pix_fmt <format> test.gif (tried all 3 supported format:yuvj420p,yuvj422p yuvj444p): Converted to jpg but dpi is changed from 300 to 96.
  4. ffmpeg y -i test.tif -r 1 -q:v <range> test.jpg (tried various range: 1 to 10): Same problem.

  5. Tried -q:v and -qscale options, but it's just changing the width and height of image.

Finally I heard about ImageMagick and problem is solved in first attempt by using following command:

  1. magick convert "test.tif" "test.jpg": converted to jpg and dpi is 300.

Is it possible to achieve the same using FFMPEG. If yes, kindly assist me as I am stuck here for the long time.

0

One thing to realize is that DPI has nothing to do with the data in an image. It is a construct based on output capabilities of hardware. An image has so many individual pixels, for which there is data in the file. The measurement of how many pixels fit in an inch only matters on output on a printer or display on a device. The image data itself has no inherent "size" of pixels. Some image file formats support metadata that can include "DPI," but it is essentially meaningless to the image itself.

The DPI information you are seeing can be arbitrarily assigned by the programs you are using to display the image files. If your paint program says the image is 300 DPI, that might have nothing to do with the data in the file, which might not have a DPI tag. TIFF files can contain metadata tags (that's why the format is "tagged image file format") such as DPI, but it doesn't matter to the image data.

These concepts seem to be especially hard for people to understand, but the fact is a picture element (pixel) does not have a size -- only output devices have DPI measurements. Your requirement to not change the DPI is someone's idea of a requirement to preserve data, I suspect. BTW, since JPEG is a lossy compression scheme, the amount of compression you apply is a lot more important than some arbitrary DPI metadata. You could be destroying these images in compressing them in JPEG format while preserving the DPI label.

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.