AcademySoftwareFoundation / openexr

The OpenEXR project provides the specification and reference implementation of the EXR file format, the professional-grade image storage format of the motion picture industry.
http://www.openexr.com/
BSD 3-Clause "New" or "Revised" License
1.62k stars 608 forks source link

update metadata without rewriting the entire file #1721

Open dekekincaid opened 4 months ago

dekekincaid commented 4 months ago

It would be nice to have the ability to update metadata on an EXR without rewriting all the channels in a file.

More specific use cases for this:

peterhillman commented 4 months ago

Have you tried exrstdattr instead of OIIO? That's much faster and less memory intensive because it doesn't decode the pixel data, just writes a new header then copies the compressed image data chunks into the new file. You would need to create a temp file then rename over the original, but that can be used to guarantee you don't end up with a corrupt file if the metadata modification gets interrupted.

It could be possible to modify attributes in place in the header, but only if they stay exactly the same size, and you can't insert, remove or rename attributes that way. If the header size changes, any tool would have to move the rest of the file by reading it in and writing it back out, which is what exrstdattr does anyway.

dekekincaid commented 4 months ago

Yes, the idea is similar to ffmpeg, where you can simply "copy" the channels from one file to another without writing every pixel again.

This would also help when using files compressed with DWAA and DWAB, so you do not recompress a lossy image.

lgritz commented 4 months ago

Somebody just added that to oiio trunk (copy without decode for exr files), though it doesn't yet work for the exrcore code path.

But back to the original question -- I'm not sure you could do this without an incompatible change to the file format, but you could imagine a change to the exr file layout spec itself that would make it more amenable to adding metadata "in place" in an existing file.

kdt3rd commented 4 months ago

there is a stubbed function in the core to support in-place edit of metadata (provided you do not change the length of strings or add values, but just updating a float or whatever). However, it is not yet finished, but was a desired tool to finish at some point! You can more easily do the copy without any decode with core, in that there are direct "chunk" read / write routines, completely skipping any decode / encode path, which you'll see me using in the rawPixel-ish functions in the cpp rewrite branch I'm working on currently. Would be lovely to have some contributors