Batch Conversion of BVH to FBX Motion Capture files

Continuing my foray into the world of motion capture, I’ve been building up my own collection of mocap data files from various sources I find on the ‘net, with the hope of ultimately using them to animate a Mecanim rig in Unity.  While I don’t think Mixamo will be worried quite yet(!), I have gathered enough BVH files such that loading them up individually into Blender and saving them to FBX necessary for import in Unity has become quite a chore.

So, I wrote a python script to automate the process,, as follows:

import bpy
import sys

#Get command line arguments
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "—"
bvh_in = argv[0] 
fbx_out = argv[0] + ".fbx"

# Import the BVH file
# See
bpy.ops.import_anim.bvh(filepath=bvh_in, filter_glob="*.bvh", global_scale=1, frame_start=1, use_fps_scale=False, use_cyclic=False, rotate_mode='NATIVE', axis_forward='-Z', axis_up='Y')

# Export as FBX 
# See
bpy.ops.export_scene.fbx(filepath=fbx_out, axis_forward='-Z', axis_up='Y', use_anim=True, use_selection=True, use_default_take=False)


Then, create a batch file, bvh2fbx.bat, that loops through all BVH files in a directory and calls Blender from the command line with the script above, passing in the details of files to be converted:


FOR %%f IN (*.bvh) DO "c:\program files (x86)\blender foundation\blender\blender.exe" -b --python "c:\temp\" -- "%%f"


(Alter the path to the Blender executable and to where you saved the script as appropriate). Run the bvh2fbx.bat file from the commandline and you should get all BVH files in the directory automatically converted to FBX.



All that remains is to import them to Unity and add a Humanoid rig and they’re ready to use in an Animator!


This entry was posted in Game Dev and tagged , , , , , , . Bookmark the permalink.

9 Responses to Batch Conversion of BVH to FBX Motion Capture files

  1. Anil Punjabi says:

    Hi there.

    Many thanks for sharing your experience with migrating the animation files.

    Wondering you’ve had success with this approach and if you could kindly share your converted animation files that can be used with Mecanim.

    Would greatly appreciate it.


    • alastaira says:

      Yes, it works great (depending on the quality of the BVH file with which you started, obviously). I can’t post the converted animation files because they’re not licensed for me to redistribute, but there’s plenty of free and commerical BVH files on the net

  2. Hi!

    You may also be interested in Blend4Web which is designed as the primary tool for the browser game development in Blender.

  3. Billy Sides says:

    I get an error when using your script, does it matter what version of Blender you are using?

    found bundled python: C:\Program Files\Blender Foundation\Blender\2.72\python
    Traceback (most recent call last):
    File “”, line 1, in
    File “”, line 2
    Type “copyright”, “credits” or “license()” for more information.
    SyntaxError: invalid syntax

    Blender quit

  4. Paul says:

    Hi, I’m using your py script and batch file to convert from bvh to fbx and I keep getting error: Object has no duplis. Any idea how to solve this?

  5. Pingback: Motion to Motion | Caffeine & Code

  6. Aste says:

    Hello thanks for sharing this is very helpful!
    Also I got some questions. How can I get the bvh files from its directory and run the bat file? Thank you for your help.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s