Project

General

Profile

commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24

Added by Oliver P over 6 years ago

Hi,
I use exiv2 in a simple script for extracting GPS data from images.
Until now I used Version 0.21.1 and the command: 'exiv2 -Pv -g Exif.GPSInfo.GPSAltitude $filename'
This used to return somehting like
"123/1"

I was going to update the script a little, and installed the latest version on my new laptop, and realized it was giving me completely different results. After a while of digging I found out why:
the same command now returns:
"0
123/1"
(including the line break)
This is because searching for 'Exif.GPSInfo.GPSAltitude' now also returns the value for Exif.GPSInfo.GPSAltitudeRef. In other words it searches for Exif.GPSInfo.GPSAltitude* rather than just Exif.GPSInfo.GPSAltitude.
I only tested 0.21.1 and 0.24 and somewhere in between the behaviour changed. Of course this is not only the case with Altitude, but the same happens with Longitude (and LongitudeRef), Latitude, etc.

2 Questions:
1) Is this wanted behaviour or a bug? (I couldn't find anything about this in the changelog)
2) either way: how can I now retrieve a single value from the commandline?

I tried adding quotes around the Tag name (same result), adding a space behind the Tag (no more results), and a few more things, but never got the expected results.

Thanks.


Replies (17)

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

I think the behaviour of the -g switch was changed from being "this key" to being "match keys" (a la grep) so -g GPSLatitude may match more than one key. Piping the output through grep to ignore "Ref" will save the day. Here's a photo I took yesterday on a trip to Windsor Castle:

594 rmills@rmillsmbp:~/Pictures/2015/Windsor $ exiv2 -pa -g Latitude DSC_6503.jpg
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 28.81760' 
595 rmills@rmillsmbp:~/Pictures/2015/Windsor $ exiv2 -pa -g Latitude DSC_6503.jpg | grep -v -e Ref
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 28.81760' 
596 rmills@rmillsmbp:~/Pictures/2015/Windsor $ 
Apologies for breaking your script. Perhaps I should have used -G for "match/grep" and retained -g for "key". I'm reluctant to change -g now as the "match" feature was put in place some time ago. If I change it again, I'll break another user's script!

We intend to extend the -g option to take advantage of the platform's regex support. http://dev.exiv2.org/issues/1024

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

I've just noticed that you are using -Pv to get the vanilla (raw) value. More apologies. You'll have to display the name and filter/cut the output.

echo $(for f in 2 3 4; do exiv2 -Pvn -g Latitude DSC_6503.jpg | grep -v -e Ref | sed -E -e 's/ +/ /g' | cut -d' ' -f $f ; done)
51/1 288176/10000 0/1
This is very tedious. However, I'm reluctant to restore the previous behaviour. Your thoughts/input are welcome and appreciated.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Alan Pater over 6 years ago

How about adding a "-k" option that only returns the value for the specified key?

While that would not restore the behaviour of 0.21, it is a bit more intuitive.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

Good Idea, Alan. -k (--keep) preserves timestamps. -K (--key) is available to implement your idea.

I've found the change from -g key to -g match: http://dev.exiv2.org/issues/0000727

That was changed years ago, so we should not revert this. I feel it's a good idea to keep -G available for some grep related purpose for the future. So -K (--key) Key looks like the way to go. Let's hear from Oliver before we decide. If we're in agreement, I'll raised a "Feature" issue and reference this discussion. The implementation is almost certainly a tiny change.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Oliver P over 6 years ago

don't worry about breaking my script - I can continue using 0.21.1 with that. I'm just looking for a future-proof way to continue using the same functionality

echo $(for f in 2 3 4; do exiv2 -Pvn -g Latitude DSC_6503.jpg | grep -v -e Ref | sed -E -e 's/ +/ /g' | cut -d' ' -f $f ; done)
is definitely not as nice as a simple --key option, so I'd vote for that :-)

Oliver

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

I think we're all in enthusiastic agreement and let's say "Thank You" to Alan for nominating this proposal.

Feature request logged as #1053 http://dev.exiv2.org/issues/1053

When -K is used, -g will be ignored. Multiple -K values may be given (just as multiple -g values are allowed).

Robin

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

I'm having a nice afternoon cup of coffee and thought of a less brutal work-around without the for loop:

666 rmills@rmillsmbp:~/Pictures/2015/Windsor $ exiv2 -Pvn -g Latitude DSC_6503.jpg | grep -v -e Ref | cut -d' ' -f 2-
                 51/1 288176/10000 0/1
667 rmills@rmillsmbp:~/Pictures/2015/Windsor $ 
It's still ugly and tedious, particularly if we need sed to chop out the useless white space.
665 rmills@rmillsmbp:~/Pictures/2015/Windsor $ for k in Latitude Longitude Altitude ; do echo -n "$k: " ; exiv2 -Pvn -g $k DSC_6503.jpg | grep -v -e Ref | cut -d' ' -f 2- | sed -E -e 's/^ +//'; done
Latitude: 51/1 288176/10000 0/1
Longitude: 0/1 362142/10000 0/1
Altitude: 18/1
666 rmills@rmillsmbp:~/Pictures/2015/Windsor $
I have the grep option compiled into the code on the Mac. We should be able to specify the pattern ^...$ pattern as in:
exiv2 -pa -g "^Exif.GPSInfo.GPSLatitude$" DSC_6503.jpg
Sadly shows no output. Can't be bothered debugging this. Much easier to implement -K option.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Alan Pater over 6 years ago

Is it too late to change my suggestion? I had missed that -k was already in use.

How about adding the "single key" option to the -P switch? Then Oliver's script could simply use -PvK ...

There is already the -Pk combination which prints out all keys.

Might have been better to assign -PK to all keys and -Pk to a single key, but it's likely not a good idea to change that.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

It's never to late to change! Oliver only has to change the -g to -K and he's done.

I prefer the [-K key]+ option for the following reasons:

  1. I think most people use the -pmode and not the -Pflg method to request reports.
  2. -K Key is independent of -pmode and -Pflg options ("orthogonal" in engineering-speak)
  3. The user may wish to specify multiple -K Key options and I'm not sure your proposal can deal with that.
  4. The -K Key option will cause values to be reported in the order of -K Key requests. Mind you that's an artefact of the implementation, however it's a useful artefact.
  5. What lead us into this was Steve's request to report multiple keys. Let's not return all the way to having only a single Key.

Oliver. Do you have an opinion about this?

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

r3684 and r3686. ^ and $ regex feature now works:

$ exiv2 -pa -g "^Exif.GPSInfo.GPSLatitude$" DSC_6503.jpg
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 28.81760' 
$ exiv2 -pa -g "^Exif.GPSInfo.GPSLati" DSC_6503.jpg
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 28.81760' 
$ exiv2 -pa -g "Latitude$" DSC_6503.jpg
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 28.81760' 
$ 

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Oliver P over 6 years ago

Great, thanks!
So will both options -g "^KeyName$" as well as -K "KeyName" be included in Release 0.25?
To me this is no urgent matter, and while I can test with a developer build, I'd prefer relying on a release.
Any plan when 0.25 will be released?

Oliver

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

I expect both -K and -g grep (with ^ and $) to ship in v0.25. Thomas S is currently working on #1024 to provide regex support http://dev.exiv2.org/issues/1024 I have to thank Thomas for discovering why ^ and $ were not working.

The team is having a meeting on Saturday week (2015-04-25) to discuss v0.25. I'll put the meeting notes on the forum. I don't want to guess when v0.25 will be released. June maybe? I don't know.

v0.25 has been delayed for the usual reason. We are totally dependant on unpaid volunteers who have other priorities in their lives. Sometimes we do the impossible quickly. Sometimes we don't! v0.25 is in the second category. It has been code complete since December.

I retired last year and, among other things, spend many happy hours talking on the forum to folks like you. So, our on-line support is usually quick (if I know the answer). However making a release involves the whole team and goes through various processes. svn://dev.exiv2.org/svn/trunk/website/Checklist.txt

http://dev.exiv2.org/projects/exiv2/wiki/_Robin_Mills_

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Oliver P over 6 years ago

Thanks for your answers and quick support!

I fully understand and appreciate the fact that you are all volunteering to code exiv2, and am very grateful to be able to make use of it! It feels quicker than exiftool, and I appreciate being able to easily get to the "vanilla" values easily (which is a lot more difficult in exiftool). June would be great - like I said, I'm in no hurry - we just use the script to show customers how they can extract GPS data from images (we don't use it in any production environment or so).

by the way, I enjoyed your lightning presentation on your wiki page - directly related to what I do for a living: [[http://www.foolography.com]]

Oliver

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

Thanks for your very nice words. I really enjoyed the Python Conference. Very nice weekend.

I attended "The Photography Show" at the NEC on the Monday. Oh, I wish I'd known you were there. I've registered with your web-site. I have a Nikon D5300 with a Sigma 18-250 f2.8 Lens. Really like the camera. I bought it because it has built-in GPS. In what way is the Unleashed Dx000 better than the built-in GPS?

Phil is a member of Team Exiv2. He's "Professor Metadata". Probably the world's leading expert in the field. ExifTool is very nice - however it requires Perl. Could you use ExifTool on an embedded controller with no operating system? I doubt it. For sure, it'd be a build challenge and require more memory and a beefy CPU. So we don't compete with ExifTool - we're happy cousins!

The reason I became involved with Exiv2 was for GeoTagging. In 2008, Exiv2 was a Linux only thing and I wanted to do the geotagging in Python (to learn Python) on Mac (and Windows). The team has grown from about 3 (Andreas, Gilles and Brad) to 13 now. It's been a rewarding adventure.

Beautiful day in England. I'm going out to cut the grass. BBQ at my son's place for dinner this evening. It's nice to be retired.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Oliver P over 6 years ago

What a shame you missed us. But Monday was by far the busiest day for us, and to be honest - the only busy day.

You could probably tell me more about why the Unleashed Dx000 is better than the D5300, if you're using the D5300 with Geotagging turned on in real life! I bought the D5300 for testing as well, and it's a great camera! But I gave it to my father for "normal use" - and found out that he actually turns the GPS off all the time, since it drains the battery of the camera so quick that it's much more of a bother than a feature he likes to use. I suppose most customers have made the same experience, which is why Nikon removed the GPS from the successor the D5500...

But apart from battery usage (the Unleashed Dx000 uses very very little power from the camera battery, and only while you're actively using the camera), there are several other advantages:
It's compatible with any Bluetooth GPS on the market, so you can not only choose the GPS you want to use it with (whether it's a cheap one, or professional grade precision GPS for several thousand Euro), but you can also upgrade the GPS at any time, without having to upgrade the whole system - in your case the entire camera. Best of all: you don't have to wait for Nikon to integrate a newer GPS chipset into a camera! You don't even have to wait for us to update our products, but can always get the newest 3rd party GPS you can find, or of course you can keep using that old Bluetooth GPS that you might still have lying around in your "unused gadgets box" :-)
The Built-in GPS of the D5300 is also pretty slow (from what I've heard, and have tested in my few tests), so you have to wait for it to get a fix before being able to take geotagged photos. With our system, you leave the GPS on all the time (after turning it on at the beginning of the day, or at the beginning of your outing), and whenever you start using the camera, the Unleashed will only need to establish the bluetooth connection, which only takes 5 seconds or so. Even that first fix will be so much faster than what you're used to on the D5300, since an external GPS typically has a larger antenna, and much less electronics that might be causing interference, compared to the packed DSLRs.
Another feature we have is that our device remembers the last known position for 30 minutes - even if the GPS loses its fix - for example when you go indoors. Then you'll still have the geotags from outside the door.
The disadvantage of our "external device" is almost non-existant, since it's such a tiny, flat device on the side of the camera, that its never in the way while taking photos, or packing the camera into your bag - very unlike other GPS devices that sit on the hotshoe and have a cable plugged into the camera...

I also do all my work on a mac, so I appreciate your work that exiv2 works on the mac too, and since so many of my customers use windows, I'm glad it also works there :-)
I probably wouldn't try running exiftool in an embedded device, but luckily I don't have to - right now we don't actually have to handle metadata in our hardware - that's done by the Camera itself. Still, of course for its intended purposes, exiftool is an amazing tool.

Anyway, I still have to do a little more work before I can go outside and enjoy the beautiful weather here! I still have a few more years to go before my retirement ;-)

Greetings from Berlin!

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills over 6 years ago

Berlin or Weisbaden? I've been to both. I worked for GE in the 80s and they had an office there. Beautiful Hotel. The Royal George?

After I asked what's better about the Dx000, I had a more careful look on your web site. What you have is much better than the GPS built into camera. I'm not bowled over by the GPS in the camera. I have a couple of batteries for the camera and power it up in the morning and don't turn it off all day - except to change the battery. However, it doesn't always geotag. It has a "recording" mode and you can extract the GPX and merge later. I bought the D5300 to escape the bother of GPX/Merge.

Incidentally, I added a sample application geotag.cpp to Exiv2 a couple years ago to do the GPX/Exif merge dance. I haven't used it because my python script (using pyexiv2) has been working perfectly since I wrote it in 2008. And to be honest, I haven't used geotag.cpp enough to be totally certain that it's 100% perfect. There's always something that seems more important.

I'd be happy to come and work with you for a day on your stand at NEC if you decide to go there again. No charge. Just to talk to folks. You can buy me lunch or something.

RE: commandline -Pv -g retrieving a single Tag value no longer works the same in 0.24 - Added by Robin Mills almost 6 years ago

Hey Oliver:

A brochure arrived in the mail today about "The Photography Show" in Birmingham March 19 .. March 22 2016. Are you attending? My offer to spend a day on your stand is good.

Robin

    (1-17/17)