updating LensType tag with exiv2/exiftool for Canon RF lens

I am finally able to enjoy cr3 files straight from camera with the new darktable 3.8. However I can see a bit of confusion in my library:

2022-01-20_23-51

One of the reason is that only the most recent files are cr3, the others are dng converted with dnglab.

The most problematic are the photos that dt thinks that have been taken with the 50mm f1.2 – which I don’t have. In fact all the 50mm photos are all taken with the same 50 mm f1.8. The problem is that lens corrections are not automatically applied in this case.

So I thought to manually fix the offending tag but I’m unable to do so, both with exiv2 and exiftool.

Example:

$ exiftool -s -G 20211009_CRP2746.cr3 | grep -i lens
[MakerNotes]    LensType                        : Canon RF 50mm F1.2L USM or other Canon RF Lens
[MakerNotes]    RFLensType                      : Unknown (280)
[MakerNotes]    LensModel                       : RF50mm F1.8 STM
[MakerNotes]    LensDriveNoAF                   : Focus search on
[MakerNotes]    ShutterReleaseWithoutLens       : Enable
[MakerNotes]    RFLensMFFocusRingSensitivity    : Unknown (-1)
[MakerNotes]    RetractLensOnPowerOff           : Enable
[EXIF]          LensInfo                        : 50mm f/0
[EXIF]          LensSerialNumber                : 9501002125
[Composite]     Lens                            : 50.0 mm
[Composite]     LensID                          : RF50mm F1.8 STM
[Composite]     Lens35efl                       : 50.0 mm (35 mm equivalent: 50.1 mm)

$ exiv2 -pa --grep lens/i 20211009_CRP2746.cr3
Exif.Photo.LensSpecification                 Rational    4  50/1 50/1 0/1 0/1
Exif.Photo.LensModel                         Ascii      16  RF50mm F1.8 STM
Exif.Photo.LensSerialNumber                  Ascii      11  9501002125
Exif.CanonCs.LensType                        Short       1  Canon RF 50mm F1.2 L USM
Exif.CanonCs.Lens                            Short       3  50.0 mm
Exif.CanonFi.RFLensType                      SShort      1  (280)
Exif.Canon.LensModel                         Ascii     138  RF50mm F1.8 STM

The offending tag is Exif.CanonCs.LensType; I tried to delete it or change it but I can’t do that:

$ exiftool -v -LensType="Canon RF 50mm F1.8 STM" 20211009_CRP2746.cr3
Warning: Can't convert Sony:LensType (not in PrintConv)
======== 20211009_CRP2746.cr3
Rewriting 20211009_CRP2746.cr3...
  FileType = CR3
  FileTypeExtension = CR3
  MIMEType = image/x-canon-cr3
  Editing tags in: MakerNotes 
  Rewriting Movie
  Rewriting UUID-Canon
  Rewriting IFD0
  Rewriting ExifIFD
  Rewriting MakerNoteCanon
  Rewriting MakerNotes
  Rewriting CanonCameraSettings
  Rewriting CanonFocalLength
  Rewriting CanonShotInfo
  Rewriting TimeInfo
  Rewriting CanonFileInfo
  Rewriting CropInfo
  Rewriting CustomFunctions2
  Rewriting CanonCustom2
  Rewriting AspectInfo
  Rewriting ProcessingInfo
  Rewriting MeasuredColor
  Rewriting AFMicroAdj
  Rewriting VignettingCorr2
  Rewriting LightingOpt
  Rewriting LensInfo
  Rewriting AmbienceInfo
  Rewriting MultiExp
  Rewriting HDRInfo
  Rewriting GPS
  Rewriting MovieHeader
  Rewriting Track
  Rewriting TrackHeader
  Rewriting Media
  Rewriting MediaHeader
  Rewriting MediaInfo
  Rewriting DataInfo
  Rewriting DataRef
  Rewriting SampleTable
  Rewriting Track
  Rewriting TrackHeader
  Rewriting Media
  Rewriting MediaHeader
  Rewriting MediaInfo
  Rewriting DataInfo
  Rewriting DataRef
  Rewriting SampleTable
  Rewriting Track
  Rewriting TrackHeader
  Rewriting Media
  Rewriting MediaHeader
  Rewriting MediaInfo
  Rewriting DataInfo
  Rewriting DataRef
  Rewriting SampleTable
  Rewriting Track
  Rewriting TrackHeader
  Rewriting Media
  Rewriting MediaHeader
  Rewriting MediaInfo
  Rewriting DataInfo
  Rewriting DataRef
  Rewriting SampleTable
  Rewriting XMP
Nothing changed in 20211009_CRP2746.cr3
    0 image files updated
    1 image files unchanged

I get a bit more info with exiv2:

$ exiv2 -vk -M'del Exif.CanonCs.LensType' 20211009_CRP2746.cr3
File 1/1: 20211009_CRP2746.cr3
Del Exif.CanonCs.LensType
Exiv2 exception in modify action for file 20211009_CRP2746.cr3:
Setting Image comment in BMFF images is not supported

$ exiv2 -vk -M'set Exif.CanonCs.LensType "Canon RF50mm F1.8 STM"' 20211009_CRP2746.cr3File 1/1: 20211009_CRP2746.cr3
Set Exif.CanonCs.LensType "Canon RF50mm F1.8 STM" (SShort)
Warning: Exif.CanonCs.LensType: Failed to read Short value "Canon RF50mm F1.8 STM"
Exiv2 exception in modify action for file 20211009_CRP2746.cr3:
Setting Image comment in BMFF images is not supported

Exif.CanonCs.LensType is not a text field but a number, as you can see with exiv2:

Exif.CanonCs.LensType Short

Both exiv2 and exiftool “translate” this number in a more readable name. I think for this, they use the number but also other data (like focale length), because this number is not unique between different lens.
In particular, Exif.CanonCs.LensType is always the same 61182 number for all RF lenses (Exif.CanonFi.RFLensType contains a different number for each RF lenses however).

Anyway, you won’t be able to change it like this (and you probably shouldn’t try to modify you cr3 file).

I encounter the same problem you have with Canon RF50mm F1.8 STM being recognised as Canon RF 50mm F1.2L USM. I described here what I currently do to corrected this (each time I import new files taken with this lens, for now):

@paperdigits wrote this .exiv2 file could be filed with another metadata parameter (which could avoid doing the cumbersome steps I explained), but I must admited I didn’t manage to make it work.

1 Like

If like me you were wondering why exiv2/darktable relied on Exif.CanonCs.LensType while there are other fields with the written name (like Exif.Photo.LensModel = RF50mm F1.8 STM), it is because these are new fields (see "Canon EF 80-200mm f/4.5-5.6 II" identified as "Canon EF 80-200mm f/4.5-5.6" · Issue #1906 · Exiv2/exiv2 · GitHub).

There is this PR for exiv2 about Canon lens identification: https://github.com/Exiv2/exiv2/pull/1692
It has already been merged in june, but not in last stable release of exiv2 V0.27.5.

I have been wondering if it would correct this problem: I just tried to compile it and I can confirm it works! It should be in exiv2 V1.00, in a few month hopefully :slight_smile:

Following @Peter comment here, I tried to write in the .exiv2 file : 61182=000.
It does what @Peter described: the lens name in darktable then inherite the Exif.Canon.LensModel, so “RF50mm F1.8 STM” (instead of “Canon RF50mm F1.8 STM” with exiv2 master), like you dng file @aadm. Lensfun is able to recognised it (because there is an alias in the lensfun database, I think). I think I won’t use that solution because I’d rather have 1 name for 1 lens in the end, but it works if it’s purely for lensfun.

1 Like

It also works for Exif recognition in darktable even if you don’t have Lensfun. Glad it worked for your lens.

RF50mm F1.8 STM is, what I know, what Canon DPP4 uses.

Yes, sorry, I not been really clear: you will indeed see “RF50mm F1.8 STM” as lens in darktable! But you will have “RF50mm F1.8 STM” with this ‘trick’ (without “Canon” at the beginning) and “Canon RF50mm F1.8 STM” with the new exiv2 (current master or V1.00), as with other Canon RF lenses.

It’s no a big deal, but you will have two different lenses names in darktable for the same lens, as posted by @addm in the first post.

1 Like

From the exiv2 manpage:


CONFIGURATION FILE                                                                                                                                                                                                
       Exiv2 can read an optional configuration file ~/.exiv2 on Unix systems and %USERPROFILE%\exiv2.ini on Windows (using a Visual Studio build).  Cygwin and MinGW/msys2 follow the unix  convention  and      
       use ~/.exiv2  You can determine the location of the configuration file with the command:                                                                                                                   
                                                                                                                                                                                                                  
       $ exiv2 --verbose --version --grep config_path                                                                                                                                                             
       exiv2 0.27.0.1                                                                                                                                                                                             
       config_path=/Users/rmills/.exiv2                                                                                                                                                                           
                                                                                                                                                                                                                  
       The purpose of the configuration file is to define your own lenses for recognition by Exiv2.  The configuration file is in Windows .ini format and has sections for each of the major camera manufac‐      
       tures canon,nikon,pentax,minolta,olympus and sony.  The lens metadata is stored as a integer called the lensID.  You can change the lens name associated with any lensID.                                  
                                                                                                                                                                                                                  
       $ cat ~/.exiv2                                                                                                                                                                                             
       [nikon]                                                                                                                                                                                                    
       146=Robin's Sigma Lens  <--- The name of your lens                                                                                                                                                         
                                                                                                                                                                                                                  
       You obtain the lensID for your camera with the command:                                                                                                                                                    
       $ exiv2 -pv --grep lens/i http://clanmills.com/Stonehenge.jpg                                                                                                                                              
       0x0083 Nikon3       LensType           Byte       1  14                                                                                                                                                    
       0x0084 Nikon3       Lens               Rational   4  180/10 2500/10 35/10 63/10                                                                                                                            
       0x008b Nikon3       LensFStops         Undefined  4  55 1 12 0                                                                                                                                             
       0x000c NikonLd3     LensIDNumber       Byte       1  146 <--- This number                                                                                                                                  
       0x000d NikonLd3     LensFStops         Byte       1  55

well that worked! I made an .exiv2 with simply 61182=000 under [canon] and now darktable recognizes correctly all the lenses, so lensfun gets activated for all the photos taken with my 50/1.8!

many thanks @EC1000 and @Peter !

PS: I did update a few tags however related to dngs created at various times with dnglab – or cr3 extracted from those dngs later… they were also creating chaos, but now after a bit of tinkering on the command line, e.g.:…

$ exiv2 -vk -M'set Exif.Photo.LensModel "RF50mm F1.8 STM"' canon_50mm_fix_spaces/*.dng
$ exiv2 -vk -M'del Xmp.exifEX.LensModel' canon_50mm_to_fix/*.dng

…I finally have a clean set of files!

1 Like