https://www.imagineersystems.com/products/mocha-AE/ Mocha is what you need..
Ahron Rabinowitz has done a tutorial all about it.
https://library.creativecow.net/articles/rabinowitz_aharon/Mocha_Tut_1.php
Doing a similar project myself and have spent most the day trying to sort my motion tracking… Latest trial versions of Mocha don’t let you output camera data unfortunately and at £1500+ its a little excessive for the 10sec clip i’d be using it for… Let me know if you manage to find an older version out there..
Also been trying my hand with Bonjou, but not had the results I found with mocha