Be careful, this is a DIRTY solution which might have sideeffects and might even crash Blender...but...on my Macbook - it worked :D
So all perfectionists and 100% people - don't read this - this is NOT for you. But if people are interested in a solution which can work and if you render over night anyway then a few seconds of "sleep" in the code might not be important ;)
First you need a little python script which basically checks which camera is active and sets the resolution of the scene accordingly.
render = scene.render
camera = scene.camera
orig_res_x = render.resolution_x
orig_res_y = render.resolution_y
# ▼ Resolution change ▼
scene.render.resolution_x = int(bpy.data.cameras[camera.name].sensor_width) * 10
scene.render.resolution_y = int(bpy.data.cameras[camera.name].sensor_height) * 10
print("camera is", camera.name)
print ("new res is:", scene.render.resolution_x, "x", scene.render.resolution_y)
print("in pre append now")
print("*" * 50)
print ("script start")
for frame in range(bpy.data.scenes["Scene"].frame_start, bpy.data.scenes["Scene"].frame_end):
print("rendering frame", frame)
bpy.data.scenes["Scene"].render.filepath = "/tmp/%04d.png" % frame
All this python script does is define a function (def) with the name "setRenderResolution".
It then reads the original resolution x and y in the variables orig_res_x and orig_res_y.
Then the next 2 lines after "resolution change" set the render resolution.
So above "resolution change", you should enter YOUR python code to calculate the right resolution depending on your camera settings.
I just set the x and y resolution to sensor.width/height because i am lazy and i don't know the real formula.
I just set a value here to prove that my solution works.
Now how can you change cameras "automatically" in a scene?
That's pretty basic:
Open the timeline, go to a frame of your choice, press "M" -> this will set a marker in the timeline:
Now select a camera of your choice, and choose marker->bind camera to marker.
select another frame in the timeline and select another camera and repeat the steps with create marker and bind the other camera to the marker.
If you now toggle to camera view
and move the timeline over the markers, you will see the different cameras in action and it should now work as you wanted it (of course if you did add the python code for the resolution calculation).
Note: Yes, the solution is pretty dirty because of the sleep statements and because i used bpy.data.scenes instead from context, but it worked for my test render. It might be, that you have to test with other sleep values that it works for you. It might also be that my solution doesn't work at all for you (which i don't hope).
If you do a "normal" animation render, it won't work, that's why i added here the code in the script to render it "manually" but at least it read the frame start and frame end, so hopefully that's good enough.
i know it's a bit hard to see, but you see here the "finder" of a mac (which is the same as explorer in windows) and by watching the preview you can see that the resolution changes of the rendered images.