Using blender batch render from command line

I made a simple script blenderBatchRendering.sh on linux ubuntu

#!/bin/bash
#Launch blender Batch Render
/home/ubuntu/blender-4.2.0-linux-x64/blender -b /media/XXXXXXXXXXXXXXX/Project/blender/aaa/aaa.blend -o /media/XXXXXXXXXXXXXXX/Project/blender/aaa/render/aaa -f 1

It’s there a way to render from command line spicify camera name ?

One way to solve this is to create a small python file that contains code to handle the camera and use this added at the end

–python camera.py

And if you want to switch between several cameras you could add a sys argument parser to pass the cameraname in the same.

camera.py content:

import bpy, sys
camera_name = sys.argv[sys.argv.index("--") + 1]
bpy.context.scene.camera = bpy.data.objects[camera_name]

so your command should be

#!/bin/bash
#Launch blender Batch Render
/home/ubuntu/blender-4.2.0-linux-x64/blender -b /media/XXXXXXXXXXXXXXX/Project/blender/aaa/aaa.blend -o /media/XXXXXXXXXXXXXXX/Project/blender/aaa/render/aaa -f 1 --python camera.py -- NameOfCamera

Im too tired to boot into ubuntu right now but it should work…in theory

Hi,I add python command line ,stay render active camera,I try change name of camera.

File "/home/ubuntu/camera.py", line 2
    camera_name = sys.argv[sys.argv.index("--") + 1]
          ^^^^
SyntaxError: invalid syntax

I have already a trick,only we can render animation one camera from multiple views using set key to camera.

Hmm not sure whats happening there.
I tested this on windows and it worked:

"C:\Program Files\Blender Foundation\Blender 4.2\blender.exe" -b "C:\Users\r\Desktop\temp\render_scene.blend" ^
--python "C:\Users\r\Desktop\temp\camera.py" ^
-o "C:\Users\r\Desktop\temp\output\render_" -f 1 -- cam2

Somebody else has any idea why it cannot parse the argument? When you changed the ‘NameOfCamera’ did your camera name have any special characters?

PS: Note that I changed the --python to be earlier in the command, otherwise it does not set the camera before rendering and sets it after.

1 Like

Now it work ,I should change the – python camera.py -o /media/etc…

#!/bin/bash
#Launch blender Batch Render
/home/ubuntu/blender-4.2.0-linux-x64/blender -b /media/XXXXXXXXXXXXXXX/Project/blender/aaa/aaa.blend --python camera.py -o /media/XXXXXXXXXXXXXXX/Project/blender/aaa/render/aaa -f 1 -- Camera.001

Thank you.

For whatever it may be worth, I don’t attempt to “switch cameras during a render.” I set up files with “shot scenes” linked to “action scenes,” and each “shot scene” has an active camera, output filename parameters and so on. So, all I have to do is to specify the scene.

Then, I render each scene individually – allowing a second-or-so “tag” at the beginning and the end to simplify editing.

The final movie is then assembled in the video editor of your choice. Blender of course has one built-in. But there are also very good open-source ones and commercial products.

And, it is during the edit that “the movie really starts happening.” You find yourself making very small “tweaks.” Nudging this way and that to find exactly the right point to make the cut, and exactly the right transition. Changing the order of the shots from what you originally contemplated. Note also that you can begin to do this very early in the process, where shots have been correctly blocked-out but many of the final details aren’t even built yet.

One more thing,I have already multiple camera created from different view,even camera with sun different rotation for ex:
Camera.001 render with sun.001 set flag render on.
Can add sun name set flag render on in python line argument with camera name ?

@design_space: I simply suggest once again that maybe you should not attempt to “render the entire movie in this way.” Because, you are effectively making "editing decisions" in software. Then, when(!) you don’t like your decision, you are “back to programming.” This is inefficient.

“Individual renders” don’t create “the movie.” They create components of it. One “shot” at a time.

You do not need “Python scripting.” If you have different shot ideas, shoot each one. (Only as much as you think you need – you can always add more.) Then, separately, edit them together.

The immortal Psycho Shower Scene” shows how important this can be . . . (Hitchcock preferred “assembly” or “montage” over “cutting.”) As he famously said: “about 78 pieces of film in about 45 seconds.”

Hi @sundialsvc4
I use this method for some reason memory and increase the render speed,if I have a big scene + run blender graphical mode,the render will stopping,this method run render in background without run blender graphical.
But if we have good high pc performance,don’t need anymore to use batch render from command line.