hey guys welcome back to another blender 2.8 tutorial and today I'm going to be
showing you how to do 3d camera tracking all inside of blender without any add-ons
necessary now because 3d camera tracking is such a big and broad topic and
there's a lot of techniques and 3d camera tracking I'm going to take this
tutorial and split it up into two parts so in this first part we're going to be
dealing with footage that has tracking markers which makes it much easier to
track and remember our goal is to make a camera object inside blender that
matches the motion of the shot so we want the camera to move in the same way
and also have the same perspective and by doing a bunch of point tracks on our
footage blender can solve for our camera so obviously in this shot we're going to
choose to track the markers on our sheet of paper and a harder shot we're going
to need to get more creative with what we pick to track but in this case we
just have it really easy so the first step is converting this video into an
image sequence and this step isn't entirely necessary but an image sequence
doesn't have a frame rate which ultimately gives us a lot more control
so when you can it's always best to work with image sequences but again you don't
have to if you don't want to so all we have to do is go into the movie clip
editor and then just import in our footage
now that it's imported you see on the right panel which you can click end to
toggle you see a whole bunch of information like the resolution the
framerate and also the duration which is in frames and we want the settings in
our blender project to reflect these for the video duration there's two ways to
do this we can either change it manually here to 139 or we can click this button
called set scene frames which does it for us automatically and now these both
have the same frame duration next we need to match the frame rates and to do
this go to the output tab and then look for the frame rate options now in our
case we have a very weird frame rate which is 29.87
and you see that's not an option here so we're gonna have to use custom and we
can't just type in 29.87 because in this case it's
just gonna round up to thirty instead what we're going to do is scale both of
these by a hundred so we have 2987 over
a hundred and you can think of this as division which gives us our correct
custom frame rate and also we have the correct resolution of 1080p by default
now we just go into compositing and start setting up some nodes so make sure
that you have nodes and auto render enabled so you can see what you're doing
and we're going to take this render layers node and delete it with X because
we don't need it for this to bring in our footage just click shift a to add
and then go to input and then movie clip and this gives us our node and make sure
that this is set to the correct footage that we imported before and now all we
have to do is hook these two up and if we want to see what we're doing we're
just going to also add in a viewer node and then just hook it up as well
now that we're done with the setup we're just going to go to the output tab and
then set this export to JPEG and this isn't really the highest quality format
but it doesn't really matter for this tutorial and then we're just going to
create a new folder and set an output path and while we're still in Eevee we
can just hit ctrl f12 to render out our animation
now that we've converted into an image sequence we can start up a new blender
project again we're gonna go to the movie clip editor but this time we're
going to import in our image sequence and to import in an image sequence just
select all your frames with a and then import them and remember that an image
sequence doesn't have a frame rate so we can just go to the output tab and freely
choose our frame rate so I'm going to choose 30 frames per second and for the
project duration we're just going to hit set scene frames again and that's going
to automatically take care of it for us now notice that when we scrub through
the timeline the footage is a bit choppy and to fix this what you have to do is
click prefetch which loads this whole sequence into memory and now this is
playing much more smoothly remember that we get our camera solve
by just having a bunch of point tracks for the blender camera solver we need to
make sure that there's always at least 8 trackers visible during any frame in the
shot so the name of the game is getting as many high quality trackers as
possible we want trackers that last for a long time and have a very low average
error and to help us with this we want to make sure that we're using the best
settings for our trackers the first thing we need to pick is a motion type
and there's a lot of options like location for example which tracks the
location of a pattern between frames but in this case it probably makes the most
sense to use perspective because our markers are kind of getting perspective
warped as the camera is moving we can also enable normalize which is going to
help blender ignore some subtle lighting changes that might have thrown off our
track otherwise this does take some more time to compute but generally it is
worth it lastly in the tracking settings extra we're going to pick a correlation
value of 0.9 this number is basically just a threshold that the tracker needs
to meet during every frame so it doesn't stop so when this value 0 it's just
going to ignore any error and just keep tracking and instead if this number is 1
it needs to be a hundred percent confident during every frame that it's
correct or otherwise it's immediately going to terminate so 0.9 is a very high
value which demands a very high accuracy but it does give us a little bit of
wiggle room so it's not stopping constantly and now we can begin adding
in trackers with control click and in the tracking panel we get a zoomed in
window of our tracker which lets us make fine adjustments and center it we can
also scale up this tracker with s so our whole feature is inside the bounding
box now there's also a second hidden bounding box which we can show with alt
s and this is called the search box the search box just defines where we're
going to search for our pattern between each frame so a larger search box means
it's going to search a larger area but that's also more computationally
expensive for this shot the camera isn't moving around very quickly so we can
keep this search box rather small once we're happy with everything we can begin
tracking manually by hitting alt and then right arrow this is how we track
frame by frame and you see that it's sticking on very well to center this
tracker to the view you can just hit L and that's going to lock it to the
center and after doing a few more frames manually we can
have it go through the rest of the footage by just hitting ctrl T and it
tracks all the way to the end and of course we can also check how good this
tracker is throughout the shot once we're happy with this tracker we can
just lock it by hitting ctrl L and this means that we're done with the tracker
and we can't accidentally move it and mess with the keyframes or anything like
that so now we go back to the first frame with shift left arrow and we have
to do the rest of the trackers now this isn't going to take as long because we
can do all of them at once so I'm just going to pick a couple trackers we don't
need to do every single feature let's do something like ten when you set up all
your trackers you can just select all of them with a and then we're just gonna
hit ctrl T and they're gonna track all together then we can just hit control L
to lock all of them and now it's finally time to work on our camera solve so just
go over to the solve panel and you see a whole bunch of options here so we're
just gonna take them one at a time for the tripod option we're gonna keep this
disabled because this shot has a free moving camera it's not locked to a
tripod and it's not a nodal pan now for keyframe and keyframe a and B options
what this basically lets us do is when we do our camera solve we pick some
range that we deem to be very accurate and then it's just going to extrapolate
that so keyframe a and B is basically defining this range now in this case we
don't really know what we should pick for keyframe a and keyframe B so we're
just gonna let blender decide by enabling this keyframe checkbox and now
we can click solve camera motion and blender is going to solve for our camera
and we get some number which is our solve error which generally we want to
make as small as possible a solve error under 1 is somewhat ok but if we can get
it under 0.5 then that's pretty good basically we want to get this value as
close to zero as possible and as a result our solve is going to become
better and better the first thing we can do to lower our solver errors go over to
the refine options and you see that we have a whole bunch of choices we are
going to choose the focal length and K 1 and K2 option so that blender tries to
calculate what the focal length was in the shot that's essentially how zoomed
in we were and also the lens distortion which are these K1 and K2 numbers and
then we can just click solve camera motion again
the trick for lowering our solve error is to go into clip display and then
enable info and this is going to give us information about the error of each
individual tracker that we had obviously what we want to do is find the tracker
with the highest error and then just delete it we then click solve camera
motion again and we should have a lower solve error so let's say that we're
happy with this now and we want to incorporate it into our 3d scene all we
have to do is click set up tracking scene and already this is looking very
wrong but that's because we just didn't set up our world orientation the first
thing we do is select three trackers on this table and set this to be our floor
we can also pick one of these trackers in particular and set this to be the
world origin so everything is going to be centered from this point we can then
pick any two trackers and choose a distance and then pick set scale so that
the distance between these two points is defined to be however many units we put
in lastly to set up the x and y axes with respect to the origin all we have
to do select a tracker to the left of the origin and then click set x-axis and
then we pick a new tracker below the origin and click set y-axis and now you
see our camera solve is behaving how we expected we can see our results by going
into the rendered view in cycles the plane becomes transparent because
it's set to be a shadow catcher however there are no shadows to fix this all we
have to do select our plane and bring it into the foreground collection we can
also go to the background layer that was set up when we did our camera solve and
we can delete it and now you see that everything is working out as we expect
we're now gonna go into compositing and set up our nodes before we render and
you see we already have this whole network that again is set up by default
when you selected set up tracking scene I'm just gonna delete this with X and
show you how to make a custom node setup we're going to click shift day to add
and then we need our movie clip for the background and then our render layers
for the foreground and we can then overlay these two just using an alpha
over node and then finally we're just going to add a composite node and also a
viewer node so we can see what we're doing and so far you see that we have
the background but not our 3d objects and that's because we didn't render
anything yet so I'm just gonna go to the first frame and then hit f12 to render
and then you see that our render layers node updates and then everything works
out as it should finally in the output tab I'm going to set this to render as a
JPEG sequence which we can save in a new folder and now all we have to do is hit
ctrl f12 to render out the animation and that is the basics of 3d camera
tracking in blender 2.8 so in the next video I'm going to be going over much
more difficult footage but also we're gonna get much more in depth about how
the 3d camera tracker works so thank you guys for watching and I'll see you guys
in the next one