So, I made a little script that allows to store custom x and y resolution in camera.data.
I have a function (ccr_handler) that checks if the current scene.camera has custom resolution and in that case it changes the scene.resolution_x and _y to the stored values.
I call this function with:
bpy.app.handlers.depsgraph_update_pre.append(ccr_handler)
When I switch Camera everything works as expected: the scene resolution is changed accordingly. It also works when binding cameras to timeline markers. Changing frame or playing viewport animation show the resolution changing.
But now the issue: it doesn’t work when I launch an animation render, which is actually the main reason I made this script since the beginning. All the frames are output at the resolution currently set when I hit Ctrl+F12.
What am I missing?
Checked: doesn’t work.
The handler actually works during rendering, I put a couple of “print()” commands that get executed in the terminal. The problem is that:
If that doesn’t work at this point I only know workaround (which doesn’t mean there is no solution).
you can write a function on your own that will render each frame after frame and save it as an image. like that the rendering will be interrupted and you can update your resolution in between.
Something like
for frame in frames_to_be_rendered:
scene.render.resolution_x = cam.data[‘mycustom_xres’]
render_single_image(frame)
render_single_image = your function that will render the frame and output it with the right name to the output folder
I thought of trying the single-render approach, but afaik it freezes the UI, which is not very nice…
I tried scene.render.resolution_x = cam.data[‘mycustom_xres’]
and even bpy.data.scenes[“Scene”].render.resolutionx = cam.data[‘mycustom_xres’]
with explicit scene from data, not context.
Nothing works
I also put in bpy.ops.scene.refresh()
bpy.data.scenes[“Scene”].update()
bpy.data.images.update()
bpy.context.view_layer.update()
Nothing…
Notice that in the handler I put print (“Scene and camera:”, scene.name, scene.camera.name)
and it outputs the right values, so it’s not a matter of wrong variables
One thought: it is possible that what I am trying to achieve is deliberately unallowed. The reason is that if you are rendering in a video format changing resolution is infeasible.
So the right question now is: where to find the documentation for such an undocumented topic?