Project

General

Profile

Copy specific tags from JPG to JPG

Added by Nick Henshaw almost 6 years ago

Hi

I'm a new user of exiv2, and new to this forum. I'm using exiv2 on Windows from the command line.

Is there a straight forward way copying a specified set of tags from one JPG to another? Or this could be via a "sidecar" file. But I only want specified tags. I've (perhaps inappropriately) tried using -K parameters when extracting but they seem to be ignored. Perhaps they only work for reporting, not for extracting.

The alternative, reporting then inserting, seems long winded, especially when the values have to be reformatted (e.g. Exif.GPSInfo.GPSLatitude has a different format when reporting from when inserting).

Any help gratefully received.

Nick


Replies (7)

RE: Copy specific tags from JPG to JPG - Added by Robin Mills almost 6 years ago

Nick

You can copy all the metadata from one file to another in the application exiv2.exe, or the sample application metacopy.exe The exiv2.exe -K option applies to reporting Keys. And --grep/-g is a pattern of keys.

You can of course use "the dentist's method" (you pull them out one at a time). Very long winded and, as you're discovered, the output when reporting a key/value may require a little modification before being piped into another command.

Exiv2 outputs values in two forms "vanilla" and "translated". 'Vanilla values' are in effect the data in the file. 'Translated' means that have been made "more human understandable. You can see the different when you print GPS data. 'Vanilla' reveals raw values, and 'translated' massages them into degrees and seconds. Here's an image which I took at Stonehenge in July:

531 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pa --grep GPSInfo http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg
Exif.GPSInfo.GPSVersionID                    Byte        4  2.3.0.0
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 10.69690' 
Exif.GPSInfo.GPSLongitudeRef                 Ascii       2  West
Exif.GPSInfo.GPSLongitude                    Rational    3  1deg 49.59840' 
Exif.GPSInfo.GPSAltitudeRef                  Byte        1  Above sea level
Exif.GPSInfo.GPSAltitude                     Rational    1  97 m
Exif.GPSInfo.GPSTimeStamp                    Rational    3  14:38:55.9
Exif.GPSInfo.GPSSatellites                   Ascii       3  09
Exif.GPSInfo.GPSMapDatum                     Ascii      17  WGS-84          
Exif.GPSInfo.GPSDateStamp                    Ascii      11  2015:07:16
532 rmills@rmillsmbp:~/gnu/exiv2/trunk $ 
If you use the "P = Fine-grained output control", you can skip the type/count information in the output:
532 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -Pkv --grep GPSInfo http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg
Exif.GPSInfo.GPSVersionID                     2 3 0 0
Exif.GPSInfo.GPSLatitudeRef                   N
Exif.GPSInfo.GPSLatitude                      51/1 106969/10000 0/1
Exif.GPSInfo.GPSLongitudeRef                  W
Exif.GPSInfo.GPSLongitude                     1/1 495984/10000 0/1
Exif.GPSInfo.GPSAltitudeRef                   0
Exif.GPSInfo.GPSAltitude                      97/1
Exif.GPSInfo.GPSTimeStamp                     14/1 38/1 5588/100
Exif.GPSInfo.GPSSatellites                    09
Exif.GPSInfo.GPSMapDatum                      WGS-84          
Exif.GPSInfo.GPSDateStamp                     2015:07:16
533 rmills@rmillsmbp:~/gnu/exiv2/trunk $
With a little sed (or python or perl or dos) magic, copy the GPS into a .cmd files which you can apply to another image.
576 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -Pkv --grep GPSL http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg | sed -E -e "s/^/set /" 
set Exif.GPSInfo.GPSLatitudeRef                   N
set Exif.GPSInfo.GPSLatitude                      51/1 106969/10000 0/1
set Exif.GPSInfo.GPSLongitudeRef                  W
set Exif.GPSInfo.GPSLongitude                     1/1 495984/10000 0/1
577 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -Pkv --grep GPSL http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg | sed -E -e "s/^/set /" > foo.txt
So let's get a jpg with no metadata:
577 580 rmills@rmillsmbp:~/gnu/exiv2/trunk $ curl http://clanmills.com/robin.jpg > robin.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8779  100  8779    0     0  10105      0 --:--:-- --:--:-- --:--:-- 25082
581 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pa robin.jpg
582 rmills@rmillsmbp:~/gnu/exiv2/trunk $  
Extract the metadata from Stonehenge into a cmd file
583 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -Pkv --grep GPSL http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg | sed -E -e "s/^/set /" > foo.cmd
And apply the command file to robin.jpg
584 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -mfoo.cmd robin.jpg
And robin.jpg is now at Stonehenge
585 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pa robin.jpg
Exif.Image.GPSTag                            Long        1  26
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 10.69690' 
Exif.GPSInfo.GPSLongitudeRef                 Ascii       2  West
Exif.GPSInfo.GPSLongitude                    Rational    3  1deg 49.59840' 
586 rmills@rmillsmbp:~/gnu/exiv2/trunk $ 

RE: Copy specific tags from JPG to JPG - Added by Nick Henshaw almost 6 years ago

Robin

This is extremely useful. You have hit the nail on its head!

I had not come across the parameters you describe, (nor have I ever used sed, but am happy to learn). It is amazing what can be achieved with -Pkv and sed -E -e "s/^/set /" !!

Thanks again for your very helpful response.

Nick

RE: Copy specific tags from JPG to JPG - Added by Robin Mills almost 6 years ago

Nick

This is a rather interesting idea. I've raised a Feature request #1137 for which I've submitted the code r4044. I've added the option -PV as an additional fine grained output option to mean: "value" and insert the word 'set ' at the beginning of the command line. So:

$ exiv2 -PkV --grep GPSL http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg 
set Exif.GPSInfo.GPSLatitudeRef                   N
set Exif.GPSInfo.GPSLatitude                      51/1 106969/10000 0/1
set Exif.GPSInfo.GPSLongitudeRef                  W
set Exif.GPSInfo.GPSLongitude                     1/1 495984/10000 0/1
So, you don't have to have 'sed' to insert the word 'set ' at the start of every line.

I've also modified the option -mfilename to enable:

-m-
to be standard input. So it's now possible to pipe the metadata from one image to another (while using the -K and -g filters if you wish).
$ exiv2 -PkV --grep GPSL http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg | exiv2 -m- robin.jpg
$ 
Examining the metadata shows:
$ exiv2 -pa robin.jpg
Exif.Image.GPSTag                            Long        1  26
Exif.GPSInfo.GPSLatitudeRef                  Ascii       2  North
Exif.GPSInfo.GPSLatitude                     Rational    3  51deg 10.69690' 
Exif.GPSInfo.GPSLongitudeRef                 Ascii       2  West
Exif.GPSInfo.GPSLongitude                    Rational    3  1deg 49.59840' 
$
I always have sed on my command-line in Windows, because I install Cygwin and add c:\cygwin64\bin to my Windows path. There's quite a lengthy discussion about 'sed for Windows' here: http://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe

RE: Copy specific tags from JPG to JPG - Added by Nick Henshaw almost 6 years ago

Hi Robin

Yes the two additional features that you describe would make it a very easy seamless process to move tags around with no need for intermediate files. I would be a happy user of them!

I am not familiar with the Change Request / Development / Release process for exiv2. Do I just track the chnage using your hyperlinked tag #1137? Is it likely that these features will be generally available in a new version some time soon?

If not I will get hold of sed for Windows for the moment.

Thanks again for your help.

Nick

RE: Copy specific tags from JPG to JPG - Added by Robin Mills almost 6 years ago

I've put the changes into the code and they are on the trunk. You have to build the trunk to get them. Our next release will be v0.26 and it should be available about Easter next year.

One of the features of v0.26 is to enable users request a build (of trunk, or selected branches) and it'll be done for you by the build server. I'm still working on this.

I've been using cygwin for about 10 years. It's very solid. In that article on stackoverload, somebody mentioned a standalone sed.exe which they said was very good.

RE: Copy specific tags from JPG to JPG - Added by Robin Mills almost 6 years ago

Nick

You can now download builds of Exiv2. There is a daily (weekly and monthly) build: http://exiv2.dyndns.org:8080/userContent/builds/

Currently, I'm building Cygwin/MacOS-X/Linux/msvc (2005/8/10/12/13/15). You can pull down the build of interest and follow the instructions in the bundle's ReadMe.txt.

I intend to add MinGW (perhaps next week).

Happy Holidays. Best Wishes for 2016.

RE: Copy specific tags from JPG to JPG - Added by Nick Henshaw almost 6 years ago

Robin

Thanks for this. I'll set aside some time and take a look.

Happy New Year

Nick

    (1-7/7)