Friday 16 February 2007

3D camera tracking data import into After Effects troubleshooting

Almost everyone trying to import 3D camera data created in matchmove programs into AE has run into some problems from time to time. I hope this article can be helpful to solve some of these problems.
In this troubleshooting article i'm not gonna write about import from Maya. Primarily because i don't own the software and also since it seems that with the right settings in Maya the import into AE is very reliable.
That reliability was and is unfortunately not always given with the export from a matchmove program (because of AE or the matchmove program?).
The usual import route to AE is via the Maya ma format. The only exception i know of is the import from Boujou via the Boujou ban format with a free AE plug in from 2d3 (for me this worked pretty well sometimes and sometimes it didn't work at all).
The import via the ma file format can create a lot of problems. It seems that Maya can read the exported files from matchmove programs well but AE is a little bit more demanding. This results in the usual 320x240 comps with missing tracking marker nulls etc.. Very annoying to say the least.
The workaround for this for many people was to import the file into Maya and then export a Maya file that AE can import properly.
Now with newer versions of Boujou and also SynthEyes there's an export option called AE Maya format that puts out a ma file that AE can read well (if you know other 3d tracking software with this feature let me know).
Although i always wanted to know why the standard ma import didn't work well with AE, the availability of the new AE Maya format export options made me forget about this problem.
A recent discussion at fxphd reawakened my interest in that topic.
As a result i checked the differences between the AE Maya and standard Maya format to find out what causes the indigestion in AE and how to change the standard maya file to make it work.

So this is designed as a help if you only have matchmoving software that doesn't feature an AE Maya export option ( like Realviz's Matchmover ) or if you're just stranded with a standard maya file.

For my testing i only had 2d3's Boujou Bullet PXC and Realviz's Matchmover 4 Pro available ( thanks to the Pixelcorps ).
The example code below is from an standard maya file exported from Matchmover Pro 4 but the solutions are easily applicable to files exported from other matchmove programs.

Overall tips:
- don't export 2000 tracks etc.. only export a couple hundred or the ones
you need. Otherwise AE won't be able to handle it.
- try to use the scaling with a coordinate system in the matchmove program to get a proper scene scale.
- try to set the coordinate axis in your tracking program to y-up and also set up a coordinate system for your solve.
Still if the tracks and camera aren't positioned and oriented properly after import you can always parent all tracks and the camera to a null and rotate and move this around.


How to make a standard Maya ma file work with AE:

1. Backup your ma file (at a safe place!) and then open it in a standard text editor ( i know you don't want to do this
but hey it's easy... trust me :) ).
In case the file isn't formatted properly use a different editor.

2. Go to this line:

// edit this line to change the current units
currentUnit -l cm -a deg -t film;

Check if the word after -t is set to film for 24fps, to ntsc for 30fps or to pal for 25fps;
This should usually be set to the framerate that was used in the matchmoving program.
In one test with Matchmover it was set to film instead of ntsc.


3. Go to this line:

// the five next lines set global render attributs
// comment or edit these lines as necessary
select -ne defaultResolution;
setAttr ".w" 720;
setAttr ".h" 480;
setAttr ".dar" 1.34997;
setAttr ".ldar" yes;

Add a colon before “defaultResolution” so you get this ( if you use Matchmover also correct the typo in attributs ;) ):

// the five next lines set global render attributes
// comment or edit these lines as necessary
select -ne :defaultResolution;
setAttr ".w" 720;
setAttr ".h" 480;
setAttr ".dar" 1.34997;
setAttr ".ldar" yes;

Now this little colon solved the 320*240 comp issue. If you save now and import to AE your comp should be the correct size and framerate and you should have a correct camera motion (only the tracking points are still missing).
What would interest me is if the Maya ma format specification actually requires this colon and Maya is just more forgiving on import or if the AE import is too unforgiving?

Ok let's continue with making the tracking points show up in AE.

4. Check out this line which stands for one track (different programs put out different naming and parenting, also in this example it is an Auto track while there could also be differently named tracks like locators, manual tracks etc.) :

createNode transform -n "Auto0000" -p "Auto_Tracks";
setAttr ".t" -type "double3" 7.86996 4.28757 -15.3173;
setAttr ".s" -type "double3" 1 1 1;
createNode locator -n "Auto0000Shape" -p "Auto0000";
setAttr -k off ".v";

To make it work properly it should look like this:

createNode transform -n "Auto0000";
setAttr ".t" -type "double3" 7.86996 4.28757 -15.3173;
setAttr ".s" -type "double3" 1 1 1;
createNode locator -n "null_Auto0000Shape" -p "Auto0000";
setAttr -k off ".v";

AE won't create a null for your tracking point if the locator name doesn't start with “null_”.
If you leave the “-p "Auto_Tracks" “ in there (which is a command for parenting) AE will create 2 nulls or more with loads of parenting for every single Track which is unnecessary.
Test it out yourself and get rid of it.
The first attribute is the position of the null and the second the scaling. Scaling will determine the scaling percentage of the nulls created in AE during import. Every track you exported from your matchmoving program will result in the creation of a null with a size of 100x100 pixels.
Scaling set to 1 ( 1% ) will result in a reasonable null size in your comp (although this depends a lot on your scene scale, in a large helicopter shot this could need to be set higher). You can of course also change this in AE after import. In the Matchmover Pro export dialog, point scale will set this value. In Boujou i think it defaults to 5.

Changing those names etc. is best done with the replace function in your favorite editor where you should have an interface similar to this:

Replace: createNode locator -n "
by: createNode locator -n "null_

and

Replace: -p "Auto_Tracks"
by:

Clicking "replace all" will make the computer do all the work on the hundreds of tracks.

5. Save the file. Import into AE and be happy! :) In case something doesn't work, play around with the file some more or write me a comment that my instructions are crap ;).



Disclaimer: I'm not responsible for messed up maya files. Make a copy of the file to a safe place before playing with it.

18 comments:

Anonymous said...

Can you give any advice on how to get the free tracker, voodoo tracker, (file:///C:/Program%20Files/voodoo%20camera%20tracker/docs/manual.html#download)to work with AE?
Thanks

Loga said...

Voodoo can output a standard maya file. The maya file is well structured and with the procedures described in the article the import works really well.
The only problem is that Voodoo doesn't feature adjustable coordinate systems yet.
So you have to do all the scaling and orientation in AE with parenting, which is a bit cumbersome.
But then again Voodoo is free and it works, so that's pretty cool.

Anonymous said...

Thanks a lot!!
I was going to say incredibly useful, but so far I've only changed the framerate to PAL, but still - without this page, I wouldn't have had any idea!!

Anonymous said...

Good for people to know.

mihai said...

Thanks for the info, but Im wondering if there's any way to change the frame rate in the .ma file to something other than 30 or 24. Id like to make it 12 -- tried replacing 'film' with '12' but no dice. Any ideas?

Loga said...

Good question. I don't have maya here to play around with it.
Quick workaround would be using film (24fps).
Then after import stretching your camera layer to 200% and then setting the composition frame rate to 12.

Joe Rule said...

I've followed this tutorial along with a couple others and i still can't get it to work properly.

-I export tga out of ae after deinterlacing. 270 frames
-import to voodoo set up free move, no interlace.
-set up camera with user fixed focal length. (5.1mm)
- tracks fine with .53 accuracy
-export to maya
-edit maya as shown
-import to ae and the comp is wrong size, pixel aspect ratio is wrong and frame rate is wrong in comp with nulls.
-fix all that and put a black solid in the scene
-the solid moves generally with the camera, but not nearly exact, (i compared it to a duplicate solid parented to the camera)

ANY help would be greatly appreciated!

Joe

Loga said...

Hey Joe,

wrong is relative (it is better to specify how wrong).
As you write that you deinterlaced your footage before tracking i guess you're working with PAL or NTSC footage with non square pixel aspect ratio.
Matchmove software and visual effects generally don't like non square pixel aspect ratio that much. They work in square pixels.
In AE the comp with the camera and nulls is always square pixels so the comp size is indeed different than your footage.
The result is then scaled to non square pixels in the other comp that was created.
I assume that was the problem.

I don't understand the wrong frame rate though. Please check if you followed the instructions considering frame rate carefully.

A solid parented to a camera stays always at the same position in the image as it moves exactly with the camera.
A solid placed somewhere in the 3D comp should move around and stick to other objects in the image who where in the same position in the original filmed scene.

Loga

Joe Rule said...

thanks for the help. sorry for not including the exact frame rate etc. here it is.

The comp with the nulls in it:
1296x1080, square pixels, 30fps
(1296x1080???)

The comp that the null comp is precomposed in:
1440x1080, .9 pixel ratio, 30fps
(i think it probably got the .9par and 30fps from the NTSC setting)

I am working with 1440x1080 1.33 pixel ratio, 29.97fps

I think you are right about the pixel ratio messing it up. If i converted my 1440x1080 footage to 1920x1080 before tracking with voodoo, would that help?

Maybe I need to convert my footage to 30fps or 24fps before tracking?

I double checked the maya file. the only thing thats different in mine is an underscore in the autoxxx

Example:
Yours: auto000
Mine: auto_000

Yours: Null_auto000Shape
Mine: Null_auto_000Shape

Again thanks for all the help.

Joe

Loga said...

Hi Joe,

yes i would scale up to 1920x1080.
Those HDV resolutions probably confuse Voodoo.

If the framerate is 29.97 or 30 shouldn't matter that much. As long as each frame has a keyframe for the camera everything is fine.

Loga

Anonymous said...

I'm not able to get any null's. when I import the .MA file I don't see any key frames eather.

I am useing voodoo, what I had changed was

// the five next lines set global render attributs
select -ne :defaultResolution;

and only this line.

createNode locator -n "null_voodoo_scene_shape" -p "voodoo_scene";

what am I missing?

Loga said...

You have to change the name of many more locators.

Futher down the script you should have loads more under "// 3D feature points".

If there are no locators then you haven't exported them properly from voodoo.

To check if animation for the camera has been exported check out all the "createNode animCurve.....
setAttr...."
commands. There you can see all the keyframes for all camera transformation channels.
If there are no keyframes then something in your solve might be wrong.

Eric said...

This works wonderfully going from Voodoo to AfterEffects. Thanks so much for your work!

Ben Hughes said...

You sir, are a genius.

jim said...

This is such an excitingly brilliant tutorial and I'm NEARLY there!!

Except for the fact that running the tweaked AE script brings in my 1920 x 1080 PAL project in at 1745 x 1080. A similar problem to Joe Rule back in '08.

I've tried shanging the pixel aspect ration from square pixels to PAL widescreen but it's not *really* worked (looks a bit better but not as perfect as the co-ordinates in Matchmover relative to the image.

Any help/advice would be great but thank you already for teaching me something really rather cool to begin with!!


jim

www.jimlefevre.com

Loga said...

Hi Jim,
hope you figured it out yourself.
I'm a bit out of the AE game so can't help you out with troubleshooting.
Peter

jim said...

HEY HEY HEY!!!

After much wrangling and heartache a colleague of mine at work here has written the most awesome PC program thing that converts ALL tracking points into txt files that are copy and pasteable into AE.

I'm working with a 25fps 1920x1080 project so I know that works although not entirely sure if it works for any other comps...

I can't tell you how useful it is and once you've done it once it's actually very very simple.

Not sure how to get in contact with me to get it (and supporting bumpfh) but you could always try me through my site - www.jimlefevre.com - email address is in the about bit I think!

Loga said...

Hey Jim,

thanks a lot for the offer. In case i'm stuck with this problem in the future i will surely contact you.