ExifTool Forum

General => Metadata => Topic started by: tbraber on March 15, 2011, 09:58:48 AM

Title: Double XMP entry in file
Post by: tbraber on March 15, 2011, 09:58:48 AM
I have a jpeg file with the xmp description in the file that looks like:

<rdf:Description rdf:about=''
  xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:description> 4.0.1</dc:description>
</rdf:Description>

Exiftool reads this correctly but when I edit the dc:description it ads an extra dc:description block:

<rdf:Description rdf:about=''
  xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:description> 4.0.1</dc:description>
  <dc:description>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>test</rdf:li>
   </rdf:Alt>
  </dc:description>
</rdf:Description>

Why does it not edit the existing tag instead of adding an extra tag ?
I am using Exiftool 8.45
Title: Re: Double XMP entry in file
Post by: Phil Harvey on March 15, 2011, 10:44:19 AM
This happens because the existing description is written incorrectly.  It should be enclosed in an alternate language list.

ExifTool is very tolerant of unrecognized XMP, and will generally just pass it straight through when writing.

- Phil
Title: Re: Double XMP entry in file
Post by: tbraber on March 15, 2011, 12:37:09 PM
Phil,

could there be a way that Exiftool removed the original dc:description and replaces that with the correct one ?
Maybe by deleting the complete xmp recourse and rebuilding it again.

Thanks for your reply,
Thomas
Title: Re: Double XMP entry in file
Post by: Phil Harvey on March 15, 2011, 01:36:31 PM
Hi Thomas,

Yes, you can rebuild the XMP with this command:

exiftool -xmp:all= -tagsfromfile @ -xmp:all FILE

This will delete any XMP tags that are not writable by ExifTool.

- Phil
Title: Re: Double XMP entry in file
Post by: tbraber on March 16, 2011, 04:16:18 AM
Do you have any suggestion how to do that in Perl with the Perl Library ?

Thanks,

Thomas den Braber
Title: Re: Double XMP entry in file
Post by: Phil Harvey on March 16, 2011, 07:29:11 AM
Hi Thomas,

Sure:

    $exifTool->SetNewValue('xmp:all');
    $exifTool->SetNewValuesFromFile($srcFile, 'xmp:all');
    $exifTool->WriteInfo($srcFile, $outFile);


- Phil
Title: Re: Double XMP entry in file
Post by: tbraber on March 23, 2011, 07:19:49 AM
Thanks,

That worked really well, it fixed my double entries.

I was hoping that:


$exifTool->SetNewValue('XMP:all');
$exifTool->SetNewValue('XMP:all', undef, Replace => 2)


also would work because I already read the info from the file with $exifTool->ExtractInfo

I assume that SetNewValuesFromFile will add some more overhead.

Title: Re: Double XMP entry in file
Post by: Phil Harvey on March 23, 2011, 08:05:45 AM
You could avoid the extra step of calling SetNewValuesFromFile(), but it would require calling SetNewValue() for each value you want to write, something like this:

my $exifTool = new Image::ExifTool;
$exifTool->ExtractInfo($srcFile);
my $info = $exifTool->GetInfo('XMP:all');

$exifTool->SetNewValue('XMP:all');
foreach my $key (keys %$info) {
    $exifTool->SetNewValue($key, $$info{$key}, Group => 'XMP');
}
$exifTool->WriteInfo($srcFile, $dstFile);


Note that you will get some warnings to stderr with this code since I haven't set the Protected flag or captured the warnings from SetNewValue().

- Phil