Checking for TAG in pair of files

Started by msbc, January 16, 2017, 12:38:50 AM

Previous topic - Next topic

msbc

I'd like to check for the existence or otherwise of a tag in a RAW file and an XMP sidecar at the same time. So, if a folder contains 5 NEF files and their XMP sidecars I want to determine if a particular tag exists in each NEF and/or the associated XMP. Ideally the test would print the filename if the tag is not present in either the NEF or XMP. If the tag is present in either, or both then no action would be taken.

Is this possible ?

Thanks,
Mark
- Mark

Hayo Baan

Hi Mark,

So you are looking for a solution that shows the name of the file IF both it and the matching XMP do not have a certain tag?

Well, yes, but it not easily. A solution a can think of would be to use a custom tag which calls exiftool again on the accompanying file and checks to see if that tag is present there.

Another solution would be to just use a little bit of scripting checking the output of an exiftool call on both files (if you're on a Mac/Linux this is really simply done).

What is the name of the tag you are looking for?
Hayo Baan – Photography
Web: www.hayobaan.nl

msbc

Hi, I need an efficient solution as I will be running the command on many folders, some with 400+ NEF/XMP pairs.

Scripting is fine - I'm on a Mac. I already have a script I developed that checks all my image folders and reports if certain tags, conditions pass/fail. I'll be augmenting the script to add this new check - hopefully :-)

As background to what I'm trying to do - I want to check all my image files and report if they have/don't have GPS information. I have images from many different cameras. Most of my images I've added GPS data after shooting to the XMP. But some of my NEFs have GPS in the NEF as I've used a GPS device on my camera. So some RAW files - Sony, Canon, Panasonic, Olympus - have GPS in XMP. Some NEFs have GPS in the NEF, some in the XMP (when I didn't use the on-camera GPS) and some files have not yet been geo-tagged.

My test would be to look for gpslatitude tag in the RAW/XMP pair and print out the filename if neither had that tag.

Your suggestion about using a custom tag sounds interesting - since I don't want to have to execute the exiftool cmd twice, once for XMP and again for the RAW.
- Mark

Hayo Baan

I'll see if I can find some time tomorrow to give you a first solution.
Hayo Baan – Photography
Web: www.hayobaan.nl

Stephen Marsh

It should be possible to use the one command on a directory/subdirectories by adding the extension filter to specifically process the required file types, such as:

exiftool -r -tagname -ext .cr2 -ext .xmp DIR

Hayo Baan

Quote from: Stephen Marsh on January 16, 2017, 05:57:41 PM
It should be possible to use the one command on a directory/subdirectories by adding the extension filter to specifically process the required file types, such as:

exiftool -r -tagname -ext .cr2 -ext .xmp DIR
Stephen, that's not exactly what Mark wants: he only wants to see those files that have the GPS info set in either the raw file or the xmp. Your command will show the info for all files.
Hayo Baan – Photography
Web: www.hayobaan.nl

Hayo Baan

Hi Mark,

I've created a composite tag GPSIsSet that indicates whether or not the file (1) or the xmp (2) has GPSLatitude set.

Using exiftool's -if function you can then easily accomplish what you want: exiftool -config gps_isset_config -T -filepath -if '$GPSIsSet'

Enjoy.

File: gps_isset_config
%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        GPSIsSet => {
            Require => {
                0 => 'Directory',
                1 => 'FileName',
            },
            Desire => {
                2 => 'GPSLatitude',
            },
            RawConv => q{
                return 1 if defined $val[2];
                if ($val[1] !~ /\.xmp$/i) {
                    require File::Spec;
                    my $xmp = File::Spec->catfile($val[0], $val[1]);
                    $xmp =~ s/\.[^.]+$/.xmp/;
                    if (-f $xmp) {
                        my $et = Image::ExifTool->new;
                        $et->ExtractInfo($xmp);
                        return 2 if defined $et->GetValue('GPSLatitude');
                    }
                }
                return 0;
            },
        }
    },
);

1;
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

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

Hayo Baan

Quote from: Phil Harvey on January 17, 2017, 07:51:25 AM
Sweet.
:)

I think this is the most elegant and efficient way since it doesn't involve loading exiftool a second time (another "simpler" solution could have been to use the backtick operator to call exiftool another time, or otherwise some shell logic).

It's actually a similar technique I use in my own library. There I gather and merge (additional) information (for .mov files) from .xmp files as well.
Hayo Baan – Photography
Web: www.hayobaan.nl

Stephen Marsh

Quote from: Hayo Baan on January 17, 2017, 05:24:57 AM
Quote from: Stephen Marsh on January 16, 2017, 05:57:41 PM
It should be possible to use the one command on a directory/subdirectories by adding the extension filter to specifically process the required file types, such as:

exiftool -r -tagname -ext .cr2 -ext .xmp DIR
Stephen, that's not exactly what Mark wants: he only wants to see those files that have the GPS info set in either the raw file or the xmp. Your command will show the info for all files.

Thanks Hayo, I did test before posting and the TIF file was filtered out and only the CR2 and XMP were reported. I'll test again...

EDIT: OK I see what you mean, either CR2 or XMP – not both at the same time (and there may be more than one raw file format).

msbc

Hayo,

Just confirming my understanding of your composite tag - I have merged it into my .Exiftool-config file:
If I execute exiftool -GPSIsSet -ext NEF . then the three output possibilities for each file would be:
0 - no GPSLatitude in NEF or XMP
1 - GPSLaitude in NEF
2 - GPSLaitude in XMP
- Mark

Hayo Baan

Quote from: msbc on January 17, 2017, 06:54:45 PM
Hayo,

Just confirming my understanding of your composite tag - I have merged it into my .Exiftool-config file:
If I execute exiftool -GPSIsSet -ext NEF . then the three output possibilities for each file would be:
0 - no GPSLatitude in NEF or XMP
1 - GPSLaitude in NEF
2 - GPSLaitude in XMP
Exactly :)
Note: no checking of XMP is done once it is determined the nef has it. It's easy to extend the code to allow for this too (e.g. 3 is both have it), but it will make checking slower and I didn't think you needed it anyway.
Hayo Baan – Photography
Web: www.hayobaan.nl

msbc

Great - thanks so much for working this out :-)

I'm thinking that since the majority of my images don't have the GPS in the RAW it would be more efficient to test the XMP first and try the RAW if that fails. What modification would be needed to achieve that? I think GPSIsSet would need an argument that would be the filetype since it could be anything, not just NEF.
- Mark

StarGeek

The GPSIsSet tag will accept any file type, the NEF limitation was in the -ext NEF option on the command line.  Remove that for any file or change it to limit it.

Changing it to check XMP first might be more difficult to do.  Easier to check to see if an XMP file exists rather than checking to see if a jpeg, png, tiff, nef, cr2, etc, exists that matches the XMP file.
* 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).

msbc

The XMP will always be present - I only shoot RAW so there is always a RAW/XMP pair.
- Mark