Command Line Rendering
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!
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).
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!
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!
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!
- Alpha Channel (mask) checked - on - if you are going to composite
- 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.
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)
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).
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).
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).
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).
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).
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)
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).
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)
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).
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).
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)
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).
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.