I have made a movie clip Frame change detector in the compositor, which uses a less than node result to pass a frame or render black out during animation. As I have a boolean value from the node I want to use it to alter the rendered file save as name each time it is black, to a non unique name so that it will be overwritten. Thus I won't accumulate black frames only changed frames.
I first asked ChatGPT and it gave me this script with comments. It runs on my Mac but fails to write a sensible name for the black frames. It doesn't collect the original path to insert in the new file name. I'm not sure if its related to The OS or a mishandling of the
import bpy
import os
# This function will be called every time the frame changes
def update_overwrite(scene):
# Get the current frame number
frame = scene.frame_current
# Get the compositor node tree
tree = bpy.context.scene.node_tree
# Get the node whose output we want to use as input
# In this example, we use the less than operation on the alpha channel of an image
# You can change this to any node you want
node = tree.nodes["Less Than"]
# Get the output socket of the node
socket = node.outputs[0]
# Evaluate the output value of the socket at the current frame
# This will return a single value between 0 and 1
value = socket.evaluate(frame)
# Set the custom property to the output value
scene["overwrite"] = value
# Register the function as a frame change handler
bpy.app.handlers.frame_change_pre.append(update_overwrite)
# Create a global variable to store the original file name
original_file_name = ""
# This function will be called before each render frame
def save_file_name(scene):
# Get the current file name
global original_file_name
original_file_name = bpy.context.scene.render.filepath
# Set the render file path to "overwrite_me"
bpy.context.scene.render.filepath = os.path.join(os.getcwd(), "overwrite_me/")
# This function will be called after each render frame
def restore_file_name(scene):
# Restore the original file name
global original_file_name
bpy.context.scene.render.filepath = original_file_name
# Register the functions as render handlers
bpy.app.handlers.render_pre.append(save_file_name)
bpy.app.handlers.render_post.append(restore_file_name)
I asked ChatGPT to revise the script so that it uses the original path instead of some installed directory, I also asked it to use an if else statement from the result of the less than node in case I had to flip the choice of frame to save.
import bpy
import os
# This function will be called before each render frame
def save_file_name(scene):
# Get the current frame number
frame = scene.frame_current
# Get the compositor node tree
tree = bpy.context.scene.node_tree
# Get the 'Less Than' node whose output we want to use as input
node = tree.nodes["Less Than"]
# Get the output socket of the node
socket = node.outputs[0]
# Evaluate the output value of the socket at the current frame
value = socket.evaluate(frame)
# Decide which value to use based on the output of the 'Less Than' node
# If the output is 1.0, we use the alternate value, otherwise we use the original
alternate_value = 1 if value == 1.0 else 0
# Use the alternate value to set the render file path
if alternate_value == 1:
# Set the render file path to "overwrite_me"
bpy.context.scene.render.filepath = os.path.join(os.path.dirname(bpy.context.scene.render.filepath), "overwrite_me")
else:
# Restore the original file path
bpy.context.scene.render.filepath = os.path.dirname(bpy.context.scene.render.filepath)
# Register the function as a render pre handler
bpy.app.handlers.render_pre.append(save_file_name)
I will include the blend file with the frame change detection, it will need movie clip that includes an edit to work
value = socket.evaluate(frame)
does not exist. $\endgroup$