Rendering an animation with Blender
Every few months, because of a deadline coming up, I find myself forgetting and having to look up these steps in old Slack threads and LaTeX comments. Also, it took me a long time to learn these steps because of the lack of a guide like this, so I write this in hopes it may help young students starting out.
I will assume that you have a set of meshes in
.obj format, with ordered names like
iteration-001.obj, iteration-002.obj, … iteration-099.obj, iteration-100.obj.
- Open Blender (you can use my template file).
- Install the OBJ Sequence Blender add-on.
- In Blender, press SHIFT+a and choose Mesh->Mesh Sequence. Then, an empty object called “sequence” will appear in the scene. Select this object and go to Object Properties -> Mesh Sequence. Choose the root folder where your
.objfiles are, being careful to uncheck relative pathing (this is a bug in the Mesh Sequence Add-on). Then, in “file name”, write a string which matches the beginning of the names of all meshes, like
iteration. Finally, click “Load Mesh Sequence”. This can take a few minutes if your meshes are many or very large.
- In Output Properties->Dimensions, choose the dimensions of your animation in pixels (for example, 1920x1080px). In some versions of Blender, the “End” frame is set to 250 by default. This will make your “Baking” step much more expensive than necessary if your animation contains way less meshes, and you may miss the end of your animation if there are more than 250 meshes in your sequence. Make the “End” value the total number of meshes in your sequence (careful with 1-indexing and 0-indexing).
- Now, finalize all the details of your scene. It is especially important that at this step, you pick the materials and shading information for your mesh sequence, since you will not be able to change it afterwards. At this point, I usually save a copy of my
pre-bake.blendso that I can go back to this step if I want to iterate on my result.
- In Object Properties->Mesh Sequence, choose Smooth or Flat shading and click “Bake Mesh Sequence”. Now, if you go to the “Animation” tab, you can press Play or drag the blue time bar to see the progression of your animation.
- In Object Properties->Output, make sure your output directory is set to a known relative path like
//pngs/. This is important, because some Blender make
/tmp/by default and you may completely lose your renderings if you don’t change this. Select “File Extensions”, unselect “Cache Result”, choose “File Format: PNG”, “RGBA”, “Color Depth: 8”, “Compression: 15%”, select “Image Sequence: Overwrite” and unselect “Image Sequence: Placeholders”. Save and exit Blender.
- Now, in the command line and in the same directory as your
blender -b filename.blend -a. This will take a while.
- The rendering step will create a sequence of
001.png, 002.png, …, 099.png, 100.png. These will be transparent, which doesn’t look great for an animation, so we can preprocess these by running
mogrify -flatten *.png(this assumes you’ve installed ImageMagick, which in MacOS you can do with
brew install imagemagick).
- Put the images together into a video by running
ffmpeg -r framerate -f image2 -s 1920x1080 -i %04d.png -vcodec libx264 -crf 15 -pix_fmt yuv420p video.mp4, substituting
frameratewith how many of the pngs you want per second (this assumes you’ve installed ffempg, which in MacOS you can do with
brew install ffmpeg).
- (Optional) If you want to reduce the size of your final
.mp4file, you can do so by running
HandBrakeCLI -i video.mp4 -o 'video-compressed.mp4' -O --preset 'Normal'(this assumes you have installed Handbrake, which on a Mac is as easy as
brew install handbrake)