photostructure / exiftool-vendored.js

Fast, cross-platform Node.js access to ExifTool
https://photostructure.github.io/exiftool-vendored.js/
MIT License
405 stars 37 forks source link

-g vs -G produces different tag values #147

Closed alex-phillips closed 11 months ago

alex-phillips commented 11 months ago

Describe the bug I'm attempting to get multiple values from different groups as some of the metadata in one group is accurate and some is not accurate. In this case, There is GPS Longitude and GPS Latitude from the group XMP-exif which is correct, but using default settings, it is returning the incorrect values from the XMP-video group. If I pass in the "-G1" string into optionalArgs, it returns the following keys and values which allows me to get the correct data:

'XMP-video:GPSLatitude': '0,0.00000000N',
'XMP-exif:GPSLatitude': 35.6196222166667,
'XMP-video:GPSLongitude': '0,0.00000000E',
'XMP-exif:GPSLongitude': -78.6253083166667,

But I would like the values to exist in a group and then that object have access just to the normal tag, on not including the group (i.e., GPSLongitude). But using the argument -g1 produces the data in grouped object key-values, but the values for the XMP-exif GPS data is returned as undefined.

To Reproduce I've included the file here that I am using to attempt to extract the proper geo data. You can reproduce the above by running the following 2 ways of reading the data:

This produces the data with the group in the key which also returns the correct value:

exiftool.read(filepath, ["-G1"]).then(results => console.log(results))

This produces the exif data grouped within the data structure but returns undefined for the XMP-exif values:

exiftool.read(filepath, ["-g1"]).then(results => console.log(results))

Expected behavior The 2 options should produce the same values for the keys, just structured differently in the returned output.

Environment (please complete the following information):

VID_20190111_135851.mp4.xmp.zip

alex-phillips commented 11 months ago

For reference, here is my local output of invoking exiftool directly on the filesystem using the 2 options of -g1 and -G1:

$ exiftool -a -g1 VID_20190111_135851.mp4.xmp | grep -i "gps "
GPS Coordinates                 : +00.0000+000.0000/
GPS Latitude                    : 0,0.00000000N
GPS Longitude                   : 0,0.00000000E
GPS Map Datum                   : WGS-84
GPS Version ID                  : 2.0.0.0
GPS Version ID                  : 2.0.0.0
GPS Latitude                    : 35 deg 37' 10.64" N
GPS Longitude                   : 78 deg 37' 31.11" W
GPS Altitude Ref                : Above Sea Level
GPS Altitude                    : 61.82 m
GPS Map Datum                   : WGS-84
GPS Altitude                    : 61.8 m Above Sea Level
GPS Latitude Ref                : North
GPS Longitude Ref               : West
GPS Position                    : 0,0.00000000N, 0,0.00000000E
$ exiftool -a -G1 VID_20190111_135851.mp4.xmp | grep -i "gps "
[XMP-video]     GPS Coordinates                 : +00.0000+000.0000/
[XMP-video]     GPS Latitude                    : 0,0.00000000N
[XMP-video]     GPS Longitude                   : 0,0.00000000E
[XMP-video]     GPS Map Datum                   : WGS-84
[XMP-video]     GPS Version ID                  : 2.0.0.0
[XMP-exif]      GPS Version ID                  : 2.0.0.0
[XMP-exif]      GPS Latitude                    : 35 deg 37' 10.64" N
[XMP-exif]      GPS Longitude                   : 78 deg 37' 31.11" W
[XMP-exif]      GPS Altitude Ref                : Above Sea Level
[XMP-exif]      GPS Altitude                    : 61.82 m
[XMP-exif]      GPS Map Datum                   : WGS-84
[Composite]     GPS Altitude                    : 61.8 m Above Sea Level
[Composite]     GPS Latitude Ref                : North
[Composite]     GPS Longitude Ref               : West
[Composite]     GPS Position                    : 0,0.00000000N, 0,0.00000000E
mceachen commented 11 months ago

This library always appends the -json switch, which make -g and -G render differently from what you're looking at. From https://exiftool.org/exiftool_pod.html,

  -g[NUM...]  (-groupHeadings)     Organize output by tag group
  -G[NUM...]  (-groupNames)        Print group name for each tag

With little g, groups and values are nested objects:

$ exiftool -json -g1 -GPS\*\# /tmp/VID_20190111_135851.mp4.xmp
[{
  "SourceFile": "/tmp/VID_20190111_135851.mp4.xmp",
  "XMP-video": {
    "GPSCoordinates": "+00.0000+000.0000/",
    "GPSLatitude": "0,0.00000000N",
    "GPSLongitude": "0,0.00000000E",
    "GPSMapDatum": "WGS-84",
    "GPSVersionID": "2.0.0.0"
  },
  "XMP-exif": {
    "GPSVersionID": "2.0.0.0",
    "GPSLatitude": 35.7803977,
    "GPSLongitude": -78.6390988833333,
    "GPSMapDatum": "WGS-84"
  },
  "Composite": {
    "GPSLatitudeRef": "N",
    "GPSLongitudeRef": "W",
    "GPSPosition": "0,0.00000000N 0,0.00000000E"
  }
}]

With big G, the group name is prepended to the key:

$ exiftool -json -G1 -GPS\*\# /tmp/VID_20190111_135851.mp4.xmp
[{
  "SourceFile": "/tmp/VID_20190111_135851.mp4.xmp",
  "XMP-video:GPSCoordinates": "+00.0000+000.0000/",
  "XMP-video:GPSLatitude": "0,0.00000000N",
  "XMP-video:GPSLongitude": "0,0.00000000E",
  "XMP-video:GPSMapDatum": "WGS-84",
  "XMP-video:GPSVersionID": "2.0.0.0",
  "XMP-exif:GPSVersionID": "2.0.0.0",
  "XMP-exif:GPSLatitude": 35.7803977,
  "XMP-exif:GPSLongitude": -78.6390988833333,
  "XMP-exif:GPSMapDatum": "WGS-84",
  "Composite:GPSLatitudeRef": "N",
  "Composite:GPSLongitudeRef": "W",
  "Composite:GPSPosition": "0,0.00000000N 0,0.00000000E"
}]

The -G (or -G1, or -g, or -g1) option is not officially supported by the ExifTool.read function, as the returning value is most decidedly not a Tags instance.

Practically speaking, if you want this sort of output, you should use the ExifTool.readRaw function, which lets you and ExifTool render whatever shaped output you need, like this:

console.log( await require('exiftool-vendored').exiftool
   .readRaw("/tmp/VID_20190111_135851.mp4.xmp", ["-G1", "-GPS*#"]))

{
  SourceFile: '/tmp/VID_20190111_135851.mp4.xmp',
  'XMP-video:GPSCoordinates': '+00.0000+000.0000/',
  'XMP-video:GPSLatitude': '0,0.00000000N',
  'XMP-video:GPSLongitude': '0,0.00000000E',
  'XMP-video:GPSMapDatum': 'WGS-84',
  'XMP-video:GPSVersionID': '2.0.0.0',
  'XMP-exif:GPSVersionID': '2.0.0.0',
  'XMP-exif:GPSLatitude': 35.7803977,
  'XMP-exif:GPSLongitude': -78.6390988833333,
  'XMP-exif:GPSMapDatum': 'WGS-84',
  'Composite:GPSLatitudeRef': 'N',
  'Composite:GPSLongitudeRef': 'W',
  'Composite:GPSPosition': '0,0.00000000N 0,0.00000000E'
}

(the "-GPS*#" tells ExifTool to only return GPS tags, and to render them numeric)