10
$\begingroup$

I'd like to know if there is a command-line option (or combination, or a way!) to get the number of frames that are included in a specified blender scene; for example I'd like to use is like this:

$ blender <option> file.blend
$ Number of frames in blender scene: xxxx
$\endgroup$

3 Answers 3

10
$\begingroup$

No, Blender has no command line arguments to return the number of frames in the scene, however you can use a script.

Here is a script as mentioned by CoDEmanX above:

import bpy

scene = bpy.context.scene
print("Scene %r frames: %d..%d = %d" % (scene.name, scene.frame_start, scene.frame_end, scene.frame_end - scene.frame_start + 1)) # frame_end is included

Store this as a .py file, then you can run it like so:

blender -b <path-to-blend-file> -P <path-to-script>
$\endgroup$
4
  • $\begingroup$ Thanks a lot, I'll test it in a couple of hours and let you know if that is what I want! $\endgroup$
    – jtimz
    Commented Oct 1, 2013 at 12:12
  • $\begingroup$ Well, I tried it but I think it doesn't return the number of animation frames correctly. It always returns 1...250 frames; I tested with a couple of scenes but "dynamicpaint_waves.blend" scene from blender's own demo files has 340 animation frames and your script only returns 250. $\endgroup$
    – jtimz
    Commented Oct 1, 2013 at 12:48
  • 4
    $\begingroup$ @jtimz Try placing -P <path-to-script> behind <path-to-blend-file>, so the script is executed after the file is loaded. $\endgroup$
    – Adhi
    Commented Oct 1, 2013 at 13:05
  • $\begingroup$ Ah yes, it returns the startup.blend frames otherwise. Fixed. $\endgroup$
    – user436
    Commented Oct 1, 2013 at 14:18
10
$\begingroup$

This information is stored in the blend files header, so you can find out without having to load Blender at all.

This has the advantage you can scan a directory of 100's (or 1000's) of blend files in a very short time (a few seconds even if the files are large).

Blender comes with a script in scripts/modules/blend_render_info.py which can extract this data from a blend file (you don't even need Blender to be installed just a copy of this file and Python is enough).

You can load the script as a module or execute it directly.

command line example:

# python blend_render_info.py /path/to/my_test.blend
1 250 Scene

python example: This can run inside blender, otherwise blend_render_info.py will have to be in Python's sys.path

import blend_render_info

filepath = "/path/to/my_test.blend"
frame_start, frame_end, scene = blend_render_info.read_blend_rend_chunk(filepath)

print("total frames:", (frame_end - frame_start) + 1)

As you can see the frame range and active scene is stored, if you want more info you'll have to use a script and load the file into Blender.

$\endgroup$
3
$\begingroup$

The Command Line reference does not list a command to output the number frames of a scene: https://www.blender.org/manual/advanced/command_line.html

But you can tell Blender what scene to use and to render all frames (if that is what you want):

 -a or --render-anim 
     Render frames from start to end (inclusive)

 -S or --scene 
     Set the active scene  for renderingame> for rendering

It probably uses the frame range as set within the .blend (Timeline).

Or is your definition of "all frames" from first keyframe to last? In that case, you need a little script that determines the range and returns the info. A python script can be run like this:

 -P or --python 
     Run the given Python script file


If you want to find the min and max keyframe of any object in a scene, you can use this:

import bpy

keyframed_ranges = {}

for scene in bpy.data.scenes:
    lower = []
    upper = []
    for ob in scene.objects:
        if (ob.animation_data is not None and
            ob.animation_data.action is not None):

            # Note: frame_range.y is frame_range_x+1 if there's just a single keyframe!

            lower.append(ob.animation_data.action.frame_range.x)
            upper.append(ob.animation_data.action.frame_range.y)

    if not lower or not upper:
        keyframed_range = scene.frame_start, scene.frame_start
    else:
        keyframed_range = min(lower), max(upper)

    keyframed_ranges[scene.name] = keyframed_range

print(keyframed_ranges)
$\endgroup$
1
  • $\begingroup$ Thanks for your reply! Well, what I want to do is to be able to determine the total frames that would be rendered (i.e. individual jpeg's) in order to split the work into multiple discrete tasks; but to do that and split my scene as evenly as possible I want to be able to know beforehand the length of the scene (total individual frames to be rendered) in order to calculate an accurate step. So I guess this would fall in the second category you mentioned. $\endgroup$
    – jtimz
    Commented Oct 1, 2013 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .