由taut发布于 2019-12-17 12:15:42(
我们在Java应用程序中使用FFMPEG,并且我尝试将tiff文件转换为jpg,但要求是保持原始tiff文件中的SAME DPI。
我是FFMPEG的新手,并尝试了以下失败的尝试:

  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 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 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.

最后,我听说了ImageMagick,并通过使用以下命令首次尝试解决了问题:

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

是否有可能使用FFMPEG达到相同的效果。如果是的话,请帮我,因为我在这里呆了很长时间。

最佳答案

要意识到的一件事是DPI与图像中的数据无关。它是基于硬件输出功能的构造。图像具有如此多的单个像素,因此文件中包含数据。英寸中适合容纳多少像素的度量仅与打印机或设备上的显示器的输出有关。图像数据本身没有像素的固有“大小”。某些图像文件格式支持可以包含“ DPI”的元数据,但是对于图像本身而言基本上没有任何意义。
您所看到的DPI信息可以由您用来显示图像文件的程序任意分配。如果绘图程序说图像是300 DPI,则可能与文件中的数据无关,后者可能没有DPI标签。 TIFF文件可以包含元数据标签(这就是格式为“带标签的图像文件格式”的原因),例如DPI,但与图像数据无关紧要。
这些概念似乎很难让人理解,但是事实是像素(像素)没有尺寸-只有输出设备才具有DPI测量值。我怀疑您不更改DPI的要求是有人要求保留数据。顺便说一句,由于JPEG是一种有损压缩方案,因此您应用的压缩量比某些任意DPI元数据重要得多。在保留DPI标签的同时,以JPEG格式压缩它们可能会破坏这些图像。

changing DPI

  1. <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> 6 posts • Page **1** of **1** <br /> <br /> <br /> <br /> <br /> <br /> <br /> **ewok251** <br /> <br /> <br /> <br />

changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=36068&sid=27b6881a1dfdad7d1b316364a35faa9a#p36068) by **ewok251** » 2008-05-15T07:17:13-07:00 <br />Hi.

I want to change the DPI of an image, but it doesnt seem to be working.
I don’t want to change the number of pixels, just the size that it’s rendered at, so im using -density not -resample. However:
Same thing happens with ‘convert’ too.

The mogrify must be doing something, because if I load it into the GIMP it says the resolution is 72x72, but previewer on the Mac shows 180x180, and an ‘identify -verbose’ shows 180x180 and no mention of 72x72 anywhere.

Ive tried it on several images from several sources, all the same result. Ive stripped out any profile that might be used by Photoshop just in case.

Am I making some fundamental mistake?

thanks
$ identify -format “%x x %y” img_0359.jpg 180 PixelsPerInch x 180 PixelsPerInch $ mogrify -density 72x72 img_0359.jpg $ identify -format “%x x %y” img_0359.jpg 180 PixelsPerInch x 180 PixelsPerInch
Code: Select all


Top







fmw42

Posts:25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA



Re: changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=36073&sid=27b6881a1dfdad7d1b316364a35faa9a#p36073) by [fmw42](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=9098&sid=27b6881a1dfdad7d1b316364a35faa9a) » 2008-05-15T11:31:38-07:00 <br />It works for me.

convert rose: rose.jpg
identify -format “%x x %y” rose.jpg
72 PixelsPerInch x 72 PixelsPerInch

convert rose.jpg -density 180 rose2.jpg
identify -format “%x x %y” rose2.jpg
180 PixelsPerInch x 180 PixelsPerInch

convert rose2.jpg -density 72 rose3.jpg
identify -format “%x x %y” rose3.jpg
72 PixelsPerInch x 72 PixelsPerInch

I am on IM 6.4.1-2beta Q16-hdri
Fred’s ImageMagick Scripts


Top







anthony

Posts:8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia



Re: changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=36526&sid=27b6881a1dfdad7d1b316364a35faa9a#p36526) by [anthony](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=1663&sid=27b6881a1dfdad7d1b316364a35faa9a) » 2008-06-03T19:47:50-07:00 <br />Your JPG may be using photoshop densitys rather that the 'normal JPEG format density settings.

It also could be your IM is too old.
Anthony Thyssen — Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/


Top







ewok251




Re: changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=36544&sid=27b6881a1dfdad7d1b316364a35faa9a#p36544) by **ewok251** » 2008-06-04T03:50:47-07:00 <br />an update on how I resolved this.. first I think I was just using a too old version of IM, but secondly, Photoshop seems to divide DPI by 10000 for some reason, so for example to get Photoshop to see 300dpi, I needed to do -density 3000000<br /> <br /> <br /> [Top](https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=11255#top) <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> [anthony](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=1663&sid=27b6881a1dfdad7d1b316364a35faa9a) <br /> <br />**Posts:**[8883](https://legacy.imagemagick.org/discourse-server/search.php?author_id=1663&sr=posts&sid=27b6881a1dfdad7d1b316364a35faa9a)<br />**Joined:** 2004-05-31T19:27:03-07:00<br />**Authentication code:** 8675308<br />**Location:** Brisbane, Australia<br /> <br /> <br />

    Re: changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=36566&sid=27b6881a1dfdad7d1b316364a35faa9a#p36566) by [anthony](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=1663&sid=27b6881a1dfdad7d1b316364a35faa9a) » 2008-06-04T22:32:02-07:00 <br />try defining the -units setting as well as -density<br />Anthony Thyssen -- Webmaster for ImageMagick Example Pages<br />[https://imagemagick.org/Usage/](https://imagemagick.org/Usage/)<br /> <br /> <br /> [Top](https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=11255#top) <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> [anthony](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=1663&sid=27b6881a1dfdad7d1b316364a35faa9a) <br /> <br />**Posts:**[8883](https://legacy.imagemagick.org/discourse-server/search.php?author_id=1663&sr=posts&sid=27b6881a1dfdad7d1b316364a35faa9a)<br />**Joined:** 2004-05-31T19:27:03-07:00<br />**Authentication code:** 8675308<br />**Location:** Brisbane, Australia<br /> <br /> <br />

    Re: changing DPI

    1. <br /> <br /> [Post](https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=45133&sid=27b6881a1dfdad7d1b316364a35faa9a#p45133) by [anthony](https://legacy.imagemagick.org/discourse-server/memberlist.php?mode=viewprofile&u=1663&sid=27b6881a1dfdad7d1b316364a35faa9a) » 2009-03-23T16:43:29-07:00 <br />What operation changes the DPI? Neither resize or crop should do this.<br />Anthony Thyssen -- Webmaster for ImageMagick Example Pages<br />[https://imagemagick.org/Usage/](https://imagemagick.org/Usage/)<br /> <br /> <br /> [Top](https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=11255#top) <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> 6 posts • Page **1** of **1** <br />