Advertisement
thureinfree

temp code

May 9th, 2023 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import OpenEXR
  2. import Imath
  3. import os
  4.  
  5. def extract_metadata_from_exr(filename, metadata_key):
  6.     """Extract metadata from an EXR file."""
  7.     exr_file = OpenEXR.InputFile(filename)
  8.     header = exr_file.header()
  9.     return header[metadata_key]
  10.  
  11. def get_average_render_time(directory, prefix, extension=".exr"):
  12.     """Get average render time from a sequence of EXR files."""
  13.     total_time = 0.0
  14.     count = 0
  15.  
  16.     # Loop over files in directory
  17.     for file in os.listdir(directory):
  18.         if file.startswith(prefix) and file.endswith(extension):
  19.             full_path = os.path.join(directory, file)
  20.             render_time = extract_metadata_from_exr(full_path, "exr/renderTime_s")
  21.            
  22.             if isinstance(render_time, float): # Ensure the metadata is a float
  23.                 total_time += render_time
  24.                 count += 1
  25.  
  26.     return total_time / count if count != 0 else None
  27.  
  28. directory = "."  # current directory
  29. prefix = "image." # prefix for your sequence
  30.  
  31. average_time = get_average_render_time(directory, prefix)
  32. if average_time:
  33.     print(f"Average render time: {average_time} seconds")
  34. else:
  35.     print("No EXR files with the specified prefix found or missing metadata.")
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement