# Howto get the filepath of a rendered animation frame with python

I want to modify every frame in an animation after it has been saved as an image. Since bpy.data.images["Render Result"] doesn't have associated data I need to load it from disk.

How do I get the path of the last rendered frame in a render_post handler?

The filepath is stored in:

bpy.context.scene.render.filepath


However there is a function to find the output filename for a frame (the same function blender users internally).

output = bpy.context.scene.render.frame_path(frame=10)


example use:

>>> bpy.context.scene.render.filepath = "/test/some_###_anim.png"
>>> bpy.context.scene.render.frame_path(frame=10)
'/test/some_010_anim.png'


You'll probably want to use context.scene.render.filepath and append the frame number with (using str.zfill(4) where str is the frame number as a string and 4 is the number of digits), and extension using context.scene.render.image_settings.file_format, converted to lower case (using str.lower()).

• What about '#' in the output filepath? – Maccesch Oct 15 '13 at 13:09
• '#' indicates padding, so you could count the number of '#'s after the last slash (in case folder names have hashes) and use that instead of 4 – Greg Zaal Oct 15 '13 at 13:25
• You'd also have to remove the hashes from the output path using str.replace('#', '') – Greg Zaal Oct 15 '13 at 13:32
• Could you update your answer with a complete code example for all this please? – Maccesch Oct 15 '13 at 13:39
• Now that would make it too easy wouldn't it ;) Figuring it out by yourself will teach you something. If you're still stuck tomorrow then I'll code it for you. – Greg Zaal Oct 15 '13 at 18:05

The expression you want is bpy.context.scene.render.frame_path()

Calling frame_path without specifying a frame uses the current frame.

import bpy

def handle_render_write(scn):
print(scn.render.frame_path())

bpy.app.handlers.render_write.append(handle_render_write)