Question about using libexif or similar to edit metadata

Started by aprofiti, March 20, 2019, 09:27:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

aprofiti

I would like to edit EXIF section of an image directly in-camera (mainly for manual lenses) and because we are not currently aware how Canon code handle this, I made a research and found libexif which is capable of working on saved pictures (jpeg).

There are other library which are able to open CR2 files (libtiff, exiv2,libraw, libopenraw...) and process raw/metadata, but if I didn't understand wrong they only allow to parse IFD without be able to save metadata to the original picture.

Libexif allow to manage directly files in JPEG format but not TIFF (an old patch can be found but doesn't seems to be merged) or CR2 (which is TIFF based); reading the documentation (not so much details can be found) it appears to be able to work on a passed memory buffer.

I'm not sure what should be done after editing that memory buffer and write back changes on disk.
I imagine that there are some offset/reference sparse through the file, so replacing directly that part of the file with the new one is not possible... Anyone know how exiftool or exiv2 manage this step?

@a1ex may be feasible/useful to create a module which is able to edit metadata in-camera?

Is anyone familiar using these libraries and can provide support?

a1ex

Not familiar with it.

If you can get away with patching some integer value here and there, that should be doable pretty quickly (with seek aka FIO_SeekSkipFile). Otherwise, you (or the library) will have to rewrite the entire file, which is slow.

Changing EXIF in camera at capture time... is not exactly something I've studied, and not a high priority for me right now, but should be doable, as everything happens on the main CPU. Some of the metadata comes from the MPU; that one can probably be adjusted with a MITM "attack" (i.e. altering MPU messages during photo capture).

aprofiti

Thanks for the reply a1ex; you just confirmed a doubt I had about TIFF based files.

Unfortunately patching for Lens Name besides focal length and aperture, is something which usually require more "space" than the one  reserved for the default value when picture is created...

Rewriting the whole file is not a so feasible way for daily usage, considering also there isn't direct support for CR2 in libexif making things a couple of order more difficult, especially without a good experience on handling this file format.

Maybe just injecting a fixed longer name using ML and then rewriting that part on file could be something to start from (not considering it is a superfluous work comparing to write "correct" data directly), but will require a bit of understanding about image creation process... definitely must be set aside for now

EDIT: Just reading again MPU message thread and format.
Is a fake lens name accepted with a crafted message if no lens chip is present?
Is there a hook for MPU message injection already?