# Setting render options from the command line

I was hoping to render blender using the command line mode on linux. However, I do not no how to set the output resolution and H.264 as the encoding. Both these options work in the GUI mode but I wish to use them from the command line

• You can't set the dimensions from the command line. I'm also certain variations of this have been asked before.. please have a look through the commandline tag.. or specifically Can Cycles renders be done from the command line? and Is there a way to batch render multiple scenes?. Have a look at the parameters in the second link and I believe you can pass H.264 to -F. – iKlsR Sep 24 '13 at 1:56
• Modified the question title, since theres nothing specific to H264 about your question (for any other format the answer would be the same). – ideasman42 Sep 24 '13 at 4:34
• pretty neat one: bpy.context.scene.render.image_settings.file_format = 'PNG' – Vaqas A Oct 19 '17 at 14:36
• Yes, you can set the dimensions from the command line. The render-batch script in this repo does exactly that. – Lawrence D'Oliveiro Oct 19 '17 at 22:54
• I prefer to render to separate PNG frames (or alternatively OpenEXR). Then I encode the frames separately using FFmpeg. This way I can tweak the quality settings etc without having to re-render. – Lawrence D'Oliveiro Oct 19 '17 at 22:55

# Command line

One way is to set the properties from the gui, save the file, then render. The settings will be preserved for rendering from the command line.

Note that (as already mentioned by iKlsR) you can set the render output format from the command line with -F:

Format Options:
-F or --render-format <format>
Set the render format, Valid options are...
TGA IRIS JPEG MOVIE IRIZ RAWTGA
AVIRAW AVIJPEG PNG BMP FRAMESERVER
(formats that can be compiled into blender, not available on all systems)
HDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS


However, it seems H264 is not a valid setting for this argument.

# Python

Another way is to use blender's python API, and run a python script in blender from the command line (see this post), e.g.:

blender --background /path/to/file.blend --python /path/to/script.py --render-anim


or

blender -b /path/to/file.blend -P /path/to/script.py -a


The render resolution can be set with bpy.context.scene.render.resolution_x and bpy.context.scene.render.resolution_y.

The output format can be set to H.264 with
bpy.context.scene.render.image_settings.file_format = 'H264'.

### Note on scene values:

You may want to assign the settings for all scenes to avoid confusion with complex setups which use multiple scenes.

for scene in bpy.data.scenes:
scene.render.resolution_x = 1920
scene.render.resolution_y = 1080
scene.render.image_settings.file_format = 'H264'


### Note invoking render:

When using a Python script to render you have the choice to...

• Pass the --render-anim argument.
• Call bpy.ops.render.render(animation=True) directly from the Python script.

Both do the same thing however calling the operator from Python means if the script fails to run, render won't execute, This may be good/bad depending on your use-case.

Calling from Python also gives some flexibility - for example you could call render multiple times with different frame ranges.

• Note: to avoid creating a script file just for this, a python expression can be passed directly at the command line (the \n should be replaced with actual newlines): blender -b path/to/file.blend --python-expr "import bpy\n for scene in bpy.data.scenes:\n scene.render.resolution_x = 1920\n scene.render.resolution_y = 1080\n scene.render.image_settings.file_format = 'H264'" -a – waldyrious Oct 27 '16 at 4:44