ExifTool Forum

ExifTool => Newbies => Topic started by: David Beroff on August 13, 2018, 04:42:22 AM

Title: Retain duplicate tags
Post by: David Beroff on August 13, 2018, 04:42:22 AM
Our goal, (as part of a much larger process), is to remove as much metadata as possible from a target file, and replace it with as much metadata as possible from a reference file, i.e., the original photograph.  (The really short answer as to "why" is that some of the steps in our process are mangling this data, and rather than trying to repair the data or the programs, it'll be far easier to simply use the original metadata, especially given that the mangling steps aren't changing very much.)

We've gotten almost what we want by using:
exiftool -all= -tagsfromfile reference.jpg -all:all target.jpg

There are a few tags with the same name in the original metadata which only get copied once to the target, and we'd prefer that any duplicate tags get copied duplicate times.  e.g., The "Image Width" tag exists in both the "File" and "IFD0" groups, but only gets copied once.

We've tried various approaches to adding the -a option, including:
exiftool -a -all= -tagsfromfile reference.jpg -all:all target.jpg
exiftool -all= -a -tagsfromfile reference.jpg -all:all target.jpg
exiftool -all= -tagsfromfile reference.jpg -a -all:all target.jpg
exiftool -all= -tagsfromfile reference.jpg -all:all -a target.jpg

...all to no avail.

First post here.  Yes, we have both read the Application Documentation (https://www.exiftool.org/exiftool_pod.html (https://www.exiftool.org/exiftool_pod.html)), the FAQ number 3 (https://exiftool.org/faq.html#Q3 (https://exiftool.org/faq.html#Q3)), and tried searching this forum.  Obviously we're missing something pretty basic, and apologize in advance for this.

Thank you in advance for your kind help!
Title: Re: Retain duplicate tags
Post by: StarGeek on August 13, 2018, 05:51:59 AM
The ImageWidth/Height tags in the File section are not tags that can be copied.  They are actual properties of the file itself.  Most of the FILE section of metadata are like that, properties of the file itself.

As to why the EXIF:ImageWidth isn't being copied, I'm not sure.  Are there no error messages returned?  What are some of the other tags that aren't being copied?  If they are also EXIF tags, it might be something is writing the EXIF block incorrectly.

Title: Re: Retain duplicate tags
Post by: Phil Harvey on August 13, 2018, 08:45:52 AM
ExifImageWidth/Height are marked as "unsafe" so they must be copied explicitly.

- Phil
Title: Re: Retain duplicate tags
Post by: David Beroff on August 13, 2018, 11:16:54 AM
I see; thank you, both!  So perhaps there aren't any actual duplicate tags, then.  Still, where should we place the -a parameter, in case we do have duplicates in the future?

No, there were no error messages.

So, any differences within the System and File groups are to be expected; that's fine, then.

Since @Phil is saying that IFD0 > Image Width/Height shouldn't be copied, I will trust that at face value.

The other observed differences were as follows; I have no idea as far as consequences, (if any).  I'm simply being thorough here, and not complaining.

The entire ExifIFD group was not copied over.

IFD0 > X/Y Resolution and Resolution Unit appear to have "bled through", i.e., retained and not deleted from the original target file.

IFD0 > Y Cb Cr Positioning: Centered was added.

GPS > GPS Version ID: 2.3.0.0 was added.

XMP-x > XMP Toolkit was changed from RICOH THETA S Ver1.90 to Image::ExifTool 11.07.


These are the commands I used for this example:
exiftool -a -all= -tagsfromfile r1.jpg -all:all f1.jpg
exiftool -a -u -g1 r1.jpg >r1.txt
exiftool -a -u -g1 f1.jpg >f1.txt
exiftool -a -u -g1 f1_orig.jpg >f1_orig.txt


I have attached the three text files.  I'd be happy to share the two original graphic files; even though they met the stated restrictions, I wasn't able to attach them here, so I didn't.
Title: Re: Retain duplicate tags
Post by: Phil Harvey on August 13, 2018, 11:32:22 AM
Quote from: David Beroff on August 13, 2018, 11:16:54 AM
Still, where should we place the -a parameter, in case we do have duplicates in the future?

The -a option has no effect on the output file when writing.

QuoteSince @Phil is saying that IFD0 > Image Width/Height shouldn't be copied, I will trust that at face value.

It is safe to copy if you know that the image dimensions are the same.  But in general, this is what should be done:

exiftool -all= -tagsfromfile r1.jpg -all:all -tagsfromfile @ "-exifimagewidth<imagewidth" "-exifimageheight<imageheight" f1.jpg

QuoteThe entire ExifIFD group was not copied over.

I don't understand this.  Any tags that are not marked as Unsafe should be copied with this command.  FlashpixVersion, ExifVersion and ColorSpace should all be copied.

QuoteIFD0 > X/Y Resolution and Resolution Unit appear to have "bled through", i.e., retained and not deleted from the original target file.

These are mandatory tags, so they will generated automatically if not written.  But since they exist in the source, they will be copied.

QuoteIFD0 > Y Cb Cr Positioning: Centered was added.

GPS > GPS Version ID: 2.3.0.0 was added.

See the tag name documentation.  These are mandatory tags too.

QuoteXMP-x > XMP Toolkit was changed from RICOH THETA S Ver1.90 to Image::ExifTool 11.07.

You can copy this explicitly, but the default behaviour is to write the ExifTool version here.  This default is the same as the behaviour of all other XMP writers (except they write their own version).  ExifTool is the only XMP editor I know that allows you to change this.

You can mail me the original file if you want me to test this out.  (philharvey66 at gmail.com)

- Phil
Title: Re: Retain duplicate tags
Post by: David Beroff on August 13, 2018, 11:48:56 AM
Sent.  Thank you very much, @Phil!
Title: Re: Retain duplicate tags
Post by: Phil Harvey on August 13, 2018, 12:10:22 PM
OK.  The ExifIFD entries from r1.jpg weren't copied because they shouldn't be there.  Also, there are many entries in IFD0 of r1.jpg that should be in ExifIFD (along with many other problems).

> exiftool r1.jpg -validate -warning -a
Validate                        : 39 Warnings (6 minor)
Warning                         : Wrong IFD for 0x829a ExposureTime (should be ExifIFD not IFD0)
Warning                         : Non-standard format (rational64s) for IFD0 0x829a ExposureTime
Warning                         : Entries in IFD0 are out of order
Warning                         : Tag ID 0x0110 Model out of sequence in IFD0
Warning                         : Tag ID 0x0100 ImageWidth out of sequence in IFD0
Warning                         : Wrong IFD for 0x8822 ExposureProgram (should be ExifIFD not IFD0)
Warning                         : Non-standard format (int16s) for IFD0 0x8822 ExposureProgram
Warning                         : Wrong IFD for 0x829d FNumber (should be ExifIFD not IFD0)
Warning                         : Non-standard format (rational64s) for IFD0 0x829d FNumber
Warning                         : Tag ID 0x829d FNumber out of sequence in IFD0
Warning                         : Wrong IFD for 0xa403 WhiteBalance (should be ExifIFD not IFD0)
Warning                         : Wrong IFD for 0x9209 Flash (should be ExifIFD not IFD0)
Warning                         : Tag ID 0x9209 Flash out of sequence in IFD0
Warning                         : Wrong IFD for 0x9004 CreateDate (should be ExifIFD not IFD0)
Warning                         : Tag ID 0x9004 CreateDate out of sequence in IFD0
Warning                         : Tag ID 0x010f Make out of sequence in IFD0
Warning                         : Wrong IFD for 0x8827 ISO (should be ExifIFD not IFD0)
Warning                         : Non-standard format (int16s) for IFD0 0x8827 ISO
Warning                         : Wrong IFD for 0x920a FocalLength (should be ExifIFD not IFD0)
Warning                         : Wrong IFD for 0x9208 LightSource (should be ExifIFD not IFD0)
Warning                         : Tag ID 0x9208 LightSource out of sequence in IFD0
Warning                         : Tag ID 0x0112 Orientation out of sequence in IFD0
Warning                         : Wrong IFD for 0x9207 MeteringMode (should be ExifIFD not IFD0)
Warning                         : Tag ID 0x0101 ImageHeight out of sequence in IFD0
Warning                         : Entries in GPS are out of order
Warning                         : Tag ID 0x0001 GPSLatitudeRef out of sequence in GPS
Warning                         : Tag ID 0x8769 ExifOffset out of sequence in IFD0
Warning                         : Missing required JPEG ExifIFD tag 0x9000 ExifVersion
Warning                         : Missing required JPEG ExifIFD tag 0x9101 ComponentsConfiguration
Warning                         : Missing required JPEG ExifIFD tag 0xa000 FlashpixVersion
Warning                         : Missing required JPEG ExifIFD tag 0xa001 ColorSpace
Warning                         : Missing required JPEG ExifIFD tag 0xa002 ExifImageWidth
Warning                         : Missing required JPEG ExifIFD tag 0xa003 ExifImageHeight
Warning                         : [minor] IFD0 tag 0x0100 ImageWidth is not allowed in JPEG
Warning                         : [minor] IFD0 tag 0x0101 ImageHeight is not allowed in JPEG
Warning                         : [minor] Missing required JPEG IFD0 tag 0x011a XResolution
Warning                         : [minor] Missing required JPEG IFD0 tag 0x011b YResolution
Warning                         : [minor] Missing required JPEG IFD0 tag 0x0128 ResolutionUnit
Warning                         : [minor] Missing required JPEG IFD0 tag 0x0213 YCbCrPositioning


For this particular image, you are much better to let ExifTool decide where the metadata should go by using -all instead of -all:all:

> exiftool -all= -tagsfromfile r1.jpg -all -tagsfromfile @ "-exifimagewidth<imagewidth" "-exifimageheight<imageheight" f1.jpg
    1 image files updated
> exiftool f1.jpg -validate -warning -a
Validate                        : OK


- Phil
Title: Re: Retain duplicate tags
Post by: David Beroff on August 13, 2018, 12:41:26 PM
Thank you, @Phil.  I'll experiment with that, but I'm getting the feeling that it may defeat my overall purpose.  Y'see, the whole reason why I'm doing this in the first place is that there's some issue with the Google Street View app.  It's able to read the location, time, camera data, etc., from the original (reference) photographs just fine, presumably with the "questionable" metadata that you found.  But when the files are edited (with GIMP and FastStone) and then imported to the Street View app, it can't seem to read the metadata at all, and certain key data points need to be (re-)set manually, at a considerable time cost, (when considering hundreds of pictures).  I was advised that EXIF Fixer (http://panoramaphotographer.com/software/exiffixer/) could, well, fix this, except that I simply cannot get it to work.  Since I think that software uses ExifTool under the hood, I figured I'd just try using that directly.  :)  My experimentation so far finds that, by copying the prior metadata to the edited files, I'm now once again able to get the Street View app to see the location, etc., correctly, on the edited files.  My point here is that, by cleaning up the data, I might possibly trigger the problem again, and defeat the whole purpose of grabbing the old metadata.  I'll play with it to test these ideas, although it'll likely take a few days. 

Thanks again!
Title: Re: Retain duplicate tags
Post by: Phil Harvey on August 13, 2018, 01:21:40 PM
OK then.

If you want to copy the EXIF verbatim with all the errors, etc, overwriting the existing EXIF in the file, then ExifTool can do that too:

exiftool -tagsfromfile r1.jpg -exif f1.jpg

- Phil