ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: BonanzaMan on February 13, 2011, 08:24:43 AM

Title: Makernotes in perl script
Post by: BonanzaMan on February 13, 2011, 08:24:43 AM
I have been using:

exiftool -tagsfromfile src.jpg -makernotes dest.jpg

from the command line with good results.  I am starting to build more complicated operations using the Exiftool module in Perl.

What is the analog of this command line in the API?  I suspect it involves "SetNewValuesFromFile" but the makernotes part for my src.jpg (a reconyx image) is stumping me.

Thanks,
Greg
Title: Re: Makernotes in perl script
Post by: Phil Harvey on February 13, 2011, 10:43:22 AM
Hi Greg,

Did you try

$exifTool->SetNewValuesFromFile('src.jpg', 'MakerNotes');

?

- Phil
Title: Re: Makernotes in perl script
Post by: BonanzaMan on February 28, 2011, 10:48:48 PM
Thanks Phil -
Just now getting back to this project.  I am in the process of converting some of my working Exiftool command line utilities to perl scripts that use the API.  Per your note above, I was able to get the MakerNotes to copy over ok, but I am still a little mystified by the nomenclature for refering to cetain MakerNote tags in SetNewValue calls.

Here is a extract from the exiftool -v report:

  | | 16) MakerNoteReconyx (SubDirectory) -->
  | | + [BinaryData directory, 713 bytes]
  | | | TriggerMode = M
  | | | Sequence = 5 10
  | | | DateTimeOriginal = 39 24 10 11 6 2010
  | | | MoonPhase = 0
  | | | AmbientTemperatureFahrenheit = 32
  | | | AmbientTemperature = 0
  | | | SerialNumber = H500BD09009724
  | | | InfraredIlluminator = 0


So in this case, how would I set the "UserLabel" tag value?
      $exifTool->SetNewValue('UserLabel','Test')

Or do the equivalent of this command?
     exiftool "-datetimeoriginal<createdate" "$file")

Thanks,
Greg
Title: Re: Makernotes in perl script
Post by: Phil Harvey on March 01, 2011, 07:22:52 AM
Hi Greg,

QuoteSo in this case, how would I set the "UserLabel" tag value?
      $exifTool->SetNewValue('UserLabel','Test')

The UserLabel is missing from your output.  But yes, you are setting the value correctly.

QuoteOr do the equivalent of this command?
     exiftool "-datetimeoriginal<createdate" "$file")

$exifTool->SetNewValuesFromFile('src.jpg', 'datetimeoriginal<createdate');

- Phil
Title: Re: Makernotes in perl script
Post by: BonanzaMan on March 01, 2011, 09:04:24 AM
Thanks Phil - I must have something else going on here that my inexperienced eyes can't see - yet.

Here is what I am trying to do:
# open an existing created by OEM camera X
$exifTool->ImageInfo($srcfile);

# copy MakerNotes meta data from a JPEG file created by OEM camera Y
$exifTool->SetNewValuesFromFile('templatefile.jgp', 'MakerNotes');

# Update a Tag value from OEM Y MakerNotes
$exifTool->SetNewValue('UserLabel','Test');

# Create a new JPEG with OEM X image and meta data and updated MakerNotes from OEM Y
$errcode = $exifTool->WriteInfo($newimage);


When I do this, I get a "tag 'UserLabel' doesn't exist" error.

Using the command line interface, these two commands accomplish the desired result:
exiftool -tagsfromfile templatefile.jgp -makernotes orig.jpg
exiftool -UserLabel="Test" orig.jpg
Title: Re: Makernotes in perl script
Post by: Phil Harvey on March 01, 2011, 09:28:15 AM
Hi Greg,

It sounds like your script is using an old version of exiftool.  Try printing $Image::ExifTool::VERSION from your script to verify that you are running the correct version.  The UserLabel tag was added in version 8.44.

Also, since the UserLabel tag exists in the maker notes, your script might not do what you want.  When copying the makernotes as a block you can't change a makernote tag at the same time.  You must write the file twice to do this.

- Phil
Title: Re: Makernotes in perl script
Post by: BonanzaMan on March 01, 2011, 09:30:45 AM
I'm on 8.40.  Thanks Phil - I'll update and let you know.

Much appreciated.

Greg
Title: Re: Makernotes in perl script
Post by: BonanzaMan on March 01, 2011, 12:42:25 PM
Ok.  I am now on v 8.50.  As far as I can get tell, "$exifTool->SetNewValuesFromFile('templatefile.jgp', 'MakerNotes');" isn't working as subsequent GetValue calls return no results.  Is my basic pseudo code above correct, or am I working this in the wrong order?

Thanks, Greg


Title: Re: Makernotes in perl script
Post by: Phil Harvey on March 01, 2011, 12:51:06 PM
Hi Greg,

You spelled ".jgp" wrong.  Also, this will only work if the source image contains maker notes.

I don't know what steps you are taking, but you should be doing something like this:

# copy MakerNotes meta data from a JPEG file created by OEM camera Y
$exifTool->SetNewValuesFromFile('templatefile.jpg', 'MakerNotes');
$errcode = $exifTool->WriteInfo($newimage);

# Reset new tag values
$exifTool->SetNewValue();

# Set new value for the Reconyx:UserLabel tag
$exifTool->SetNewValue('UserLabel','Test');

# Write new UserLabel
$errcode = $exifTool->WriteInfo($newimage);


- Phil
Title: Re: Makernotes in perl script
Post by: Phil Harvey on March 01, 2011, 12:57:18 PM
A couple more things:

1) the target file ($newimage) must exist before the script is run.

2) you should also probably copy the Make and Model tags because these may affect the decoding of the maker notes:

$exifTool->SetNewValuesFromFile('templatefile.jpg', 'MakerNotes','Make','Model');

- Phil
Title: Re: Makernotes in perl script
Post by: BonanzaMan on March 01, 2011, 02:43:10 PM
Thanks for the addendum Phil... I'll check it out.  I think I finally slayed this dragon.  Here is the essentials of the flow and APIs used.  Many Thanks!  Greg

$exifTool->SetNewValuesFromFile('templatefile.JPG', 'MakerNotes');

$errcode = $exifTool->WriteInfo($image, $newimage);

# Reset new tag values
$exifTool->SetNewValue();

# Set new Values
$exifTool->SetNewValuesFromFile($newimage, 'datetimeoriginal<createdate');
$exifTool->SetNewValue('MoonPhase',$phase);
$exifTool->SetNewValue('UserLabel',$CameraMaker);
$exifTool->SetNewValue("Sequence","1 of 1");
$errcode = $exifTool->WriteInfo($newimage);