I know how to render one image via Python and get an output with Blender's compositor.
What if I need it to render 100 images for me with numerical names e.g: img_1
, img_2
, img_3
etc.?
Give me please an example of a working script via Ubuntu terminal and Python sys.argv?
Can I for example setup compositor nodes, and then simply render scene and get composited render as a result render?
Python code for rendering 1 image:
import bpy
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:]
current_frame_path = argv[0]
print(argv)
ob = bpy.context.active_object
scene_rd = bpy.context.scene.render
scene_rd.filepath = current_frame_path
bpy.ops.render.render(write_still=True)
Shell script for rendering n
images
#!/bin/bash
imgs_cnt=n
output_frame_path='RenderedImages/img'
for (( i=1; i<=imgs_cnt; i++ )); do
echo "Rendering frame ${i}/${imgs_cnt}..."
(
cd /path/to/model/
blender --background Model.blend --python Render.py-- "${output_img_path}/img_${i}.png"
)
echo "Image ${i}/${imgs_cnt} has been rendered"
done
Here's an example for what I'm trying to do:
This is an automatically generated scene with plants, and I render it via executing shell
script in terminal. It use 3 python scripts for blender. 1st script is for generating the scene, it places objects on the scene with different location and rotation settings and check if objects are intersected (to avoid clipping). 2nd script is for rendering scene. 3rd script isn't yet ready but it will be generating a mask for generated scene via cryptomatte.
As a final result I want blender to output me 2 images into 2 different directories. 1st for the original images and 2nd for mask annotations.
blender -b -f ${i} -o "${output_img_path}/img_###.png"
When useing--
make sure it is clearly separated by spaces. See blender.stackexchange.com/questions/6817/… Would be a lot quicker to copy images from one render than to render each. $\endgroup$