Write Tags from XML

Started by Curtis, August 04, 2013, 09:30:50 PM

Previous topic - Next topic

Curtis

I have a program that uses exiftool with a -@ "command file" and -stay_open.  I'm using the  -X -l -t options to get my tag values as an XML string (from stdout). 

My program then changes some of the values and now I want to write the updated values back to the image file.  I tried the -tagsFromFile option, but this requires me to write my updated XML string out to a file for exiftool to read.  (also I have not been able to get that to work anyways, I send exiftool via the command file -tagsFromFile then on the next line the file name ( test.xml ) which is the update output from the -X -l -t ) and exiftool does not update the image file, no warning or error messages either)

I'd like the write my updated XML string back to the "command file", as I believe (but could be wrong) that this would not involve a disk write/read and if so would be much quicker.

Is it possible to 'send' my update XML string to exiftool via the "command file" to update the tag values?  (or is it moot since it is really going to go to a disk file then to exiftool?)

Thanks!
Curtis

Edit: After a little more research I discovered I can  redirect sdtinp to exiftool using -@ - (and I have it working that way now), so that should completely eliminate the possibility of my commands 'written' to exiftool going through any disk write/reads.  Also in this post https://exiftool.org/forum/index.php/topic,4689.msg23281.html#msg23281 I found the -xml+= command, but that appears not to be for the standalone windows exiftool.exe, is there a way to use this command with exiftool.exe?

OR

instead of writing tags from XML is there a command option to identify the tag to be written using 'table name, id and index #'  (ie:  et:table, et:id and et:index values)?

Phil Harvey

Hi Curtis,

Quote from: Curtis on August 04, 2013, 09:30:50 PM
I have a program that uses exiftool with a -@ "command file" and -stay_open.  I'm using the  -X -l -t options to get my tag values as an XML string (from stdout). 

My program then changes some of the values and now I want to write the updated values back to the image file.

Since you are using the -stay_open feature, the technique would be to add this to the command file:

-GROUP:TAG=some value
-execute


QuoteI tried the -tagsFromFile option, but this requires me to write my updated XML string out to a file for exiftool to read.  (also I have not been able to get that to work anyways, I send exiftool via the command file -tagsFromFile then on the next line the file name ( test.xml ) which is the update output from the -X -l -t ) and exiftool does not update the image file, no warning or error messages either)

This should work for non-protected tags.  A specific example, or the -v2 output, would be useful.

QuoteIs it possible to 'send' my update XML string to exiftool via the "command file" to update the tag values?

No.  The command-line arguments for writing tag values directly are only of the form -GROUP:TAG=VALUE.

QuoteAlso in this post https://exiftool.org/forum/index.php/topic,4689.msg23281.html#msg23281 I found the -xml+= command, but that appears not to be for the standalone windows exiftool.exe, is there a way to use this command with exiftool.exe?

The standalone Windows version is exactly the same as other versions, but I don't think that -xml+=VALUE does what you want -- it adds more data to the XML in a JPEG2000 image.

Quoteinstead of writing tags from XML is there a command option to identify the tag to be written using 'table name, id and index #'  (ie:  et:table, et:id and et:index values)?

No.  You can only write by GROUP:TAG.  If there are multiple TAGs with different indices in the same GROUP, they will all be written.  This is the same as when you do -tagsfromfile XMLFILE.

- 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 ($).

Curtis

Hi Phil,

Got the -tagsfromfile working (dumb typo error  :-X). 

I understand what you are saying about writing my updated tag values.  I am trying to make sure I handle updating/adding tags correctly by trying to only update the exact same tags I had gotten via the -X -l -t XML output which uniquely identifies the tag (according to our previous forum posts).  This may not ever be a problem, but I was not sure.  As an example from the -listx output I see there are two IFD0:Model tags with id=272, one in Exif::Main table and the other in PanasonicRaw::Main table.  In this case I assume exiftool determines which version of the Model tag it got based on the image file format it is reading and that there would never be both Model tags in a given image file in the same Family 1 Group.  Is this generally true?  (ie can't have more than one tag with the same name in a given Family 1 (g1) Group?)

So it seems like the best way for me to write tags is as you said with -GROUP:TAG=some value and seems it would be best if I used the g1 Group name (from my -X -l -t XML output) since g1 gets me to a specific location in the meta data.  And I'll continue to get tag values with the -X -l -t XML output since it is the only way to get a unique tag id info to use to lookup description info in the -listx XML output.  Any suggestions of  a better way is welcome!

Thanks again!
Curtis

PS:  Since I did get the -tagsFromFile working, I did try using it to update IFD0:Artist and it worked, but I did notice it is not the same as doing a -IFD0:Artist=<new value> in that the -tagsFromFile appears to try to update Artist in all Groups but the -IFD0:Artist=<new value> appears to only try to update the Artist in IFD0 (as would be expected).  I will not be using -tagsFromFile for this, so this info is just FYI   :).  Results are below.

-tagsFromFile XML file:  (modified Artist value from XML output made from -X -t -IFD0:Artist)
<?xml version='1.0' encoding='utf-8'?>
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>

<rdf:Description rdf:about='D:/XMP Test Pictures/t.jpg'
  xmlns:et='http://ns.exiftool.ca/1.0/' et:toolkit='Image::ExifTool 9.33'
  xmlns:IFD0='http://ns.exiftool.ca/EXIF/IFD0/1.0/'>
<IFD0:Artist et:id='315' et:table='Exif::Main'>An XML IFD0 updated Artist!!!!!</IFD0:Artist>
</rdf:Description>
</rdf:RDF>


and exiftool output is:
Setting new values from C:\SimpleRoot\XML out from IFD0-Artist.xml
Sorry, CanonVRD:XMP is unsafe for writing
Sorry, XMP:XMP is unsafe for writing
Sorry, File:FileName is unsafe for writing
Sorry, File:FileModifyDate is unsafe for writing
Sorry, File:FileCreateDate is unsafe for writing
Sorry, File:Directory is unsafe for writing
Writing PNG:Artist
Writing Pentax:Artist if tag exists
Writing XMP-xmpDM:Artist if tag exists
Writing XMP-tiff:Artist if tag exists
Writing IFD0:Artist
Sorry, XMP-rdf:About is unsafe for writing
======== D:/XMP Test Pictures/t.jpg
Rewriting D:/XMP Test Pictures/t.jpg...
  Editing tags in: APP0 APP1 CIFF ExifIFD IFD0 JFIF MakerNotes PNG XMP
  Creating tags in: APP1 IFD0 PNG
JPEG APP1 (14696 bytes):
  Rewriting IFD0
  ExifByteOrder = MM
    - IFD0:Artist = 'Old Artist tag'
    + IFD0:Artist = 'An XML IFD0 updated Artist!!!!!'
  Rewriting ExifIFD
  Rewriting MakerNoteCanon
  Rewriting CanonCameraSettings
  Rewriting CanonShotInfo
  Rewriting CanonCameraInfoUnknown32
  Rewriting MyColors
  Rewriting ContrastInfo
  Rewriting FaceDetect3
  Rewriting AspectInfo
  Rewriting InteropIFD
  Rewriting IFD1
JPEG APP1 (5214 bytes):
  Rewriting XMP
    [XMP rewritten with no changes]
JPEG APP13 (160 bytes):
JPEG DQT (65 bytes):
JPEG DQT (65 bytes):
JPEG SOF0:
JPEG DHT (29 bytes):
JPEG DHT (179 bytes):
JPEG DHT (29 bytes):
JPEG DHT (179 bytes):
JPEG SOS
    1 image files updated


and exiftool output from using -IFD0:Artist=New Artist from tag
Writing IFD0:Artist
======== D:/XMP Test Pictures/t.jpg
Rewriting D:/XMP Test Pictures/t.jpg...
  Editing tags in: APP0 APP1 IFD0 JFIF
  Creating tags in: APP1 IFD0
JPEG APP1 (14696 bytes):
  Rewriting IFD0
  ExifByteOrder = MM
    - IFD0:Artist = 'An XML IFD0 updated Artist!!!!!'
    + IFD0:Artist = 'New Artist from tag'
  Rewriting ExifIFD
  Rewriting MakerNoteCanon
  Rewriting CanonCameraSettings
  Rewriting CanonShotInfo
  Rewriting CanonCameraInfoUnknown32
  Rewriting MyColors
  Rewriting ContrastInfo
  Rewriting FaceDetect3
  Rewriting AspectInfo
  Rewriting InteropIFD
  Rewriting IFD1
JPEG APP1 (5214 bytes):
JPEG APP13 (160 bytes):
JPEG DQT (65 bytes):
JPEG DQT (65 bytes):
JPEG SOF0:
JPEG DHT (29 bytes):
JPEG DHT (179 bytes):
JPEG DHT (29 bytes):
JPEG DHT (179 bytes):
JPEG SOS
    1 image files updated

Phil Harvey

#3
Hi Curtis,

Quote from: Curtis on August 05, 2013, 03:43:22 PM
Is this generally true?  (ie can't have more than one tag with the same name in a given Family 1 (g1) Group?)

There are many exceptions in the maker notes, but this is generally true for the major metadata types (EXIF, IPTC, XMP).

QuoteSo it seems like the best way for me to write tags is as you said with -GROUP:TAG=some value and seems it would be best if I used the g1 Group name (from my -X -l -t XML output) since g1 gets me to a specific location in the meta data.

Yes.  This is what adding -all:all does when copying with -tagsFromFile -- it writes to the same family 1 group (specific location).

QuoteAnd I'll continue to get tag values with the -X -l -t XML output since it is the only way to get a unique tag id info to use to lookup description info in the -listx XML output.  Any suggestions of  a better way is welcome!

No.  I think that's the way to do it.

Quote-tagsFromFile appears to try to update Artist in all Groups

Yes, unless you specify the destination group.  Adding -all:all (as I mentioned above) implies the same family 1 group destination when copying all tags.  Whether copying or writing, ExifTool is consistent about this.  While it may not be intuitive, it does give you freedom to do what you want if you know where you want the information to go, otherwise by default ExifTool creates new tags in its preferred location and updates all existing same-named tags.

This is all explained in the second paragraph of the -tagsFromFile documentation, although I can see how easy it would be to miss the significance of this.

- 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 ($).

Curtis

Thanks Phil for your quick and concise answers!

Until next time....
Curtis