Render crashes always after about 100 frames

Use blender in the background.

In the terminal you can render with Blender either the whole animation or just every next frame. You can do it like this.

blender -b blendfile.blend -o /folder/where/the/render/will/be/#### -F JPEG -f 101

This will render 101th frame from your animation into a Jpeg file with the formatting of “0101.jpg” which is set by using the /#### in the end. It tells how many zeros to use.

So the next step would be to code a little script that will check which frames are missing in the folder and render the next frame. If you have python installed it’s not too complex.

I think it is not too out of reach to actually know the range. Your start and end frame. And your rendering file and the destination. So we can make a script that will be executed like this:

python3 your_script.py file_to_render.blend /folder/to/save/render JPEG 0 340

in which 0 is the start frame and 340 is the end frame.

To make python read arguments like this you will need the sys module, but don’t worry about it, it’s usually preinstalled with python. So the beginning of the script should be:

import sys

args = sys.argv # This is the list of the arguments you have passed to it

# Let's save them for clarity

blendfile = args[1]
destination = args[2]
imageformat = args[3]
startframe = args[4]
endframe = args[5]

Now we need to setup a loop that will constantly check for which frame in the range between the start frame and the end frame not yet in the folder. But there is a problem. Numbers in python even converted to text will still looks like numbers 1 2 3 and so on. While we need 0001 0002 0003 and so on.

Also we need to add an extension to the end of the filename. And the problem is that for something like JPEG blender expects it to be JPEG file the file extension will look like .jpg or something.

So it’s good to define a few functions that will deal with those problems.

def getnumstr(num):
    
    # This function turns numbers like 1 or 20 into numbers like 0001 or 0020
    
    s = ""
    for i in range(4-len(str(num))):
        s = s + "0"
    
    return s+str(num)

If you will define that function and will try:

print( getnumstr( 20 ) )

The output should be 0020

def getfileoutput(num, FORMAT):
    
    # Function gives an output of a file. From the current frame that's rendering.
    # instead of having frame 1 and format EXR it will give you 0001.exr
    
    s = getnumstr(num) # Here I'm using the previously defined function
    
    if FORMAT == "JPEG":
        s = s + ".jpg"
    else:
        s = s + "." + FORMAT.lower()
        
    return s

With those 2 functions defined you can do this:

print( getfileoutput( 20, "JPEG" ) )

and it should output 0020.jpg

Next we will need to cycle through the files of the destination folder. And render everything that is not rendered yet. But in such a way that if Blender crashes, we will try again immediately.


import os # A module that can output list of files in a folder
          # And can run commands in the terminal

while True: # Spawns up a never ending loop.
    
    # We need a mechanism to stop the script when it's done rendering
    tostop = True

    # Checking if the file is in the folder
    for framenumber in range( int( startframe ), int( endframe )):
        imagefilename = getfileoutput( framenumber, imageformat )
        if imagefilename not in os.listdir( destination ):
            tostop = False # If at least one frame missing, we do not stop.
            # Lets render the picture
            os.system("blender -b "+blendfile+" -o "+destination+"/#### -F "+imageformat+" -f "+str(framenumber))
    
    if tostop: # This will end the script.
        break