Duplicates in tables

Started by MichaelRath, January 06, 2011, 07:04:32 AM

Previous topic - Next topic

MichaelRath

Dear Phil,

another problem I have is that I want to get one database containing all EXIF information in one CSV file. The -T option is really nice and gives me the format I want.

But in some pictures some values are stored multiple times (e.g. because of embedded JPEGs in RAW files) so that the resulting table contains lines with two or more fields for the same tag completely ruining the CSV database structure (columns).

This could be addressed by using group names when specifying the tag name but it does not work all the times:

There are group names that only differ in one extra group, e.g.:

[MakerNotes:Minolta:Camera:Main:Copy1] Flash Exposure Compensation: +14/3
[MakerNotes:Minolta:Camera:Main] Flash Exposure Compensation: -3.199248564e-07


Aside from the peculiar value for the last and why on earth the two values differ, I found no way to get only the value for the Main group. Using -MakerNotes:Minolta:Camera:Main:FlashExposureComp as tag definition still delivers two fields...

My current workaround for such cases leading to duplicate fields is to define composite tags like
        MyFlashExposureComp => {
            Require => 'FlashExposureComp',
            ValueConv => 'return $val'
        },


That gives me only one value but I'm not really able to choose which or is there a way to do that in this definition?

And even if I could specify exactly the desired group that may not be the solution for all cases:

Sometimes the information is stored in different places, e.g. "Quality" is stored either in

[Ducky:Image:Main] Quality
[MakerNotes:Canon:Camera:Main] Quality
[Photoshop:Image:Main] Photoshop Quality


and I have a Sony RAW file containing:

[MakerNotes:Sony:Camera:Main:Copy1] Quality     : RAW + JPEG
[MakerNotes:Sony:Camera:Main] Quality           : Unknown (256)


How can I get the right value for all pictures of all different cameras?

The workaround with user defined composite tags has another problem:

Using
        MyQuality => {
        Require => 'Quality',
            ValueConv => 'return $val'
        },

gives me only raw values (numbers) and not the meaning depending on the camera (e.g. "RAW + JPEG", "77%", "Fine", "Normal"...).

I found a way to solve that for the Lens ID:
        MyLensID => {
        Require => 'LensID',
        PrintConv => 'Image::ExifTool::Exif::PrintLensID($self, $prt[0], @val)',
            ValueConv => 'return $val'
        },

but I don't know Perl and your program well enough to get a PrintConv function for all tags (e.g. Quality) on all different cameras...

So what I like to have is:

The possibility to request really only one value for a given tag (even if the group names differ only in one appendix like ":Copy1") or to have all different values for one tag name listed in the same column in the table that means no field delimiter (tab) between the values.

Regards

Michael

Phil Harvey

This general problem is solved by just not using the -a option.

However, it sounds like this doesn't suit you because you want to be able to fine-tune which of the values is reported in the case where multiple values exist.  This is a big can of worms as you probably realize, but the only solution I can see for you is through the user-defined tags.  You could do something like this:

        MyFlashExposureComp => {
            Require => 'FlashExposureComp', # (this will be $val[0] since an index isn't specified)
            Desire => {
                1 => 'EXIF:FlashExposureComp',
                2 => 'Minolta:Copy1:FlashExposureComp',
            },
            ValueConv => 'pop @val while @val and not defined @val; return $val[-1]',
        },


The above example takes the tag with the highest index, so if you put the tags in increasing order of precedence this will work.  You could also get real fancy and test the values themselves to take the one you like best.

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

MichaelRath

Dear Phil,

QuoteThis general problem is solved by just not using the -a option.

well, I wasn't really aware that I indeed introduced an "-a" when adding the last field (-IPTC:All) in my option file ("-@") to be sure to get really all IPTC tags.

After removing it nothing changed and I found that I had to explicitly disable "-a" by using "--a" because in my .ExifTool_config downloaded from your site "Duplicates => 1" was set...

But as you said that is not always the best solution for me.

I think I can get it to work my way by adapting your example to the other tags.

Though the other problem to convert the resulting raw values to "print values" (see remarks to "MyQuality" in my original posting) is still unsolved.

Is there a way to enumerate all tags with the same name from different groups? And would it then be possible to do the corresponding print conversion (PrintConv) for the found value?

Or can I find out the type of object used when just specifying the tag name without group qualifier and then call the corresponding PrintConv?

Regards

Michael


Phil Harvey

Hi Michael,

Quote from: MichaelRath on January 07, 2011, 08:37:10 PM
After removing it nothing changed and I found that I had to explicitly disable "-a" by using "--a" because in my .ExifTool_config downloaded from your site "Duplicates => 1" was set...

I imagine this would have caused some head-scratching.  Glad you figured this out.  Locally I use the sample config file too so I always have to keep this in mind myself.

QuoteThough the other problem to convert the resulting raw values to "print values" (see remarks to "MyQuality" in my original posting) is still unsolved.

Sorry for missing this.  You access the print-converted values through the elements of @prt in your ValueConv and PrintConv statments just in the same way that you access the numerical values through @val.  $val is special, and is provided for convenience to represent $val[0].  (Also, you can access the original raw values straight out of the file with @raw, but you would probably never need to do this.)

Quote
Is there a way to enumerate all tags with the same name from different groups?

-all:TAG on the command line.  But it gets much trickier if you want to do this in a Composite tag.

Quote
And would it then be possible to do the corresponding print conversion (PrintConv) for the found value?

OK, it seems you want to do this in a Composite tag.  As I said, it is tricky and uses some inside knowledge about the format of a tag key in ExifTool:

    MyTag => {
        Require => 'SomeTagName',
        ValueConv => q{
            for (my $i=0; ;++$i) {
                my $key = 'SomeTagName';
                $key .= " ($i)" if $i;
                my ($v, $p) = $self->GetValue($key, 'Both');
                last unless defined $v;
                my $g = $self->GetGroup($key, 1);
                print "$i) $g $v $p\n"; # test purposes only
            }
            return undef; # <-- you will have to figure out what to return here
        },
    },


In this example, $v and $p are the ValueConv and PrintConv values, and $g is the family 1 group name.  It is up to you to figure out what you want to do with these inside the for loop.

Quote
Or can I find out the type of object used when just specifying the tag name without group qualifier and then call the corresponding PrintConv?

Maybe I just wasted my time with the example, because I answered this question earlier.  Just use the value from the @prt array.

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

MichaelRath

Hi Phil,

thanks again for your fast and competent reply. This is all (and more ;)) that I need.

QuoteMaybe I just wasted my time with the example, because I answered this question earlier.  Just use the value from the @prt array.

I'm pretty sure this knowledge will come handy sooner or later as I get to know Exiftool and Perl - and even if not for me, somebody else might need it...

Regards

Michael