Batch Render Multiple Blend Files with Shell Scripts

Batch rendering multiple Blender files using a shell script allows you to automate rendering queues overnight or across multiple machines without opening the graphical user interface. This guide demonstrates how to configure Blender’s command-line interface (CLI) to process multiple .blend files sequentially, customize output paths, render specific frames or complete animations, and execute the workflow via a Bash script on Linux and macOS.


Understanding the Blender CLI Basics

Blender provides a command-line interface that can run headless using the -b (or --background) argument. The core arguments required for rendering are:

  • -b <file.blend>: Opens the specified file in background mode.
  • -o <path/to/output>: Defines the output path and file naming format.
  • -f <frame_number>: Renders a single specific frame.
  • -s <start> -e <end> -a: Renders an animation range from frame <start> to <end>.
  • -a: Renders the entire animation range configured within the file.

Step 1: Locate or Export the Blender Executable

Ensure that blender is accessible in your system path. If it is not, define the path explicitly in your script:

  • Linux: /usr/bin/blender or /path/to/blender-dir/blender
  • macOS: /Applications/Blender.app/Contents/MacOS/Blender

To add Blender to your system PATH temporarily:

export PATH="/Applications/Blender.app/Contents/MacOS:$PATH"

Step 2: Write the Shell Script

Create a file named batch_render.sh in the directory containing your .blend files or anywhere on your system.

#!/usr/bin/env bash

# Define the path to the Blender executable
BLENDER_PATH="blender"

# Define the source directory containing .blend files and the target output directory
SOURCE_DIR="./scenes"
OUTPUT_DIR="./renders"

# Create the output directory if it does not exist
mkdir -p "$OUTPUT_DIR"

# Loop through all .blend files in the source directory
for blend_file in "$SOURCE_DIR"/*.blend; do
    # Check if any .blend files exist to avoid errors
    [ -e "$blend_file" ] || continue

    # Extract the filename without the directory and extension
    filename=$(basename -- "$blend_file")
    basename="${filename%.*}"

    echo "=========================================="
    echo "Starting render for: $filename"
    echo "=========================================="

    # Run Blender in background mode to render the full animation
    "$BLENDER_PATH" -b "$blend_file" \
        -o "$OUTPUT_DIR/${basename}_####" \
        -a

    echo "Finished rendering: $filename"
done

echo "All batch render tasks have completed."

Step 3: Configure Render Modes

Modify the command inside the loop depending on your rendering requirements:

Render Only Still Images (e.g., Frame 1)

"$BLENDER_PATH" -b "$blend_file" -o "$OUTPUT_DIR/${basename}_render" -f 1

Render a Specific Frame Range

"$BLENDER_PATH" -b "$blend_file" -o "$OUTPUT_DIR/${basename}_####" -s 1 -e 120 -a

Override the Render Engine via CLI (e.g., Cycles)

"$BLENDER_PATH" -b "$blend_file" -E CYCLES -o "$OUTPUT_DIR/${basename}_####" -a

Step 4: Make the Script Executable and Run It

Grant execution permissions to the script using chmod:

chmod +x batch_render.sh

Execute the script:

./batch_render.sh

To run the rendering process in the background and output the logs to a text file, use nohup:

nohup ./batch_render.sh > render_log.txt 2>&1 &

Helpful Command-Line Flags

Argument Description
-t <threads> Restricts Blender to use a specific number of CPU threads.
--log <match> Enables specific logging modules for debugging errors.
-noaudio Disables audio processing to save overhead.
--python-expr "<code>" Runs an inline Python command before the render executes (e.g., changing device to GPU).