Skip to main content

Getting camera tracking data from Blender to After Effects

By February 7, 2014April 12th, 2022No Comments

There’s a plugin for Blender that lets you export 3D camera data in a format AE can use – you end up with a camera in AE that moves exactly the same way as your camera in Blender.

After Effects strangely doesn’t support orthogonal cameras though – you can have either flat compositions with no 3D transformations, or full-on 3D with perspective. No isometric-style perspectiveless 3D. So, no good for my current project, which looks 3D but is completely perspectiveless:

Screen Shot 2014-02-07 at 11.11.52

This means that if you need to track a logo in over an orthogonally-rendered animation you have to use the 2D Corner Pin effect to distort the logo to fit the scene. In a fast-moving scene you can just render tracking markers at the corners of where the logo should go, then use them in AE to place the corner pins, either by eye or using Motion Tracker.

For slow moving scenes it’s hard to get the track perfectly. Orthogonal views along with a camera that rotates as well as translating exacerbates the error; the lack of perspective already looks weird, so a logo that isn’t tracked solidly seems to swim. After much frustration and a bit of googling I decided to hack up a script for Blender to export the data I needed:

# use this script to export the resulting screen coordinates
# of the currently active object in 3D space. Coords get 
# output to the console -h

import bpy
from bpy_extras.object_utils import world_to_camera_view

scene = bpy.context.scene

# needed to rescale 2d coordinates
render = scene.render
res_x = render.resolution_x
res_y = render.resolution_y

rnd = lambda i: round(i,1)


for j in range(1845,1902):   # frame range you're interested in    
    obj = bpy.context.active_object
    coords_2d = world_to_camera_view(scene, cam, (obj.matrix_world *  obj.location))
    print("\t{}\t{}\t{}\t".format(j, rnd(res_x*coords_2d.x), rnd(res_y*(1-coords_2d.y))))

Worth the hassle, though: the flown-in logo is locked to the wall now:
Screen Shot 2014-02-07 at 11.15.36

Leave a Reply