updated blender -> Hitfilm script

Zero to Hero hopefully!, supporting links and downloads below.
 
Blender Camera Solve for export to Hitfilm
Tutorial 1 : This tutorial assumes no knowledge of Blender or tracking, it walks you through installing Blender, basic user interface commands and getting your first scene tracked. 
http://www.youtube.com/watch?v=VREMV00PKJ8
 
Tutorial 2 : I work through how to camera solve the track including lens distortion etc.
http://www.youtube.com/watch?v=EgcDdEzh3aA
 
Tutorial 3 : I explain how to install the Blender to Hitfilm export script and use it.
https://drive.google.com/file/d/0By8EUjcMjNPRb2lOZWdQOEJHZGM/edit?usp=sharing
http://www.youtube.com/watch?v=Gk-YTHA1-Jg
 
Image files used in this demo can be downloaded here
https://drive.google.com/file/d/0By8EUjcMjNPRVWxtLWxHQ2hXYm8/edit?usp=sharing
 
Script Updates
15/01/2014 18:54 added new file name
21/01/2014 21:33 changed how animation of emptys calculated, fixed orientation, location is always from global so if it's following a path that will get exported.  Rotation is from local so if it's not baked it will be whatever the rotation or animated rotation of the object is, if it is baked you'll get the additional constraint rot added etc.
 
General comments, (covered in tutorials)
  • It's vital you set the frame rate correctly in blender before you export, hitfilm uses time code in the xml for frame rate so I have to calculate that off the frame rate so it all stays in sync.  Make sure you have the framerate set correctly to match in hitfilm as well.
  • I'm calculating the zoom off the sensor width etc. just keep that at what your track has refined to I pull it from there.  I've tested with my GH3 and Iphone 5 and the random clip in the first post I guessed at the settings for in the first post they all resolve ok, have done some decent pans etc as well.  Worth getting lens calibration correct as well but the refine works quite well for that also.
  • If you want to export emptys you have to create them where the track point is you want and select them to export, I can change it to auto export everything to skip that step, but I've left it working like that for now.
  • By default it will not animate emptys as that takes up loads of space in the xml file, if you look on the export page under scale I've added an export empty animation option so if you have created funky path animations in blender you can parent the empty(s) to that and export into hitfilm, that's pretty cool, watch out for gimble lock that’s not a script bug but a maths issue with Euler
  • I've tried hard to get the orientation in the blender export to match what gets into hitfilm.   I try and keep the camera scale at 1 and the xyz planes looking sensible so if it's a pov shot something like  stick the camera at 90deg rotation parallel to the floor on the x axis as well then it comes into hitfilm at 0 pointing straight ahead for a start
  • If there is media that has been tracked the export script will attempt to add that to the composite shot, worst case scenario just link it back in hitfilm.
  • I had to derive a lot of this, there's no published api for the XML, I didn't pay much attention in math class about matrix multiplication and euler etc and had to teach myself python/blender etc as I went along so don’t rely on it for paid blockbuster work :)
  • Gimbal lock with the animation export  is not that big a deal you just need to be aware of with certain types of animation it so if you see funny animation glitches like in my example spinning banana on a circular path following the path video try changing the relevant objects Euler order of calculation in blender (as gimbal lock video) or work around it in hitfim as I have shown in the example vid I just exported following the path in space but not in orientation to the path just let is spin then key framed orientation every 90 deg in hitfilm to replicate what was happening in blender.

 
http://www.youtube.com/watch?v=HdMqYPbUdHM
http://www.youtube.com/watch?v=zc8b2Jo7mno
 
Known issues
  • You might get an error popup R6034 application has made an attempt to load the C library incorrectly when you first load the export module.  Just click ok, it's a bug on windows with the UUID python lib that i needed for the xml creation and hitfilm, you can look in the code first if you don't believe me ;)  Shouldn't get it on linux/mac (i've tried to use libs that will work cross platform).  Need to figure out workaround.
  • If you do save as in blender to a different directory than the original file was in I get a relative reference to the media that I can't resolve so you have to load the media separately.  If you do save as a different file name in the same directory it's fine.  I can fix that just need to figure out better place to get media file path.
  • I need to re-factor the code (putting it politely ;) ) add proper error handling etc. this is just raw first pass to get it working ish.
  • I need to read the blender guide on writing export scripts correctly I didn't realise there was one until the end so will need to tidy it up ;-)

 
Old .ma export script
Fixed to the scaling issue with the blender to hit film camera path animation export extension when I was searching about to see how to do it.  I had a quick look while I was figuring it out and I think I've fixed it, basically the original version and the one it was based on had hard coded the sensor width size to a fixed value (not that it was obvious it's an maya attribute called .cap that says its an aperture setting and takes inches :0) ) so if you are doing a solve in blender and have that set to anything but the default it throws all the calculations out.
I've changed it so it pulls it from the active blender session and converts the width to inches and it appears to work now with my limited testing and pixel ratio of 1 with 1080p and 720p.  
YMMV but it works for me.  The's a bug with the rotation translation in the script as well that crops up every now and then when the axis flip from - to +, I'm just rewriting that part but I'm back at work tomorrow so might take a while and I could get distracted and haven't done any python or maya so figuring it out as I go along but as usual it's finding the relevant API references rather than stringing the code together, I'm a bit rusty but if I can do it I'll post it as an update.
https://drive.google.com/file/d/0By8EUjcMjNPRbzFyaHV5ZEpjZ0k/edit?usp=sharing

I've been using blender 2.69 into hitfilm ultimate for my tests with the camera solver.
http://www.youtube.com/watch?v=XUa5TTLYc-Y
Mark
«1

Comments

  • Had anyone got a camera track *.ma file exported from something like pftrack they could upload so I can compare it to what's getting exported by the blender export script.
    Something funky going on with the x rotation translation. I know blender is 90 deg different in the x orientation but the translation looks ok in the generated export just when it gets imported into Hitfilm it seems to do a further translate that orientates the camera ok but it's right on the boundary of a full rotation which confuses matters (can be corrected manually by adding either -1 or +1 to the full rotation value key frames in Hitfilm where there is an issue but it's a bit of a pain and I'd like to see if I can fix it then it will work nicely.
  • Mark... thank you, thank you! Gonna try this out in a bit.
  • Moved this from tech support to Techniques, so hopefully more people will find it. :)
  • edited January 2014
    Let me know how you get on it worked ok for me just that annoying rotation issue :) I'm sort of toying with the idea of binning the .ma output and writing out a hitfilm composite file as they just appear to be simple xml, will have a play around in the coming weeks see what I can come up with if there's a simple fix for the .ma file for the rotation I'll do that.  The hitfilm composite file would be nice as I could potentially include media etc. as well and could build on the .jsx afterefect export code basically just make sure the axis and rotation are changed for any difference between hitfilm and AE and write out xml instead of javascript shouldn't be a massive deal (famous last words!)
    Would be really useful if someone has a pftrack export to .ma to see how they format it I'm waiting on my demo licence wasn't as simple as just downloading it.
  • Hey, thanks for all of your hard work. 
    The export script seems to work fine, if you animate a Blender camera manually or if you use an empty to animate the camera, which is really great if you want to do mograph.
    I still see that X rotation issue if I export a camera that's been matchmoved in Blender though. 
    Try talking to this guy, http://hitfilm.com/profile/5477 or this guy http://hitfilm.com/profile/1543 if you can. I think they were both working on fixing the Blender to HF2U export script as well, so that it works in Blender 2.69. They may have a solution, or are at least very close to solving this.
    Great idea, it would be awesome to be able to export a HF2U composite shot from Blender. :) 
    I would ask around to see if one of the guys "users" on this forum, still has PFhoe as well as PFtrack. Maybe both programs export camera data in the same .ma format?
  • I got my hands on a trial of pfmatch (which is awesome btw!) I analysed the same scene and managed to reproduce the same issue with the x axis, I'm fairly sure it's a bug with how hitfilm is parsing the .ma file (but as always I could be wrong!)  the x axis rotation appears to be getting an additional rotation translation applied for example if x rotation == 0.1 degrees it gets imported into hitfilm as -359.874 degrees so if your camera is rotating up and down in hitfilm it can easily flip around and cause issues.  Y and Z port in ok.
    I thought there may be an extra parameter in the ma file that was missing in the blender version but hitfilm imports the pftrack ma files the same with the same translation, basically if you spend time setting up the floor plane in blender or pf track and the x axis rotation is around 0 i.e. camera pointing straight ahead you may run into issues.
    Workarounds I can think of are deliberately set the x axis rotation out buy enough degrees to accommodate the motion then parent everything to a 3d point in hitfilm and fiddle about with the floor plan there or and easier solution I think is just step through frame by frame and where there is a keyframe that causes a flip just add -1 or +1 to the additional rotation setting then all subsequent key frames after until it stops flipping.  It's just a one time deal and less frustrating than trying to align the floor plan manually after import I think which does my head in :)
    going to start working on a hitfilm composite export file export, I've checked and that does not apply any additional rotation so should work nicely, watch this space :)
  • Mark, 
    Thanks for trying to figure this out. Will surely keep an eye on this thread. :)
  • Mark... holy crap dude!!! Thank you, thank you, for all of your hard work. Gonna try this in a little bit. Will respond with results. ;)
  • Mark... holy crap dude!!! Thank you, thank you, for all of your hard work. Gonna try this in a little bit. Will respond with results. ;)

    Don't get too excited it will be a rough start I'm sure, good news is I think I've broke the back of it so I'm hoping that it will be mainly different systems config / orientation / scale issues if it doesn't work, I've had some excellent results with some stuff just playing with one now :)
     

  • Hmmm, I get this error when I try to install the addon. I removed the older .ma export script. Any insight?
    6lf5.jpg
  • Hmmm, I get this error when I try to install the addon. I removed the older .ma export script. Any insight?
     

    Sorry added a period to the file name when I uploaded it, forget it doesn't like that, I'll update the link in the mean time just rename the file to export_hitfilm_camera-v96-alpha.py or something like that and it will work.  I gave it a different name to the .ma file so you should be able to run side by side I have been.
    see told you not to get excited :)
    let me know if that works!
    Mark

  • Duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude... it works! ;P
    In HF2U, it's off by -1.3 on the z axis but it's an easy fix. Everything else is so damned perfect! PERFECT!!!
    Thank you Mark... thank you times infinity! Best day ever!  :D 
  • Duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude... it works! ;P
    In HF2U, it's off by -1.3 on the z axis but it's an easy fix. Everything else is so damned perfect! PERFECT!!!
    Thank you Mark... thank you times infinity! Best day ever!  :D

    Nice one that went better than expected :^) if you can give me some detail at some point (no rush!) about the z axis error or send me a simple blender file showing the issue I can probably figure it out, may as well fix any bits while I have it fresh in my mind.
    Do you mean -1.3 deg rotation around the z axis, I'm wondering about what else I could do now I've got started ;) but need to get this tided up first to get a good base to work on.
    Will shoot some fun footage that will be good to write a demo around over the weekend, fed up with with looking at the stuff I shot to figure it out with!  I'll do a separate one for the animation export, I really like, not sure what I'll every use it for but it's really nice!

  • Whoops... I lied. It's -2 degrees in the Z axis. Easy fix though! :)
  • Whoops... I lied. It's -2 degrees in the Z axis. Easy fix though! :)

    hmm can't reproduce, if you get a sec drop me a link to the blend file if it's viable and I'll have a look on my system and figure it out, I set up some test rigs to go through the range of motions on each axis for each frame rate to check for that and they all running spot on, would be interesting to have a look see what i missed.

  • edited January 2014
    I'm gonna upload it to dropbox real fast. 
    EDIT.
    Never mind, it's gonna take a bit because I'm uploading it along with an image sequence. You'll have to relink the footage in HF2U.
  • Man.... this is exactly why it takes me so long to finish projects.... this community keeps producing awesome things that I "HAVE" to try and put into my project that I'm currently working on....  lol
    This looks great, while I haven't looked at using animated cameras in Blender yet, the possibilities to have fine tuning control over a camera and directly importing that into HitFilm will be fantastic...... there's gonna be some late nights ahead -.-
    Someone post something up!!! 
  • Oh nice!
    So the rotational issue is not fixed yet? I too discovered this when I fiddled with the exporter script.. I don't have that much experience on coding so, I managed to fix the zoom value (same way you did now) but that rotational problem is a pain.. I actually told this to Simon some months back and he said that dev's are looking into it. I hope it gets solved! :)
    Great work Mark_e!
  • edited January 2014
    It's not bad guys... have you tried it?
    I'm gonna shoot some footage tomorrow to see if it's still off by, positive 2 degree on the Z axis.  
    Damn... I lied again. The Z rotation wasn't off at all. I forgot that I undistorted the footage that I was using. I was using the original clip instead of the undistorted clip. 
  • Oh nice!
    So the rotational issue is not fixed yet? I too discovered this when I fiddled with the exporter script.. I don't have that much experience on coding so, I managed to fix the zoom value (same way you did now) but that rotational problem is a pain.. I actually told this to Simon some months back and he said that dev's are looking into it. I hope it gets solved! :)
    Great work Mark_e!


    rotation should be fixed the only bit i haven't tried yet is looping over 360 which I should be able to accommodate and add the appropriate rotation vectors looks like the slight degree outage spydurhank was seeing was from the undistorted render v distorted original from a track shot which makes sense.  You definitely don't see the flipping you see from the .ma export hitfilm I fixed that in my script (well I built on a clever persons code who had set up a native export for after-effects :) )  the .ma import to hitfilm over rotates the x axis causing the issue they can copy the euler translation in my script to fix the issue.

  • It's not bad guys... have you tried it?
    I'm gonna shoot some footage tomorrow to see if it's still off by, positive 2 degree on the Z axis.  
    Damn... I lied again. The Z rotation wasn't off at all. I forgot that I undistorted the footage that I was using. I was using the original clip instead of the undistorted clip. 


    Good stuff so it works as expected then :) just downloading the clip to have a look anyway

  • Hi!
    Are you aware that the same kind of flipping might happen on every axis? OR, does they also happen because of the x-axis problem? :) At least I've managed to create such situation. :)
    Nice to know the Z-axis offset wasn't an issue! :)
  • edited January 2014
    Hi!
    Are you aware that the same kind of flipping might happen on every axis? OR, does they also happen because of the x-axis problem? :) At least I've managed to create such situation. :)
    Nice to know the Z-axis offset wasn't an issue! :)


    in the .ma to hitfilm import I've predominantly seen it on the x axis as that gets imported with 90 deg in blender (equivilent to xrot 0 deg in hitfilm) being around -359 deg ish (from memory) so if you have a typical shot with your camera held in front of you you can easily run into issues on a tracked shot.  I'm sure the same can happen on the other axis but at more extreme angles or if you have the axis set up incorrectly in blender or whatever program you are exporting from causing the rotation to fall near those limits to .ma I managed to do that a few times until I got my head around it better and set the alignment nice.  You can deliberately push the axis off in the origionating program to work around it or manualy go to each key frame and add appropriate rotation usually + or -1 and then each subsequent frame until it stops flipping.
    In my new script exporting to .hfcs from blender you should be fine as long as you have the axis set up ok in blender unless you go over -360 +360 rotation which I haven't tested yet and I'm assuming I need to code for to set the rotation flag in hitfilm.
    Next items I'm looking at when I get a chance are exactly working out what scaling needs to be applied to make what you see in blender exactly match what you see in hitfilm and set that as the default.  Work out how to handle rotations over -360 / +360 in blender and convert to hitfilm friendly.  Figure out if I need to add the zoom calculation to the hitfilm z axis as part of the import and what that means to any relative empty locations.  at the moment I'm setting the focus distance the same as the zoom want to check thats a good idea and I'm also setting the hitfilm aperture the same as the originating camera calculation, I want to see if that is required or if I should default to the standard hitfilm aperture.  Once I've done that and anything else that comes up here I was going to tidy up the code make it modular and then see what next.  (all over some time period I'm just doing this in my evenings while it's dark and wet and I can't go out filming stuff so much :) )

     


  • You're writing the script from a scratch? :)
    Why would you want to zoom z axis?
    To my knowledge, that -360 / +360 and 0 / -0 limit value flipping is the worst problem.. At least the .ma exporter script works flawlessy otherwise..
    Ah, but the empties has same rotation flipping problems, as camera rotations. That is if the empties are animated. :)
  • You're writing the script from a scratch? :)
    Why would you want to zoom z axis?
    To my knowledge, that -360 / +360 and 0 / -0 limit value flipping is the worst problem.. At least the .ma exporter script works flawlessy otherwise..
    Ah, but the empties has same rotation flipping problems, as camera rotations. That is if the empties are animated. :)

    No i've borrowed from lots of different sources it's a mash up of the original .ma script, the native AE export script and then random stuff from me as I've figured it out and worked out how the xml for hitfilm hangs together which I wrote from scratch, the maths was the hard part and others did the ground work there I just fiddled with it until it worked for hitfilm but I do understand it now (ish). credits in the script already and I'll link out properly when I get to a stable release. 
    I noticed that mocha added the zoom value to the z axis when it exported it's hitfilm version after tracking, I figured they were doing it for a reason :) I may or may not add it just want to understand why.
    I'm sure I can code for the additional rotations should be fun but for now at least it works for the majority of tracking shots, will just be pure animation there the rotation exceeds -360 +360 my script will need tweaking and I'm on that :)

  • This all sounds very exciting. :)
    Not being a Blenderite, I look forward to somebody putting up some practical examples. :P
  • This all sounds very exciting. :)
    Not being a Blenderite, I look forward to somebody putting up some practical examples. :P


    I'm hopefully going to record a tutorial this weekend for blender tracking into hitfilm with this export script from start install blender to finish export hitfilm with project files people can download, installing the export script etc., been wanting to try my hand at doing a tut for a while this seems like a good one!  It's not that bad, well in comparison to everything else you can do in blender :)  Will do a separate one for pure animation of empties and camera that's pretty cool I just want to finish a few tweaks on the script for that first.

  • It's a quite large bit to swallow with 1 tutorial, but surely blender tracker is pretty easy to handle once you get aquinted with it! Just the basic things explained might be the best.
    By the way, as I did fiddle too with the exporter script, I can provide assistance beta-testing that script and maybe some minor coding help(tho, I do know so little about coding..)

Sign in to comment