Overwriting EXIF Data of a Lens in Darktable Using Exiv2 and Lensfun

Overwriting EXIF Data of a Lens in Darktable Using Exiv2 and Lensfun #
When working with images in Darktable, you may sometimes encounter situations where the EXIF data of your lens is incorrect or missing. This can happen when using adapted lenses, legacy glass, or third-party manual lenses. Fortunately, it is possible to overwrite the lens EXIF data using the exiv2
tool along with a configuration file approach. This method ensures that Darktable recognizes the correct lens data and applies the appropriate lens correction from the lensfun
database.
Prerequisites #
Before proceeding, make sure you have the following tools installed on your system:
- Exiv2: A powerful command-line tool for manipulating EXIF, IPTC, and XMP metadata.
- Lensfun: A database used by Darktable for lens correction.
- Darktable: Your preferred open-source RAW image processing software.
Step 1: Identifying the Image’s EXIF Data #
To check the current metadata of an image, use the following command:
exiv2 --print v --grep lens/i IMG_7670.CR2
This will return various lens-related EXIF tags, such as:
0x0016 CanonCs LensType Short 1 161
0x0017 CanonCs Lens Short 3 75 28 1
0x0095 Canon LensModel Ascii 74 28-75mm
0x0000 CanonLe LensSerialNumber Byte 5 0 0 0 0 0
0xa432 Photo LensSpecification Rational 4 28/1 75/1 0/1 0/1
0xa434 Photo LensModel Ascii 8 28-75mm
0xa435 Photo LensSerialNumber Ascii 11 0000000000
Step 2: Configuring Exiv2 for Overwriting Metadata #
Exiv2 allows overwriting EXIF metadata using a configuration file stored in a user-specific directory. First, determine your configuration file location:
exiv2 --verbose --version --grep config_path
This will return an output similar to:
exiv2 0.28.4
config_path=/home/chris/.exiv2
Edit (or create) the configuration file at this location, e.g., /home/chris/.exiv2
with the following content:
[canon]
161=Tamron SP AF 28-75mm f/2.8 XR Di (IF) Macro
Here, 161
represents the internal lens ID used by Canon cameras, and the corresponding value is the corrected lens name.
Step 3: Refreshing EXIF Data in Darktable #
Any image that has already been imported into Darktable will not automatically reflect these changes. You need to refresh the metadata manually.
To reload the metadata for all images:
- Open Darktable.
- Select all images in the Lighttable mode.
- Navigate to Lighttable → Actions on selection → Metadata tab → Refresh EXIF.
Warning: According to the Darktable manual, this action may overwrite some tags and metadata that you have altered in Darktable (such as star ratings). Proceed with caution.
References #
For more details on Exiv2 configuration files, see the official documentation: Exiv2 Manpage
For more information on refreshing metadata in Darktable, refer to the discussion here: Refresh Darktable Database
Conclusion #
Using the exiv2
tool with a user-specific configuration file, you can easily overwrite lens metadata for better compatibility with Darktable’s lensfun
database. This workflow is particularly useful for manual lenses and adapted glass, ensuring that the correct lens profile is applied during processing.
Have you tried this approach? Let me know if you encountered any issues or have alternative methods to share!