Multple ExifIFD groups in multi-part/page TIFF?

Started by torarnv, September 21, 2014, 06:23:16 PM

Previous topic - Next topic

torarnv

When creating a multi-part TIFF I get the following output from exiftool -s -a -e -G5


[ExifTool]      ExifToolVersion                 : 9.57
[System]        FileName                        : bar.tif
[System]        Directory                       : .
[System]        FileSize                        : 3.5 MB
[System]        FileModifyDate                  : 2014:09:22 00:16:12+02:00
[System]        FileAccessDate                  : 2014:09:22 00:17:21+02:00
[System]        FileInodeChangeDate             : 2014:09:22 00:16:12+02:00
[System]        FilePermissions                 : rw-r--r--
[TIFF]          FileType                        : TIFF
[TIFF]          MIMEType                        : image/tiff
[TIFF]          ExifByteOrder                   : Little-endian (Intel, II)
[TIFF-IFD0]     ImageWidth                      : 3264
[TIFF-IFD0]     ImageHeight                     : 2448
[TIFF-IFD0]     BitsPerSample                   : 8 8 8
[TIFF-IFD0]     Compression                     : JPEG
[TIFF-IFD0]     PhotometricInterpretation       : YCbCr
[TIFF-IFD0]     StripOffsets                    : 8
[TIFF-IFD0]     Orientation                     : Rotate 90 CW
[TIFF-IFD0]     SamplesPerPixel                 : 3
[TIFF-IFD0]     RowsPerStrip                    : 2448
[TIFF-IFD0]     StripByteCounts                 : 1849906
[TIFF-IFD0]     PlanarConfiguration             : Chunky
[TIFF-IFD1]     ImageWidth                      : 3264
[TIFF-IFD1]     ImageHeight                     : 2448
[TIFF-IFD1]     BitsPerSample                   : 8 8 8
[TIFF-IFD1]     Compression                     : JPEG
[TIFF-IFD1]     PhotometricInterpretation       : YCbCr
[TIFF-IFD1]     StripOffsets                    : 1850058
[TIFF-IFD1]     Orientation                     : Rotate 90 CW
[TIFF-IFD1]     SamplesPerPixel                 : 3
[TIFF-IFD1]     RowsPerStrip                    : 2448
[TIFF-IFD1]     StripByteCounts                 : 1849906
[TIFF-IFD1]     PlanarConfiguration             : Chunky


Is there a way to copy the ExifIFD group from another photo to each of the individual IFDs? So that I will have both [TIFF-IFD0-ExifIFD] and [TIFF-IFD1-ExifIFD]

Doing "-all<all" seems to write the exif to the "root" of the TIFF file, and it only shows up on one of the two pages in OSX Preview.

I tried using -TagsFromFile with "-IFD0:all<all" and "-IFD1:all<all" to set the individual exif info, which seems to work, but the full Exif does then not show up in Preview, only a subset of it.

Not really sure if what I'm doing is supported, so any guidance is appreciated :)


Phil Harvey

No, you can't do that.  This usage is not mentioned in the EXIF specification (to my knowledge), and ExifTool won't create an ExifIFD anywhere except in IFD0.  I'm not sure if this is legal, and don't recall ever having seen this in a TIFF image.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

torarnv

Thanks for your quick feedback!

Looking at the spec [1], section 4.6.3, it would seem like each IFD could have its own Exif IFD pointer (tag 34665), but perhaps the format doesn't allow multiple ExifIFDs? A suppose technically it would at least be possible to have the single ExifIFD shared between every IFD by each IFD having a unique Exif IFD pointer tag with the right offset?

tor arne

[1] http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf

torarnv

Using libtiff I was successfull in writing a multi-page TIFF with multiple EXIF directories as well:

[ExifTool]      ExifToolVersion                 : 9.57
[System]        FileName                        : bar.tif
[System]        Directory                       : .
[System]        FileSize                        : 3.5 MB
[System]        FileModifyDate                  : 2014:09:22 03:26:08+02:00
[System]        FileAccessDate                  : 2014:09:22 03:26:12+02:00
[System]        FileInodeChangeDate             : 2014:09:22 03:26:08+02:00
[System]        FilePermissions                 : rw-r--r--
[TIFF]          FileType                        : TIFF
[TIFF]          MIMEType                        : image/tiff
[TIFF]          ExifByteOrder                   : Little-endian (Intel, II)
[TIFF-IFD0]     ImageWidth                      : 2448
[TIFF-IFD0]     ImageHeight                     : 3264
[TIFF-IFD0]     BitsPerSample                   : 8 8 8
[TIFF-IFD0]     Compression                     : JPEG
[TIFF-IFD0]     PhotometricInterpretation       : YCbCr
[TIFF-IFD0]     StripOffsets                    : 8
[TIFF-IFD0]     SamplesPerPixel                 : 3
[TIFF-IFD0]     RowsPerStrip                    : 3264
[TIFF-IFD0]     StripByteCounts                 : 1860367
[TIFF-IFD0]     PlanarConfiguration             : Chunky
[TIFF-IFD0-ExifIFD] FNumber                     : 2.8
[TIFF-IFD1]     ImageWidth                      : 2448
[TIFF-IFD1]     ImageHeight                     : 3264
[TIFF-IFD1]     BitsPerSample                   : 8 8 8
[TIFF-IFD1]     Compression                     : JPEG
[TIFF-IFD1]     PhotometricInterpretation       : YCbCr
[TIFF-IFD1]     StripOffsets                    : 1860678
[TIFF-IFD1]     SamplesPerPixel                 : 3
[TIFF-IFD1]     RowsPerStrip                    : 3264
[TIFF-IFD1]     StripByteCounts                 : 1860367
[TIFF-IFD1]     PlanarConfiguration             : Chunky
[TIFF-IFD1-ExifIFD] FNumber                     : 4.5
[Composite]     Aperture                        : 4.5
[Composite]     ImageSize                       : 2448x3264



Interestingly, if I then use -TagsFromFile "-all<all" on the output file, ExifTool will fill in both ExifIFDs with the same info, so it seems to at least iterate them all. Viewing the resulting file in OSX's Preview app shows the individual Exif infos in the information browser when you switch between images.

So from the looks of it, since TIFF supports multiple IFDs (of which the Exif IFD is just another directory), and the default (image) IFD has a per-IFD-tag to point to its Exif IFD, it seems like this is a valid usecase. Not sure how hard it would be to implement in ExifTool though :/

If I generate the multiple Exif IFDs myself, does ExifTool have syntax to reference them individually so I can update or append the dictionary?

Phil Harvey

Thanks for looking into this.

Could you post a sample multi-page tiff with multiple ExifIFD's so I can have something to play with?  Interesting that this hasn't ever come up before.

Currently, ExifTool doesn't have any way to distinguish between the information stored in different ExifIFD's, either while reading, or writing.  I could potentially use the family 3 group (document number) to distinguish this, although currently the document number can't be specified when writing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

torarnv

Hey! Sorry for the delay, you can find a test TIFF file here:

  https://www.dropbox.com/s/zu9o6njrn2s2pj1/multiple-exififds-test.tiff?dl=0

The file has five TIFF pages created from JPEG files (by writing each image as a single strip). Each image IFD has a corresponding ExifIFD, with a single F-Stop Exif tag which increases by one for each page so you can tell them apart.

A tiffinfo dump of the image gives:


TIFF Directory at offset 0x5b854 (374868)
  Image Width: 1280 Image Length: 1000
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: min-is-black
  Samples/Pixel: 1
  Rows/Strip: 1000
  Planar Configuration: single image plane
  EXIFIFDOffset: 0x5b83a
TIFF Directory at offset 0x5b83a (374842)
  FNumber: 0.000000
TIFF Directory at offset 0x923a2 (598946)
  Image Width: 1280 Image Length: 867
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 1, 1
  Samples/Pixel: 3
  Rows/Strip: 867
  Planar Configuration: single image plane
  EXIFIFDOffset: 0x92388
TIFF Directory at offset 0x92388 (598920)
  FNumber: 1.000000
TIFF Directory at offset 0x10119a (1053082)
  Image Width: 1280 Image Length: 873
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 1, 1
  Samples/Pixel: 3
  Rows/Strip: 873
  Planar Configuration: single image plane
  EXIFIFDOffset: 0x101180
TIFF Directory at offset 0x101180 (1053056)
  FNumber: 2.000000
TIFF Directory at offset 0x138676 (1279606)
  Image Width: 1280 Image Length: 864
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 1, 1
  Samples/Pixel: 3
  Rows/Strip: 864
  Planar Configuration: single image plane
  EXIFIFDOffset: 0x13865c
TIFF Directory at offset 0x13865c (1279580)
  FNumber: 3.000000
TIFF Directory at offset 0x15a038 (1417272)
  Image Width: 1221 Image Length: 1000
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Rows/Strip: 1000
  Planar Configuration: single image plane
  EXIFIFDOffset: 0x15a01e
TIFF Directory at offset 0x15a01e (1417246)
  FNumber: 4.000000


The program used to generate the test file can be found here:

  https://gist.github.com/torarnv/723397a0590663d20669

(Note that it requires a local copy of libtiff, so that it can fix a backwards-compability issue with recent versions of libtiff. This is unrelated to the multiple-ExifIFDs, and just a workaround so that the Exif data will show up in OSX Preview which only supports the older way of defining ExifIFD pointers).

Hope this helps!

Phil Harvey

Thanks for the sample.  I'll play around with it when I get a chance.

Quote from: torarnv on September 25, 2014, 07:58:17 PM
which only supports the older way of defining ExifIFD pointers).

Older way?  I wasn't aware of any change to the way ExifIFD pointers are used.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

torarnv

Quote from: Phil Harvey on September 26, 2014, 07:06:33 AM
Older way?  I wasn't aware of any change to the way ExifIFD pointers are used.

They changed the datatype of the pointer in libtiff 4.0.0 (I think) from TIFF_LONG to TIFF_IFD/TIFF_IFD8, presumably as a way forward for BigTIFF.

ExifTool seems to read both types, but will write LONG. Apple's OSX Preview application only understands LONG (from what I can tell).

See eg. http://www.asmail.be/msg0054967491.html

Phil Harvey

Ah, right.  Yes, using the TIFF_IFD format type would break a lot of readers.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).