Saturday, July 3, 2010

Blender Tips - Video Recording

As promised, here is a brief overview of the (current) way I'm putting together the video demos of my Blender SoC project.

The Current Process
Currently, all the Blender screen-captures are all recorded using Blender 2.5's builtin "Screencast" feature (Alt-F3).  To use this:
  1. Simply set aside a directory somewhere (in my case, c:\tmp\bt_demo)
  2. Run Blender, and prepare it for recording by...
    1. Seting this directory as the output directory (under Scene -> Output).
    2. Setting the output file-format to PNG. PNG has better quality than JPEG for fine line details, and will ensure better quality until video compression gets to mangle everything later
    3. Resize the Blender window until it's a reasonable size for a video - try not to make the window too large (large video files - bad for you unless you're lucky enough to have unlimited bandwidth/blazing-fast upload speeds, and also bad for whoever ends up downloading it though hardly anyone will if its too large), or too small (there would hardly be enough room to see everything relevant in the GUI, making it pretty useless). Remember that the size of your window determines the size of the recorded images/video. However, under most OS's, it won't be possible to easily specify an exact size, so just do whatever looks good to the eye in general.
  3. Set up everything ready for recording. Add/tweak whatever settings that are irrelevant to the purpose of the video but which need to be set/present for everything to happen
  4. When you're ready to record, simply Alt-F3, accept the confirmation, and start blending.
  5. ...
  6. When you're done, the simplest way to stop recording is to quit Blender. While recording the videos this week, this was the only option at my disposal, since the 'End Capture' button was not showing in the Info header anymore. 
Putting it All Together into a Single Video
(Remember, this is the 'current' procedure that was used for the videos this week)
  1. Open a new instance of Blender (with FFMPEG compiled in)
  2. Open Sequence Editor in Blender
  3. Add an image strip - in the file browser, navigate to the c:\tmp\bt_demo or whatever you're using, then AKEY to select all the images in the folder. Confirm and make sure the new strip starts on frame 1.
  4. In the Scene tab...
    1. Set resolution to the nearest 'standard' size to the dimensions of one of the .png's saved in the temp directory. By 'standard' size, I mean dimensions such as (800, 600, 640, 480, 320, 240). For example, in the videos I posted, I used 800 x 480 since original dimensions were 779 x 471 or similar. This is very important (as you'll see in the next section)
    2. Set output format to the 'Ogg Theora' preset
    3. Set the output filename appropriately - just make sure you can find it later :)
    4. Set frame range to be 1 to whatever-the-last-frame-of-the-strip-is
    5. Set frame rate to 5 fps or 10 fps. Unless you're moving purposely slowly when recording, use 5 fps to ensure readability.
  5. Click the 'Render Animation'
  6. Upload and rejoice!

Pitfalls - Parts of Previous Processes
Not using 'standard' dimensions
You pay a heavy penalty for not using the 'standard' dimensions (the ratio of the dimensions doesn't matter that much for most modern codecs though), and your options for getting the video made get quite slim.

FFMPEG will not work at all if you don't use these dimensions. It will refuse, refuse, refuse, and crash, crash, crash!
MPEG, XVID (this one takes a good 5 seconds to decide that it can't do the deed, while its partners in crime are quicker on their heels), H.264 will refuse to work, and FLV, MPEG-4/DIVX, FFMPEG Movie Codec will crash; other FFMPEG-based apps such as avidemux will also crash when trying to handle similar files too. The one FFMPEG format that partially works is OGG-Theora, but then you have an annoying problem where only half your video shows up and offset to only show in the bottom half of the frame only. 

So far, my experiences with FFMPEG (as an encoder) have not generally been too positive (though as a playback engine, it is reasonably good, playing most formats under the sun). Last time I used it, most if not all the formats crashed in one way or another - sometimes immediately, sometimes after 1-2 frames, sometimes on the last frame. When it didn't crash (a miracle), only a very very small subset of video players around could read the files it produced (and those were AVI's that were supposedly using standard codecs). 

At least this time, once I'd figured out the fix for the half-frame issue, I could get Ogg-Theora working using the defaults in Blender for using it, which are a good sign that progress is being made in this area :D
    Your only choices are good-ol' AVI files
    • From Blender, you're effectively limited to using AVI JPEG, though at best you're still going to have a rather large file that can't be easily uploaded and can't have sound, but at least it works.
    • On Windows, you could also use VirtualDub to output some AVI's using some other codecs that you may have installed. Unfortunately for me, I don't have many installed, and the ones I do have are the really crappy (i.e. rather lossy codecs). This was the approach I used for the first set of videos, but I abandoned it this time because the files were still as large as those from AVI JPEG but with similar levels of nasty compression artifacts.
    So really, the only remaining alternatives suck pretty badly...

    Not making sure that the output directory is empty
    You'll want to make sure the output directory is empty, as:
    1. You'll probably end up with extra 'junk' from previous sessions tacked onto the end of your recent capture when trying to reconstruct it
    2. Finding (and isolating) the files you want will be harder/take more effort
    3. You don't want some other app still 'using' or 'locking' one of the files you're going to write to, thus causing recording to fail without warning, and wasting effort or losing a good capture to avoidable errors.

    Why record as still images if we can record as videos directly?
    There are 2 problems with directly recording to video:
    1. Something goes wrong while recording, and the video file ends up in a semi-corrupted/unreadable state. This is more of an issue with particular fileformats than others, though it's best to be safe...
    2. You cannot be sure that your original captures are going to be at the right size, since most OS's won't tell you this or let you size precisely. Hence, you might waste heaps of effort recording a long video only to find that it got corrupted by something like the Ogg-Theora half-video-shift described above (trust me, it happened the when I first started trying to record these. Also, this could happen with the other approach too due to other reasons, but saving as images greatly reduces the problems you'll encounter).
    Why record using Blender's builtin screencasting?
    So far, I haven't found any other satisfactory solutions. Everything else either has really bad compression + colour distortion (Camstudio), crashes when compiling the final file (Wink), or so other weird quirks. Also, I realistically only need to record the contents of the Blender window only.


    1. Hi! Thanks for all this info! Really useful to take into consideration for next tutorials.

      One question, when you say "under most OS's, it won't be possible to easily specify an exact size (for the Blender wondow)", which OSs can do that? My approach was to use XVidCap (Ubuntu user here) that lets you define an exact recording area and then resize the Blender window to fit (extra space goes perfect for text files with "memory helpers").

      Thanks again!


    2. When I've worked with computers running Linux (Fedora + Gnome), you get a little box with the dimensions in the middle of the window you're resizing. So, you can keep an eye on these dimensions as you move the mouse until the size matches what you're after.

    3. Have you tried FFmpeg?

    4. Quick question; is there any way to increase the number of frames recorded? It doesn't look nearly smooth enough; for example, I did about 5 min. of recording, and it only recorded 131 frames! Is there any way to change that? Thanks.

    5. Hi Ben,

      The settings which control this are the "Screencast" settings in the "System" tab of the User Preferences.

      The "FPS" setting controls the frame-rate of the output screencast, if you record as a video file (not really recommended, due to the FFMPEG's pickiness and buginess).

      The "Wait timer" on the other hand controls the time between recorded snapshots. The easiest way to change this, is to enter something like
      1.0 / 25
      in that number field once you start editing it. This particular expression gives you 25 fps, but you can modify the 25 to be any other FPS you want, though you probably don't want to make this too high.

    6. when I screnncast something, I do the AVI thing and encode it by WinFF GUI, very capable, and does a nice job for mpeg, open sourced of course. For MP4 high quality, nicely compressed, do the MeGUI rap. For a lot easier MP4 do the Bencos dance, anime compressor.

    7. I am so happy and proud of you to provide such amazing stuff, I’m truly thankful to you!