Write metadata based on lensinfo

Started by Jeroen, April 19, 2019, 03:22:02 PM

Previous topic - Next topic

Jeroen

Hi,
Completely new to this forum! Trying to find my way in batch files and Exiftool.
I have a Fujifilm X_Pro2 camera, with a few Fujinon lenses but also some vintage lensen, and they have obviously no exif data written in the files.
Only I can decide to set (in the camera setiings) the focal length of the lens.
Now I want to try to automate the lens data before importing in the raw developer software (Capture One), so I want to write a batch file that does the following:

Read all files in directory, and check Lensmake (something like exiftools -Lensmake *)
If Lensmake = FUJIFILM do nothing but process next file
If FocalLenght = 28 then Lensmake = Takumar, Model = etc and proecess next file
If FocalLength = 50 them Lensmake = etc etc and process next file

I know the exiftool -Lensmake parameter, but I do not know how to base the logic of this batch file upon this.
Any help greatly appreciated!
thanks
Jeroen

StarGeek

#1
The thing about exiftool is that it can do most of the batch type commands by itself without having to write a complicated script.

Your example can be run with two commands
exiftool -if "$EXIF:FocalLength#==28" -LensMake=Takumar -LensModel=Model FileOrDir
exiftool -if "$EXIF:FocalLength#==50" -LensMake="Something Else" -LensModel="Some other Model" FileOrDir

These commands check the raw value (the trailing #, see -n (printConv) option) of the EXIF:FocalLength to see if it's 28 or 50 and ignore anything else.  You then set any tag you need to set  (see the EXIF tag names page).

I used the raw values here because it might be easier to deal with.  Without the trailing hashtag, the results would be something like 28.0 mm.  There are a couple other ways to do the compare (using eq or the =~ binding operator) as well.  Replace FileOrDir with the files and/or directories to be processed.

This command creates backup files.  Add -overwrite_original to suppress the creation of backup files.  Add -r to recurse into subdirectories.  If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.

One thing to avoid with exiftool is to use it in a looping script (see Common Mistake #3).  Exiftool's biggest performance hit is the startup time and if you have to run it individually on hundreds or thousands of files, it can take an extremely long time.
* 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).

Phil Harvey

You would need a double == for the comparison:

exiftool -if "$EXIF:FocalLength#==28" -LensMake=Takumar -LensModel=Model FileOrDir
exiftool -if "$EXIF:FocalLength#==50" -LensMake="Something Else" -LensModel="Some other Model" FileOrDir


But be careful that FocalLength# is exactly 50, and not 49.9 or something.

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

StarGeek

* 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).

Jeroen

Many thanks StarGeek and Phil  :) :)
It is certain that it might have taken me a good deal of time to find that out!
Was on a completely wrong track, with command file logic, this looks MUCH better so, wil try to incorporate this, learned something again.

The logic I am looking for is a bit different ;), because when it is a Fujifilm lens, then all necessary Exifdata is there, and I do not want to do anything. Only when it is NOT a Fujifilm make, then these commands have to run. In theory it might happen that there is a Fujifilm lens with a focallength of 28 or 50, but then NO processing is to be done. I think I might be able to figure out now a way to accomplish that. Something along the line of:
exiftool -if "$EXIF:LensMake#==FUJIFILM" do nothing,
else
exiftool -if "$EXIF:FocalLength#==28" -LensMake=Takumar -LensModel=Model FileOrDir

Yes I know that it will not work with 49.9, but that is the one Exifdata I have to set deliberately on the camera when not using a compleely manual lens, meant to set the viewfinder correct, but I use it for this purpose.

Jeroen

Hayo Baan

This can be done quite easily. You just need to use the proper comparison operators; ==, != etc. are for numerical values, eq, ne etc. are for strings.

So in your case case the command would be something like this:
exiftool -if "$EXIF:FocalLength#==28 && $EXIF:LensMake ne 'FUJIFILM'" -LensMake=Takumar -LensModel=Model FileOrDir

In this case you don't need the hash after the LensMake tag name since its a string already. The && stands for and (which you could have used as well  ;)).
Hayo Baan – Photography
Web: www.hayobaan.nl

Jeroen

Again, incredibly fast and helpful reply, many thanks :)
Exiftool is much more powerful than I thought!
As soon as I have time I will try to fiddle with all this, very helpful!
Jeroen

Hayo Baan

Hi Jeroen,

Graag gedaan :)

If you know a little perl, you'll be able to perform even more sophisticated manipulations than the rather straightforward example you now presented ;D
Hayo Baan – Photography
Web: www.hayobaan.nl

Jeroen

Yes, I now see that is has some true scripting capabilities, not a command-only exe.
But for now I am more than satisfied with what I tried to accomplish, script is already almost ready, thanks to this jumpstart :)
In this case I do not really need much more sophistication, because the camera adds the Exifdata for the picture taken, the only data I miss are the lens data, which I can provide this way. After this the only data that still lacks are the f-stops used per picture, but in order to know these, I have to remember them or write them down, old fashioned ;D
Jeroen