13
$\begingroup$

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

$\endgroup$
5
  • 2
    $\begingroup$ 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. $\endgroup$
    – iKlsR
    Sep 24, 2013 at 1:56
  • $\begingroup$ Modified the question title, since theres nothing specific to H264 about your question (for any other format the answer would be the same). $\endgroup$
    – ideasman42
    Sep 24, 2013 at 4:34
  • $\begingroup$ pretty neat one: bpy.context.scene.render.image_settings.file_format = 'PNG' $\endgroup$
    – Vaqas A
    Oct 19, 2017 at 14:36
  • $\begingroup$ Yes, you can set the dimensions from the command line. The render-batch script in this repo does exactly that. $\endgroup$ Oct 19, 2017 at 22:54
  • $\begingroup$ 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. $\endgroup$ Oct 19, 2017 at 22:55

1 Answer 1

18
$\begingroup$

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.

Further reading: https://docs.blender.org/manual/en/latest/advanced/command_line/arguments.html#python-options

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.

$\endgroup$
2
  • 2
    $\begingroup$ 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 $\endgroup$
    – waldyrious
    Oct 27, 2016 at 4:44
  • $\begingroup$ instead of /n you can use semicolons ; $\endgroup$ Apr 27, 2023 at 8:51

You must log in to answer this question.

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