Command Line Rendering

Introduction

This tutorial is geared towards Maya users with little or no experience working in the Windows Shell.  It was written to help students in a class I was in to help them better understand how to launch batch renders from the command line, and how to create batch scripts to execute a number of separate file renders automatically.
 
Command line rendering allocates more system resources to the render processes than if one were to render with Maya open.  Additionally, in an environment using a license and a server (such as in most universities and large businesses) there are often more users than there are licenses!  So, in addition to being less efficient and more unstable, batch rendering from within Maya locks up a license unnecessarily.  All in all, unless it's for a preview, it's better to render with Maya closed!

Step 1

Make sure you have set up a "project file" in Maya.  This step should have been done at the very start of an assignment, but it can technically be done at anytime.  To set up a project up go to: File > Project > New (Fig.01).

Fig. 01

Fig. 01

You will then get the New Project dialogue box (Fig.02). Click the "Use Defaults" button at the bottom and specify the name of the project and the location where you'd like it stored.  Don't use any spaces or funny characters in your scene names or filenames - it's just easier in the long run if you don't!

Fig. 02

Fig. 02

For the remainder of this tutorial I'm going to use the project name "MidTerm".  The location of the MidTerm project is going to be G:\DIGM211\MidTerm.  To find your file path, navigate to your project and look at the file path box in the explorer window (Fig.03).With your project set, any files you save while working within the project will be stored in their proper folders.  This is priceless!  Maya does most of the work for you, but what you need to do before you start rendering animations is to go into the "images" folder of your project and MAKE INDIVIDUAL FOLDERS FOR EACH AND EVERY CAMERA AND/OR SHOT YOU ARE GOING TO RENDER!

Fig. 03

Fig. 03

Step 2

OK, so you are working in a project, you have your camera moves, animations, lighting, and texturing all ready for a batch render.  While it's possible to batch render from within Maya, this approach is incredibly inefficient.  In reality, rendering anything other than previews in Maya is inefficient.  The reason for this is that the Renderer and Maya are actually separate programs.  So by rendering with Maya open you are going to be needlessly clogging your systems memory.  On large scenes there is often no other alternative than rendering from the Command Line.  As your work in Maya progresses you might end up working on scenes that can take 5-10+ minutes to simply OPEN.  Rendering from the command line allows you to render whatever you specify without ever opening Maya.
 
The easiest way to begin Command Line rendering is to, from within Maya, open the scene you want to render and set all the render settings to how you'd like them. i.e.:

File Name Prefix:  I recommend using the camera name you are rendering from (you are using dedicated cameras for rendering, right?)
  
Frame/Animation ext:  name.#.ext, or name_#.ext

Image Format:  LOSSLESS FORMATS ONLY (EXR, Targa or Tiff generally)

Start Frame:  Whatever frame in the timeline you want the animation render to start

End Frame:  Whatever frame in the timeline you want the animation render to end

By Frame:  1 usually; 2 is sometimes used if you want to render every other frame for a preview

Frame Padding:  How many number spaces are in the .ext of the frame render names. Let's say you have 350 frames you want to render - use 3 for the frame padding. That way the files will then start with frame number 001 and end at frame 350. Compositing programmes will be sure to understand the numbering this way.

Renderable Camera: BE SURE TO SET THIS TO THE RIGHT CAMERA FOR THE ANIMATION!

  1. Alpha Channel (mask) checked - on - if you are going to composite
  2. Depth Channel (zDepth) checked - on - if you are going to do depth of field, etc. in post-production

And finally, set the Render quality levels for whatever Renderer you want to use.  Save your scene after the render settings are all perfect.

Step 3

Take a deep breath and close Maya.  The rest of this tutorial is going to assume you are working on a Windows machine. 
Go to Start > Run (Fig.04)

Fig. 04

Fig. 04

You will get a little dialogue box - type "cmd" in it and click OK (Fig.05). This will open your Command Prompt.  If you are on a Mac you can open a terminal window; UNIX users open a shell window - it's all basically the same thing (with different syntax) (Fig.06).

Fig. 06 - Click to Enlarge

Fig. 06 - Click to Enlarge

My project's file path (if you'll recall) is: G:\DIGM211\MidTerm.  So, as you can see from the Command Prompt in Fig.06, we are in the C:\ drive.  To change drives, type the drive letter followed by a colon and hit Enter.  For me: "G:" (Fig.07). Type "dir" to list the contents of whichever drive you are in (Fig.08).

Fig. 07 - Click to Enlarge

Fig. 07 - Click to Enlarge

Fig. 08 - Click to Enlarge

Fig. 08 - Click to Enlarge

I want to get into the DIGM211 directory next, so use "cd" to change directories.  Once in DIGM211, again type "dir" to list the contents (Fig.09).

Fig. 09

Fig. 09

We have taken a very long route to get to this file to illustrate the basic steps in getting around using the command line.  However, normally once in the G: drive, I'd just type: "cd DIGM211\MidTerm\scenes" (Fig.10).

Fig. 10

Fig. 10

And here we have all the different scene files I've saved for the MidTerm project.  Two things to take note of in particular are:

1. The individual renderCam files at the bottom of the list.  These are individual copies of the final scene that I set up for each camera move or shot; each one has individual start and end frame settings and renderable camera settings and prefix names. While this isn't necessary, and anything you adjust in the Render Settings window in Maya can be achieved using flags in the command line (explained later), it will make things easier when you are starting out.  It also allows you to work with smaller scenes due to the fact you can basically delete anything not visible in the shot.

2. Notice the .bat files - VERY IMPORTANT and explained in a bit!

OK, first things first.  Flags are basically little variables that store the settings you'd like to use in your renders.  There are a lot of them!  So even though we specified a lot of things in the Render Settings window of our scene file, they can be changed from the command line.  The saved file will not be affected, just the render.  To see a list of the Maya Renderer flags, type:  "Render -h" (Fig.11).

Fig. 11

Fig. 11

This is a truncated list of the option flags that will be listed.  I'm not going to go into what each one does - you can explore that on your own someday!  The Maya documentation (F1 from inside Maya) has a great list and also goes over the Mental Ray flags.  Third party render apps (PRMan, 3Delight, etc.) will have their own special flags, so read their documentation to learn more. I'll only describe a few of the Mental Ray flags that I use most often in this tutorial.

Now, you can either write your commands directly in the Command Prompt window, or you can use a text editor like notepad (notepad scripts are executed as .bat files, which are covered a bit later on) to write your code.  Don't use a word processor!

On Windows: Start > All Programs > Accessories > Notepad (Fig.12)

Fig. 12

Fig. 12

OK, in my MidTerm\scenes directory I have a file saved as "gears.mb".  Let's say I want to render it.  To just use the standard Maya Renderer, type: "Render yourFilenameHere.mb" (or .ma depending on how you have saved them) (Fig.13).

Fig. 13

Fig. 13

If you hit Enter, this will launch the Maya Renderer and begin rendering the scene file you want, using all available processors, using the preferences you set up in the Render Settings window way back at the beginning of this tutorial, and saving all the images to the "images" folder in the project directory that Maya built for you.

Before you start rendering long animations, it's important to note that, while in the Command Prompt window, by holding down the Control key and pressing the letter "C", you can interrupt the batch render.  You can then type "Y" to affirm the quit command or "N" to resume rendering.

Let's say you want to use Mental Ray:  Render -r mr yourFilenameHere.mb (Fig.14)

Fig. 14

Fig. 14

Let's say you have changed your mind, and instead of rendering frames 1 - 350 (which were set in the Maya render settings window), you want 10 - 350: -s startFrame -e endFrame -b byFrame (Fig.15).

Fig. 15

Fig. 15

Remember, the flags are only overrides - all the other settings are going to be read from the Render Settings window of the file!

Let's say you want to specify a different camera for the render: Render -r mr -cam persp yourFileName.mb

Here is the official point where this gets cool!

Let's say you want to render hundreds of images for your animation while you continue working on your term paper and listening to music. You can tell the renderer how many of your processors to use. So I am running a dual-core CPU in my home machine; by specifying 1 processor, I have been rendering out hundreds of images while I worked on this PDF!  Note the different flags for Mental Ray and Maya.  On a quad core, you could use two or three processors and still work on other stuff.

Render -n 1 yourFileName.mb // this renders with one processor using the Maya Renderer

Render -rt 1 -r mr yourFileName.mb // this renders with one processor using Mental Ray

Remember how you made all those extra folders in your project's images directory for all the camera shots you intended on rendering?  Unfortunately, the images folder you specify in the Maya Project window is UNIVERSAL for the project.  What that means is you can't just open each individual shot file and change the image folder - it will change it for every other file in the scene.
 
This is how you direct the images into them.  I am going to direct my gears.mb renders to a folder named "gearPanAndZoom":

Render -r mr -rd DIGM211\ MidTerm\images\gearPanAndZoom gears.mb

And here is where it all comes together! Let's say you want to render every single shot in your animation and go home to get some sleep. What a concept?! Open up Notepad; we are going to create a batch script - a simple executable file that will run shell commands in order with very little work from you. For this you don't even have to open the command prompt window (Fig.16).

Fig. 16

Fig. 16

You can use whatever flags you want in the script. The one in Fig.16 tells the computer to:

Render -using one processor -using mental ray and -where to save the images -for each scene

Again, any information you don't specify with flags will be derived from whatever was specified in Maya's Render Settings window when you last saved your scene.

After you type your commands, go to: File > Save > Save in THE SAME FOLDER AS THE FILES YOU WANT TO RENDER > Choose the "Save As Type" drop down item "All Files" > Name your file and use the extension .bat at the end of the file name.
 
For this example: RenderMyStuff.bat

Two important notes:
1. Do not save your file as a .txt file - it will not run!
2. Do not name your file "render.bat" - it will execute infinite loops of badness!(Fig.17)

Fig. 17

Fig. 17

Mike_Jensens_Techniques

Mike_Jensens_Techniques

Great! Now close Notepad and open the project\scenes folder you just saved your .bat file to (Fig.18).

See that file with the little gear symbol on it?  It's a .bat or "MS DOS batch" file.  The one you are looking at is the one I'm using this (Friday) afternoon while I work on this.  There are others in there, including the "RenderMyStuff.bat" we just made. If you were to double-click one of the .bat file icons, a command prompt window would open and tell you what it is doing, and whether there are any problems.
 
Provided your file paths are all correctly written and your flags make sense, the lines of code you typed in notepad would begin executing and would continue executing until the computer runs out of commands.  You type Control C, or your system crashes (which will happen, but not nearly as often as if you try and render from inside Maya, which brings us full circle to why you want to render this way in the first place).

Fig. 18

Fig. 18

Step 4

In closing, you've double-clicked your .bat file, the command prompt window has opened and no errors have been returned.  What I usually do is press "Control + Alt + Delete" and this opens up the Windows Task Manager.  Click the "performance" tab at the top.  The CPU Usage windows show you how much of your available processing power is being used.  On a side note, each "CPU Usage History" window represents a single processor.  I'm running a script in the background using 50% (or 1 processor) (Fig.19).

I'll then open up the folder to which I am directing my rendered images, to make sure they are going where I expect them to and saving in the proper format. If you are curious, you can then time how long each file is taking to render (based on how long it takes between file icons to appear in your folder). You can then decide if you are going to have your MidTerm project done in time for the crit.!

When I'm working in a shared environment I'll also put up a plain Notepad text file explaining what frames I am rendering (in case it finishes and someone else needs the computer), and what my contact number/email is in case there are questions or problems.

Enjoy!

Fig. 19

Fig. 19

Fetching comments...

Post a comment