10 Replies Latest reply on May 1, 2016 11:18 PM by Matt Paintin

    Can I re-center a null that has an expression applied?

    Matt Paintin

      Hi everyone


      I have a null that has some 2D tracking applied to it and therefore has a keyframe for every frame in the sequence. The idea is, is to parent footage to this null to create a handheld effect to said footage.


      I have applied an expression to the nulls position and rotation that essentially allows me to dial in the amount of handheld effect on the footage that is parented to the null.


      This all works well until I dial in other expression values. The null gets set off centre and can end up some distance outside the footage window (see attach) which affects the movement of the footage adversely (pivot point for the rotation is not centred)


      Is there a way to recentre the null whilst keeping the effect of the expressions whatever value I type in? (I have tried the 'pan behind' tool but no luck)





        • 1. Re: Can I re-center a null that has an expression applied?
          Mylenium Most Valuable Participant

          Is there a way to recentre the null whilst keeping the effect of the expressions whatever value I type in?

          Sure. But the news that's going to disappoint you is that you will actually have to learn how to combine multiple expressions. Your setup doesn't make much sense, anyway. You don't use parenting, you connect the transform parameters directly with expressions and leave the original tracking data unchanged.



          • 2. Re: Can I re-center a null that has an expression applied?
            Rick Gerard Adobe Community Professional & MVP

            The screenshot is a start but we don't know what your expression is or whether the null was exactly where it was supposed to be before you applied your expression. I suspect the null was where it was supposed to be. The last line of your expression is probably an array. Your expression probably adds or multiplies the original position values. I would have added sliders to the expression to adjust the amount of smoothing for both X and Y and then used a value + statement. IOW if the last line of your expression is [x,  y] I would have changed that line to read:

                 value + [x, y]


            If you can't figure it out with that help we need complete workflow details and to see your expression.

            • 3. Re: Can I re-center a null that has an expression applied?
              Matt Paintin Level 1

              Thanks for your feedback guys...


              Apologies for sounding a little vague but I'm far from competant with expressions....


              You are correct Rick, it begins to drift outside the frame as I multiply the expression values to increase or decrease the effect of the tracked motion.


              I dont know how to set up sliders or have the knowledge to implement expressions to do my bidding so if you have a more streamline approach to achieving a the same thing it would be great to hear your ideas.


              Just to recap my current workflow:

              1.I shot some tracking markers to get some source footage of a handheld effect.

              2.Use that information by tracking the footage in AFX

              3.Apply tracked motion to a null, add a value expression to the position and parent various footage layers to give them the handheld look.



              • 4. Re: Can I re-center a null that has an expression applied?
                Rick Gerard Adobe Community Professional & MVP

                Show us your expression and we can probably help.

                • 5. Re: Can I re-center a null that has an expression applied?
                  Matt Paintin Level 1

                  Rick, is this what you mean?-


                  I alt click on the position stopwatch which gives me 'transform.position' and then I type 'value*x' where x is what ever I decide to dial in.

                  • 6. Re: Can I re-center a null that has an expression applied?
                    Rick Gerard Adobe Community Professional & MVP

                    It looks like you just typed value * 2 as an expression for both position and scale. This will never work at all. Think about it. If the position is 960, 540 and you multiply that position by 2 the new position will be 1920, 1080. You need a completely different approach.


                    You stated that you wanted to be able to "dial in" the amount of hand held effect in the footage. I'm guessing that you used Track Motion to track some object in the scene. I'm also guessing that you tracked something like the corner of a building or a something else that was not moving in the scene so you just got the camera motion. I'm guessing that the null in your comp was supposed to be the Motion Target. There are keyframes for position and scale so you must have wanted to Motion Track both position and scale for the layer.


                    What I don't understand is why there is not a keyframe for every frame for position and every frame for scale. There would be if you tracked the motion of something in the frame and applied that motion to the null. There are only keyframes every 8 frames like there are for position. This tells me that you did not apply the Tracker data to the Null. If you did, where did the other keyframes go?


                    There are a bunch of techniques that you can use to dial in the motion of a hand held shot. Essentially you want to Stabilize Motion in the shot and then adjust the amount or percentage of that stabilization.


                    Let's simplify the approach and just deal with motion and forget scale for a moment. If you had chosen Stabilize Motion from the tracker and picked some piece of fixed geometry in the scene like the bottom of a lamp sitting on a desk and then applied the Stabilize Motion data to the footage you would have a bunch of keyframes for Anchor Point added to the footage. This would keep the bottom of the lamp fixed in the frame but the edge of the frame would creep into the frame as the camera moved around. You could add a null to the comp and add an expression to your footage that tied the null's position to the anchor point of the footage. Let's say you named your footage "stabilized" then the expression would look like this if you used the pickwhip to create it:


                    You could leave off the transform if you wrote the expression by hand.


                    If you then made the null the parent of the stabilized footage the camera motion would return and the black edge problem would go away. You end up with the same shot you started with before Stabilize Motion was applied but you have data that tells you how much camera motion there was in the shot.


                    Now let's think about the math we need. If we could calculate the percentage of movement from the center of the frame we could then add a multiplier that would give us anything from complete stabilization to any multiple of the camera movement we wanted. If we really wanted to get fancy we could change the percentage for movement in X and movement in Y so we could completely smooth out horizontal camera movement while and reduce the amount of vertical movement by half. Let's say that we wanted a value of 100 would give us a completely stabilized shot (we'll worry about the edges of the frame later). Now let's think about the math required and an easy way to adjust the percentage of correction.


                    Expression sliders (Effect>Expression Control>Slider) are a great way to give us control over values in an expression. Let's add two slider controls to the Null layer. Rename one "x adjust" and the other "y adjust". The Effects Control Panel should look like this:

                    Screen Shot 2016-05-01 at 1.34.44 AM.png

                    You rename by selecting the slider (Slider Control), pressing enter and typing a new name


                    Now let's think about the math we need. Here is a short course in expressions setting up variables in expressions.

                    cc = [thisComp.width/2, thisComp.height/2] returns the center of the comp as an array

                    cc[0] would return the x value of the center of the comp

                    cc[1] would return the y value of the center of the comp


                    If we can calculate how much the anchor point value moves from the center of the comp we can figure out the percentage of that movement and then just multiply that percentage by a factor to adjust the amount of movement we want in the footage. Let's begin. Lets start by declaring some variables. tp would be the track point or anchor point of the stabilized footage, cc is the comp center. xa is the x adjust slider, ya is the y adjust slider. The value is divided by 100 to give us a percentage. Now it's time for some math. This is just high school algebra.


                    The ofst is the amount of the track point is offset from the comp center calculated by subtracting the track point from the comp center. Unfortunately to do the rest of the math we have to break the values of the variables into the corresponding parts of an array. [0] is the x value, [1] is the y value. We calculate the offset percentage by dividing the offset value for x by the comp center multiplied by 2. The ofst is adjusted by the slider so that a slider value of 0 is no correction and a value of 100 is 100% correction. xa converts the percentage into pixels by multiplying the comp width by the percentage of offset. x is finally calculated by adding the number of pixels to the comp center. The same math is done for y and then an array is used to return the new position values for the null.


                    tp = thisComp.layer("stabilized").transform.anchorPoint;

                    cc = [thisComp.width/2, thisComp.height/2];

                    xa = effect("x adjust")("Slider")/100;

                    ya = effect("y adjust")("Slider")/100;


                    ofst = tp - cc;


                    xofst = ofst[0] / cc[0] / 2;

                    axo = xa * xofst;

                    xa = axo * cc[0] * 2

                    x = xa+cc[0];


                    yofst = ofst[1] / cc[1] / 2;

                    ayo = ya * yofst;

                    ya = ayo * cc[1] * 2

                    y = ya+cc[1];


                    [x, y]


                    You should now move the CTI (current time indicator) to the first frame. Once you add this expression and parent the stabilized layer to the null the expression will not control the amount of stabilization. If the X and Y sliders are set to zero, there is no stabilization and the camera movement is exactly as it was shot. If you set the X and Y sliders to 100 (100%) then the lamp base in this example does not move in the frame and the edges creep in as the camera moves. If you want to exaggerate the camera movement you just increase the slider values to above 100%. As you increase the value above 100%


                    To take care of the edge problem you can scale up the layer.


                    There are a bunch of other ways to do this. You can use the smoother, found under the Window menu, use hundreds of different expressions, use different tracking strategies. It all depends on exactly what you are trying to do. You could even use this expression with some slight modification to point right to the attach point of the tracker and only use Track Motion. If you wanted to track scale and rotation and position then you would have to write expressions for all of those properties. You could even use Corner Pin or Raw tracking. From what you described I think this solution would work for you providing you did use AE's Track Motion feature to track some fixed geometry in your scene.

                    • 7. Re: Can I re-center a null that has an expression applied?
                      Matt Paintin Level 1

                      Hey Rick


                      Firstly, thank you for such a thorough and detailed breakdown.

                      The whole idea behind this was to add add a handheld effect to some locked off footage. To that end I mounted a couple of tracking markers to a wall and filmed them without a tripod to get a genuine handheld feel. I then tracked this in after effects and applied the motion to a null to which I could then parent any footage I desired. By tweaking the values I could increase or decrease the effect of the handheld motion. This has worked well for me in the past but the 'off centre' null issue has limited me on occasions. I always have to increase the footage in size by a few percent to ensure that I dont lose any edges.



                      In answer to your question regarding missing keyframes - I changed the time on the null layer to 130% which smoothed out the erratic nature of the movement. It has spread out the key frames at the same time.


                      Even the simplest algebra fried my head at high school but I will take a look at the examples that you have kindly prepared for me here and see how I get on.


                      Many many thanks

                      • 8. Re: Can I re-center a null that has an expression applied?
                        Rick Gerard Adobe Community Professional & MVP

                        I wished you had explained that in your first post. You way over thought the project. You didn't need tracking markers and you didn't need to track scale. Here's what I would have done.


                        To get the shot of hand held camera movement I would have shot the same shot hand held and picked two points that had fixed geometry in the middle ground of the scene. For example a lamp on a desk and a book on a bookshelf on opposite sides of the room.


                        I would have then Stabilized Motion and rotation only. No need for Scale.


                        Then I would have renamed the footage Stabilized and and then added a much simpler expression to the anchor point and rotation of the original footage instead of a null. The expression would have been for rotation and position only. I'll show you later this afternoon.

                        • 9. Re: Can I re-center a null that has an expression applied?
                          Pat481 Level 1

                          Try using the anchor point reset feature of this plugin-

                          Motion v2 — Mt. Mograph



                          • 10. Re: Can I re-center a null that has an expression applied?
                            Matt Paintin Level 1

                            Apologies Rick. The outline of my workflow (on post 3 above) must have been lacking some important information........

                            I appreciate your help nevertheless.


                            Pat481 - Many thanks for pointing me at this plug in....only on CS4 here.....and a tight budget!