Page 1 of 1

finding embedded mattes in exrs

PostPosted: Sat Jan 18, 2020 7:50 pm
by waltervolpatto
We are working on a huge project that has literally 2000 VFX shots. For some effect we will have multiple versions deliveries.

all VFX are delivered as EXR (zip compressed) and the colorist assist need to find which shots have embedded mattes and which does not have it and flag the shot for the colorist and report back to the editorial staff.

I cannot find any elegant way to do that short or load all the shots in a timeline, go to color page, right click add matte and see if another layer/channel exist.

While this works, it is really tedious and long. prone to errors.

so, i have a two fold questions:
1) I cannot see anywhere in the media page a column for embedded mattes/extra layers, it could be nice if there is one. that shows if a shot has alpha or extra layers and I can flagg it. either I missed entirely or it is simply not there.
2) I still need to solve the problem now, and i was wondering if there is way to python script it something that does two things:
A) find shots within a folder that have extra layer/channels
B) add a flag with color X to that shot.

Any ideas?

Walter.

Re: finding embedded mattes in exrs

PostPosted: Sat Jan 18, 2020 10:04 pm
by iddos-l
I don’t know of a straight way to find embedded mattes data with the API.
When looking in the MediaPoolItem. GetClipProperty(), just like the clip attributes from the menu, there is no information of ext mattes.

But I was thinking, if the exr files with the mattes are bigger in size compare to the ones without, it is possible to catch them with a script.

Re: finding embedded mattes in exrs

PostPosted: Sat Jan 18, 2020 11:44 pm
by roger.magnusson
The current Resolve API can't find the extra channels in the EXR files, just like Iddo says. But, the Fusion API in Resolve can certainly do it. Not sure that's practical though, since you would need to put all the clips on a timeline and have the script create Fusion clips out of each one. Or use a single Fusion comp with a script that loads each EXR sequence from disk instead of from the Media Pool.

Instead I would probably use a command line utility like ffprobe or exiftool to find the clips with the extra channels outside of Resolve and output the filenames to a text file. Then use the text file as an input to a script in Resolve that adds the flag to each clip. No timeline or Fusion clips required.

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 19, 2020 12:11 am
by waltervolpatto
iddos-l wrote:I don’t know of a straight way to find embedded mattes data with the API.
When looking in the MediaPoolItem. GetClipProperty(), just like the clip attributes from the menu, there is no information of ext mattes.

But I was thinking, if the exr files with the mattes are bigger in size compare to the ones without, it is possible to catch them with a script.


unfortunately those are compressed ZIP, all over the place in size, we thought about that....

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 19, 2020 12:12 am
by waltervolpatto
roger.magnusson wrote:The current Resolve API can't find the extra channels in the EXR files, just like Iddo says. But, the Fusion API in Resolve can certainly do it. Not sure that's practical though, since you would need to put all the clips on a timeline and have the script create Fusion clips out of each one. Or use a single Fusion comp with a script that loads each EXR sequence from disk instead of from the Media Pool.

Instead I would probably use a command line utility like ffprobe or exiftool to find the clips with the extra channels outside of Resolve and output the filenames to a text file. Then use the text file as an input to a script in Resolve that adds the flag to each clip. No timeline or Fusion clips required.


I see... Thanks!

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 19, 2020 8:22 am
by Igor Riđanović
Roger's method for flagging clips would work for sure. OpenEXR Python bindings can also read EXR headers. It's easier to use than Exiftool and more OS portable.

Instead of the end user generating a text file and feeding that to a script, it's possible to make a script that goes through all EXR files in a bin and flags any that have auxiliary channels. It becomes a single click operation.

I don't know if this is practical in your use case, but it's also possible to iterate timeline clips and build color page node trees with EXR auxiliary channel mattes already connected.

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 19, 2020 8:24 am
by Igor Riđanović
iddos-l wrote:But I was thinking, if the exr files with the mattes are bigger in size compare to the ones without, it is possible to catch them with a script.


This is highly unreliable because of compression. You can have a case where a file with more channels is smaller in size than a file with fewer channels.

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 19, 2020 9:59 am
by Oyvind Stiauren
waltervolpatto wrote:2) I still need to solve the problem now, and i was wondering if there is way to python script it something that does two things:
A) find shots within a folder that have extra layer/channels
B) add a flag with color X to that shot.


Hi Walter.

I have a python script that basically does that. Right now it's not putting a flag with a specific color on the clip, but rather it's putting a color to the clip. But it should not be very difficult to make it put flags in stead.

The script finds all the EXR clips in video track 1, scans the header of the file for alpha channel and color the clip Orange if they're a match. The script is very crude, and the header detection might not work on all EXR files without modifying the script. I've also only tested it on Linux CentOS.

If you're interested I can PM you the script.

Re: finding embedded mattes in exrs

PostPosted: Wed Jan 22, 2020 11:19 pm
by roger.magnusson
So, I took a deep dive into the OpenEXR specs and made a script in Resolve that can read the OpenEXR channels without any external applications or third party modules. I usually build scripts in Lua instead of Python which means the module Igor mentioned won't work. I have nothing against Python but I like the idea of Lua since it's built into Resolve and it doesn't require installation like Python does on Windows.

After I finally had the script working for OpenEXR v2 multipart files I discover that Resolve/Fusion actually has a scriptable module for this already built-in. :shock: It's called EXRIO, it's not documented except for a few calls in the External Matte Saver.fuse file that BMD includes with Fusion Studio. More info.

With the help of a hex editor and some spying in fusionoperators.dll you can find some of the available functions. Here's a simple Lua script that prints all the parts and channels in an OpenEXR file using EXRIO.
Code: Select all
local exr = EXRIO()
exr:ReadOpen("/Users/rogmag/Downloads/multipart.0001.exr", -1) -- filename, frame

assert(exr:ReadHeader())

for part = 1, exr.NumParts do
   if (exr.NumParts > 1) then
      print("Part: "..select(2, exr:GetAttribute(part, "name")))
   end
      
   for _, channel in ipairs(exr:GetChannels(part)) do
      print("   Channel: "..channel.Name)
   end
end

assert(exr:Close())

Image

Be aware that scripting EXRIO in Resolve is extremely volatile, if you make a mistake Resolve simply quits immediately. But it beats rolling your own like I first did. Oh well, at least I learned a lot about the file format.

Re: finding embedded mattes in exrs

PostPosted: Thu Jan 23, 2020 6:11 am
by iddos-l
Great thanks for sharing

Re: finding embedded mattes in exrs

PostPosted: Fri Jan 24, 2020 7:36 am
by waltervolpatto
Thanks!

Re: finding embedded mattes in exrs

PostPosted: Fri Jan 24, 2020 11:25 am
by Hendrik Proosa
Can you access bins, markers etc Resolve side stuff with Lua too? That would make Walters original request pretty easy then.

Re: finding embedded mattes in exrs

PostPosted: Fri Jan 24, 2020 11:35 am
by roger.magnusson
Yes, all of it is possible now. I'm thinking about doing something with a nice GUI if I find the time.

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 26, 2020 1:53 pm
by roger.magnusson
It's coming along nicely I think. It's an exercise in patience though... :lol:
Anything I should add? I'm thinking I want to keep the GUI simple and not add everything to it. I can see making some variations of it though, like adding the channel names as keywords in the clip metadata.

@BMD, will I get into trouble if I use your icons in the form (the flags)?

Image

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 26, 2020 4:27 pm
by iddos-l
roger.magnusson wrote:It's coming along nicely I think. It's an exercise in patience though... :lol:
Anything I should add? I'm thinking I want to keep the GUI simple and not add everything to it. I can see making some variations of it though, like adding the channel names as keywords in the clip metadata.

@BMD, will I get into trouble if I use your icons in the form (the flags)?

Image


Looks great
When it comes to GUI dev there’s never enough patience!

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 26, 2020 8:59 pm
by waltervolpatto
At the moment that looks extremely slick to me!

(i'm Italian, I can only do spaghetti code!)

Is it operative system dependent?

Re: finding embedded mattes in exrs

PostPosted: Sun Jan 26, 2020 9:45 pm
by roger.magnusson
I once had a C language teacher that called it spaghetti code as well! I think we have the perfect name for a collection of Resolve scripts right there.

Yes, the goal is to get it working on all three platforms.

Re: finding embedded mattes in exrs

PostPosted: Wed Jan 29, 2020 3:05 pm
by roger.magnusson
No script would be worth its name if the script itself was not scriptable. So in addition to the GUI you will be able to execute the same thing from the Terminal/PowerShell/Command Prompt without user interaction. Or from another Lua script inside Resolve or the scripting Console.

Image

Re: finding embedded mattes in exrs

PostPosted: Tue Feb 25, 2020 2:12 pm
by roger.magnusson
I haven't forgotten about this. It's just that there's an elusive bug when using UIManager to display a window with a Tree inside it. It only affects Linux. It's intermittent but gets way worse once you start nesting controls (when the Tree is inside one or more layouts). Impact is severe, when you close the window and hover over another control in Resolve it completely crashes Resolve.

I don't think there's anything I can do about it and what's worse, BMD does not yet offically support this "new" (since Fusion 8) way of creating GUI:s for scripts. If I report it I imagine it will go straight to the bottom of the backlog.

Re: finding embedded mattes in exrs

PostPosted: Tue Feb 25, 2020 2:54 pm
by iddos-l
Maybe release a win/Mac version?
Is it in lua?

Re: finding embedded mattes in exrs

PostPosted: Fri Mar 06, 2020 10:25 am
by roger.magnusson
From my initial smoke test in v16.2 it seems the issue with UIManager on Linux has been silently (or unknowingly?) fixed. Will do more tests before confirming though.

Re: finding embedded mattes in exrs

PostPosted: Fri Mar 06, 2020 7:17 pm
by roger.magnusson
Unfortunately it's still crashing, just not as frequent. Out of about 20 runs it crashed twice. I'll write up a report for BMD and hope they can fix it.

Re: finding embedded mattes in exrs

PostPosted: Thu Sep 17, 2020 9:49 pm
by Jerome Raim
No one likes dependencies, but if you can stomach them, OpenImageIO is a good way to inspect for additional layers/subimages.

Something like this:

Code: Select all
from OpenImageIO import ImageInput

def has_mattes(path_to_probe):

    has_mattes_bool = False

    img_obj = ImageInput.open(path_to_probe)
    spec = img_obj.spec()
       
    if len(spec.channelnames) > 4: ## more than R,G,B,(A)
        has_mattes_bool = True
   
    if img_obj.seek_subimage (1, 0) is True: ## subimages present
        has_mattes_bool = True
   
    img_obj.close()
   
    return has_mattes_bool


PS: Be sure to inspect *not* the first frame as that often is an RGB-only slate