1
$\begingroup$

Im trying to render directly from a python script in Blender, and I almost got it. But there is no information on how to do it in the docs.

Actually, the code I got so far is from here With the following code, the script will render your blender scene into a series of images:

for scene in bpy.data.scenes:
    data_context = {"blend_data": bpy.context.blend_data, "scene": scene}
    bpy.ops.render.render(data_context, animation=True)

This will produce a folder with all the frames in your scene.

But how to convert those to a video in 30 fps with a python script with blender? I found no documentation about it. Anyone did this? Thanks!

$\endgroup$
4
$\begingroup$

Within your scene loop you can alter the render settings within scene.render

Some variables of interest may be -

render.image_settings.file_format default available image_format options are BMP IRIS PNG JPEG TARGA TARGA_RAW OPEN_EXR_MULTILAYER OPEN_EXR AVI_JPEG AVI_RAW - depending on the build settings others may be available, like CINEON DPX TIFF or FFMPEG

If you have the FFMPEG option then you can adjust it through variables in scene.render.ffmpeg such as scene.render.ffmpeg.codec with options like H264 or MPEG4. Other ffmpeg variables include video_bitrate maxrate minrate packetsize

To change the framerate set scene.render.fps

To specify where the file is saved you set scene.render.filepath

One point to consider is that bpy.ops.render.render will render using the settings saved with the file, so you can setup these options and save before starting your python script.

It is also common to render animations to individual files for each frame and then join them into a video file once rendering has completed. One way to do this is with ffmpeg as described here another is to import the image sequence into blender's video sequence editor and 'render' to a video file, this is very quick once all the images have been rendered. The blender wiki can get you started.

Blender is a large beast and the python dataset to access it all is just as large. You can find a large amount of information in the blender API documentaion but you may find blender and it's built-in python console just as helpful. You can right click on almost any interface item and select Edit Source - this will open the python file used to display that item in a text block (available in a text editor window) with the cursor on the relevant line.

Within the blender python console you can enter bpy.data.scenes['Scene'].render.ffmpeg. and click the Autocomplete button to see a list of variables and functions available as the next item.

Also don't forget that if it has been turned off you can turn on python tooltips in the user settings, which displays some python paths (sometimes truncated) in the tooltips for most things, that can at least point you in the direction to look for more information.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Great, thanks, will work on it and as soon as I get it to work will accept answer and suggest things I find on the way :) $\endgroup$ – I want badges Dec 23 '13 at 15:11
  • $\begingroup$ Well, after all, I found just easier to get it into frames then use this to make the frames into a video: superuser.com/questions/624567/… $\endgroup$ – I want badges Dec 23 '13 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.