There is, unfortunately, no provision in the APIs of the underlying libOpenEXR 
that we depend on to modify a file "in place" in any way. And the specification 
of the exr file format (its actual bit pattern, I mean, not just the APIs of 
the library) is not especially amenable to modifying metadata in place. This is 
not unique; I'm not aware of any image file format that made it a core design 
principle to allow this to be done easily.

So, yeah, the usual way to do it is to read the whole file in, and write a new 
whole file with whatever modifications you want. This seems really wasteful in 
a huge image file if all you want to do is change one piece of metadata, but it 
is what it is.

The trick with writing a new file and then moving it to the old location only 
when it's done and correct, is the right approach to make sure you don't lose 
data if the script crashes or the write cannot complete for some reason. If 
you're doing this task by using oiiotool, like

    oiiotool myfile.exr --attrib "NewMetadata" "NewValue" -o myfile.exr

it already (always) does the "write temp file and move to requested location at 
the end" trick automatically. (Important caveat: this is a behavior of oiiotool 
itself, not the underlying OIIO APIs.)


> On Sep 7, 2022, at 11:58 AM, Anders Carlsson <anderscarlsso1...@gmail.com> 
> wrote:
> 
> Hello!
> 
> Is there a way in OIIO to modify/inject metadata into an exr without saving a 
> new file? Both oiiotool and the python bindings are of interest.
> 
> Or is the recommended approach for such a thing to have a script that saves a 
> new file, deletes the old one and then moves the new one to the same location?
> 
> Thanks
> 

--
Larry Gritz
l...@larrygritz.com





_______________________________________________
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to