Wrong message in case of conditional replace

Started by herb, May 08, 2023, 07:16:42 AM

Previous topic - Next topic

herb

Hello Phil,

I played with the new feature introduced with version 12.60: replace option -addTagsFromFile

I tested with version 12.62 on Windows 10 the following scenarios - conditionally replace value of a single tag (in my case -xmp-dc:Identifier)
using string-values and/or also variables for both old- and new-value.

In case of using a tag-variable for old-value and/or new-value I have not seen any strange behaviour.
BUT in case of using strings (no variables) I received output messages which I did not expect.
See the following commands:
exiftool.exe -xmp-dc:identifier=ident -usercomment=comment test.jpg
    1 image files updated

exiftool.exe -xmp-dc:all test.jpg
Identifier                      : ident

exiftool.exe -tagsfromfile @ -xmp-dc:identifier-=value -xmp-dc:identifier=newident test.jpg
(*)  1 image files updated

exiftool.exe -xmp-dc:all test.jpg
Identifier                      : ident

exiftool.exe -xmp-dc:identifier-=value -xmp-dc:identifier=newident test.jpg
(*) 0 image files updated
    1 image files unchanged

exiftool.exe -xmp-dc:all test.jpg
Identifier                      : ident

exiftool.exe -tagsfromfile @ -xmp-dc:identifier-=ident -xmp-dc:identifier=newident test.jpg
(*)  1 image files updated

exiftool.exe -xmp-dc:all test.jpg
Identifier                      : ident

exiftool.exe -xmp-dc:identifier-=ident -xmp-dc:identifier=newident test.jpg
    1 image files updated

exiftool.exe -xmp-dc:all test.jpg
Identifier                      : newident

Questions ad (*):
Why is output different with/without option -tagsfromfile @ ?
Why is message "1 image files updated" although nothing is changed?

Thanks for your help in advance
Best regards
herb

StarGeek

I haven't completely looked over your output, but in the case of -TagsFromFile @ -xmp-dc:identifier-=value -xmp-dc:identifier=newident, here's what I think it happening.

In that command, you do not declare any tags to copy.  So it is defaulting to -All.  If you look at all the tags after the -TagsFromFile option, you will see that exiftool has copied data from the file properties into the EXIF/XMP-exif tags of the same name
C:\>exiftool -G1 -a -s -e --file:all y:\!temp\Test4.jpg
[ExifTool]      ExifToolVersion                : 12.62
[IFD0]          XResolution                    : 72
[IFD0]          YResolution                    : 72
[IFD0]          ResolutionUnit                  : inches
[IFD0]          YCbCrPositioning                : Centered
[ExifIFD]      ExifVersion                    : 0232
[ExifIFD]      ComponentsConfiguration        : Y, Cb, Cr, -
[ExifIFD]      UserComment                    : comment
[ExifIFD]      FlashpixVersion                : 0100
[ExifIFD]      ColorSpace                      : Uncalibrated
[XMP-x]        XMPToolkit                      : Image::ExifTool 12.62
[XMP-dc]        Identifier                      : ident
[XMP-exif]      ComponentsConfiguration        : Y, Cb, Cr, -
[XMP-tiff]      BitsPerSample                  : 8
[XMP-tiff]      ImageHeight                    : 1205
[XMP-tiff]      ImageWidth                      : 1749
[XMP-tiff]      YCbCrPositioning                : Centered
[XMP-tiff]      YCbCrSubSampling                : YCbCr4:2:0 (2 2)

At that point, I'm not sure what happens. By reading note #4 under the -TagsFromFile option, it seems that the -xmp-dc:identifier=newident assignment should be in position 4.  I'm looking through the -v (-verbose) option output to dig a bit deeper.

Phil will probably answer the question before I figure it out, though.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

herb

Hello StarGeek,

thanks for your analysis.
QuoteSo it is defaulting to -All.
I do not agree, because in case of following command
exiftool.exe -tagsfromfile @ -xmp-dc:identifier-=value "-+xmp-dc:identifier<${usercomment}" test.jpg
    0 image files updated
    1 image files unchanged
we have the expected answer.

Best regards
herb

StarGeek

#3
But you have an explicit tag you are copying, UserComment, so it won't default to -all.

edit:  So this is both a conditional replacement and explicit tag copy.  Because Identifier does not equal "value", nothing is changed.  But change the delete to "ident" and the replacement is made
C:\>exiftool -P -overwrite_original -tagsfromfile @ -xmp-dc:identifier-=ident "-+xmp-dc:identifier<${usercomment}" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -Usercomment -Identifier y:\!temp\Test4.jpg
[ExifIFD]       UserComment                     : comment
[XMP-dc]        Identifier                      : comment
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Ok, trying to work through this.

exiftool.exe -tagsfromfile @ -xmp-dc:identifier-=value -xmp-dc:identifier=newident test.jpg

This is two separate operations. First, the conditional replacement of Identifier. From the docs
     and -= may be used to conditionally delete or replace a tag
This is an operation I always have problems wrapping my head around, but Identifier is changed only if it was already set to "value".  The -v3 output on this is
Deleting XMP-dc:Identifier if value is 'value'
Writing XMP-dc:Identifier if tag was deleted
See these writing examples

The -TagsFromFile option is completely separate from the conditional replacement.  Since no tags are listed for this operation, it defaults to -All.  This can be seen by looking at the rest of the data that was copied as shown in my post above.  -v3 output for this shows
  Rewriting IFD0
    - IFD0:XResolution = '72'
    + IFD0:XResolution = '72'
    - IFD0:YResolution = '72'
    + IFD0:YResolution = '72'
    - IFD0:ResolutionUnit = '2'
    + IFD0:ResolutionUnit = '2'
  Rewriting ExifIFD
    - ExifIFD:ExifVersion = '0232'
    + ExifIFD:ExifVersion = '0232'
    - ExifIFD:UserComment = 'ASCIIcomment'
    + ExifIFD:UserComment = 'ASCIIcomment'
    - ExifIFD:FlashpixVersion = '0100'
    + ExifIFD:FlashpixVersion = '0100'
    - ExifIFD:ColorSpace = '65535'
    + ExifIFD:ColorSpace = '65535'
JPEG APP1 (2823 bytes)
  Rewriting XMP
    + XMP-tiff:BitsPerSample = '8'
    + XMP-exif:ComponentsConfiguration = '1'
    + XMP-exif:ComponentsConfiguration = '2'
    + XMP-exif:ComponentsConfiguration = '3'
    + XMP-exif:ComponentsConfiguration = '0'
    + XMP-tiff:ImageHeight = '1205'
    + XMP-tiff:ImageWidth = '1749'
    + XMP-tiff:YCbCrPositioning = '1'
    + XMP-tiff:YCbCrSubSampling = '2'
    + XMP-tiff:YCbCrSubSampling = '2'

exiftool.exe -xmp-dc:identifier-=value -xmp-dc:identifier=newident test.jpg

Again, conditional replacement.  Identifier is set to a new value only if it was deleted.

exiftool.exe -tagsfromfile @ -xmp-dc:identifier-=ident -xmp-dc:identifier=newident test.jpg

This one is tricky.  First, conditional replacement of IdentifierIdentifier is set to "newident".

But then, because there was no explicit tag copy for -TagsFromFile, it defaults to -All.  So the Identifier value of "ident" is copied back into the file.

The only thing I'm unsure about here is the order of operations.  From note #4 under the -TagsFromFile option, any tag assignment given after the -TagsFromFile option is done last. This would be the -Four=4 in that example.  So either no explicit tag assignment -all is done last or the conditional replacement isn't considered an assignment.

And the final example is the conditional replacement.

I think that covers it all
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

herb

Hello,

yes, you are right; and thanks for your detailed analysis.

Best regards
herb

StarGeek

Thanks for giving me a puzzle to work out regarding the conditional replacement.  Like I said, it's a weak point for me and this helped me get my head around it a bit better.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).