27 Replies Latest reply on Feb 27, 2008 1:55 PM by (edsmithboulder)

    Inserting Keyframes Between Keyframes

    Level 1
      OK this is what I'm trying to achieve. Basically I'm doing some animations in AE on some pixelation. what i want to do is place the first keyframe and then move the position or whatever (scale/rotation) and then INSERT a keyframe every 2 frames in between these. Basically I want to then Hold these keyframes to make it look like it's not "tweened". Kinda like when you use the "exponential scale" option on something. Now I can do it frame by frame but I was hoping someone might have a nice, quick and easy solution and save me all this hassle this holiday season.

      Ed
        • 1. Re: Inserting Keyframes Between Keyframes
          David Wigforss-Hv1BNN Level 2
          I wish their was an easier way as well, since all my stuff is usually on 2s.. I just hover my mouse over the add keyframe button, click it, ctrl-arrow arrow, add keyframe, ctrl-arrow arrow, etc. Then change them all to hold.
          • 2. Re: Inserting Keyframes Between Keyframes
            Level 1
            BOOOOOooooooo..... Thanks for input David, I reckon if you're not aware of a way to do it quicker then there prolly aint one. Cheers anyway. By the way, nice going on the Dora stuff, my 2 year old loves your work. I'm an Avatar man myself though. We just got canceled here in Dublin. Poor old El Tigre is no more...sniff sniff.
            • 3. Re: Inserting Keyframes Between Keyframes
              David Wigforss-Hv1BNN Level 2
              Thanks! Yeah, I liked Avatar as well, too bad they only intended to make 3 seasons. Apparently (according to an article on www.3dtotal.com and an interview on mtv), there's a movie trilogy in the works with M Night Shyamalan to direct.

              I was a big fan of Catscratch and was sad to see it cancelled.

              Too bad Viacom just slashed my benefits, along with 1400 other non union workerbees... :( :( :( Coming up on 10 years, and rather than getting another week of vacation or something, we get a week less and all our other benefits are reduced or eliminated. Not sure how much I can divulge, but it f'in BLOWS! Merry Christmas.

              I couldn't get an answer whether this had something to do with it -
              http://www.mediaweek.com/mw/news/cabletv/article_display.jsp?vnu_content_id=1003284724
              http://community.tvguide.com/blog-entry/TVGuide-News-Blog/Tv-Guide-News/Don-Imus-Settles/8 00020396
              http://www.reuters.com/article/businessNews/idUSWNAS009120071102?feedType=RSS&feedName=bus inessNews
              http://www.alleyinsider.com/2007/12/viacom-via-cutting-back-on-freelance-benefits.html

              I wasn't aware that working for 10 years nonstop in-house was considered freelance...
              • 4. Re: Inserting Keyframes Between Keyframes
                Level 1
                I heard though that the new Avatar movies can't be called Avatar, cos there's a Cameron movie out now with that name. Apparently there was a bit of a kerfuffle about the whole thing. Anyway, it's crappy about the benefits thing, we don't even HAVE a union over here! Poor little catholic Ireland eh? We've still got a few more El Tigre shows to do early next year but after that...we don't know what's happening. I'm coming up on 4 years here in Boulder and I can put hand on heart and say that i get ZERO benefits. Not even a christmas bonus!! Seriously considered a move to Vancouver but the co-pro limitations there make it hard for non Canadians to make a go of it. JESUS!! I just checked out that alleyinsider article, you guys are getting screwed! There was an interesting description of long term freelancers in there though. Permalancers is a good word...hoe it works out for you man.
                • 5. Re: Inserting Keyframes Between Keyframes
                  (Steve_Patterson) Level 1
                  Ugh. I had a "permalance" job for 6 years. It was for a huge company, so the name looked good on the resumé, and the experience was good, blah blah blah. Still, I had to fork over cash monthly for my own HMO, and had no PTO. Per Diem status is the way the industry turns it's tricks, and it sucks. Sorry to hear that they're being such jerks to you, David. Big companies have a way of screwing the people who work the hardest.
                  • 6. Re: Inserting Keyframes Between Keyframes
                    David Wigforss-Hv1BNN Level 2
                    We (Nickelodeon) used to be non-union.. They picketted our grand opening party when our new studio opened, and placed a 2 page ad in Variety mocking our studio's invitation (it was actually quite clever).. And then the caption. "Glamour Glitz, Miniture Benefits." Our benefits used to be good, but maybe they should reissue the ad now...

                    I'm not quite sure what brought the Animation Union in. I think it may have started with writers trying to bring in the WGA (which we are not a part of to this day, so the strike doesn't affect our studio). The Animation Union however does not cover production staff, editors, animatics, cg artists, audio dept (why no CG, I still haven't gotten a satisfied answer). And the slashing/elimination of benefits doesn't affect HR, Legal, IS&T, Finance, Admin - apparently they're hired for the longterm, whereas production people come and go. Funny, I think I've seen a lot more of those people leaving than production staff....

                    Permalancer - I noticed that term in that article as well... What a f'in joke. Sh*t, if I'm freelance, I should be able to work from home, right?
                    • 7. Re: Inserting Keyframes Between Keyframes
                      Level 1
                      Work from home!! Wow! now that would shave a 2 hour commute off my day for me (Dublin is to traffic what the desert is to sand). I'm actually one of the elite few who have a permanent contract in here though, what that means if the work dries up I don't know...
                      • 8. Re: Inserting Keyframes Between Keyframes
                        Level 1
                        Getting back to the topic at hand, this is a perfect application of the Posterize Time effect. You can simply divide the current frame rate by the number of frames you want to skip. Let's say that your comp is 29.97 fps and you want to only have motion every 8 frames. All you have to do is type 29.97/8 in the Frame Rate value and no movement will happen until frame 9. If you want movement to happen on frame 8 then you simply subtract a very small value from the frame rate. Something like .00009 would probably do just fine.

                        If you want to you could use the following expression for Posterize Time/Frame Rate:
                        s = 8; //number of frames skipped;
                        fr = 1 / thisComp.frameDuration;

                        fr / (s - .00009)
                        This will keep things lined up for quite a while, but if you want to end up exactly at the position of the last keyframe when you get to the last keyframe you would use fr/s in the last line and move your ending keyframe one frame back in time.
                        • 9. Re: Inserting Keyframes Between Keyframes
                          A. Cobb Level 3
                          Maybe I'm misreading the original post, but back when I actually got to work on animation (it's been all motion graphics and compositing for some time now) I used this expression to put my animation on 2's:

                          stepFrames = 2;
                          step = thisComp.frameDuration*stepFrames;
                          prevKey = nearestKey(time);
                          if((prevKey.time > time) && (prevKey.index > 1)) prevKey = key(prevKey.index - 1);
                          valueAtTime(prevKey.time+Math.floor((time-prevKey.time)/step)*step)


                          Changing the value that gets assigned to stepFrames changes the number of frames per "hold".
                          • 10. Re: Inserting Keyframes Between Keyframes
                            Level 1
                            Hi Aaron and Rick, Cheers for the input. Yeah i've reread the original post and I prolly wasn't as clear as I could have been. Basically I was looking for a way to select 2 keyframes that are say...10 frames apart and be able to insert automatically 5 keyframes in between them at 2 frame intervals, similar to when you select "exponential scale". Then I would change these keyframes to "hold" keyframes to make the animation look like it was done on twos and not look all "tweeny". I'm a bit of a scaredy cat when it comes to scripting so I havent really a clue what these expressions would do if I applied them. For instance, if I just precomped all the AE animation and set that comps duration to double it's current length (obviously making sure I had halved the timings to begin with) would that be similar to what would happen with these scripts? Ideally I would like to be able to have the keyframes there so that if I wanted to change part of the motion back onto "ones" then I could easily do that (rather like you might on an old commodore line tester....ahh the halcyon days of classical animation in college). Currently the only other way I can think of doing it is time-remapping the precomp, which is just as tedious. I mean this is not a major issue as it's not a HUGE amount of work to just manually add the keyframes, just thought some of you whizzkids on here might know of a quicker way. I appreciate the scripts though, i'll give them a lash on the animation I have. Cheers again.
                            • 11. Re: Inserting Keyframes Between Keyframes
                              A. Cobb Level 3
                              Well, the expression does put the animation on 2's (or 3's, or whatever number of frames you designate in the first line), but it doesn't do so using keyframes. Rather, it does so by modifying the output value of the property. This has the advantage of allowing you to change the keyframe values, change the keyframe interpolation, or even move them around on the timeline, without having to generate new intermediate keyframes.

                              However, if you want to be able to mix and match different step values on the same property, the expression as written isn't able to do that. I took a crack at implementing the ability to set the step using marker comments tonight. I haven't really thoroughly tested it, so let me know if you run into any bugs:

                              stepFrames = 1;

                              prevKey = nearestKey(time);
                              if((prevKey.time > time) && (prevKey.index > 1)) prevKey = key(prevKey.index - 1);
                              baseTime = prevKey.time;

                              if(marker.numKeys > 0){
                              for(i = marker.nearestKey(time).index;
                              i > 0 &&
                              (marker.key(i).time > time ||
                              parseInt(marker.key(i).comment) != (marker.key(i).comment - 0)); i--);
                              if(i > 0){
                              markerValue = parseInt(marker.key(i).comment);
                              if(markerValue > 0){
                              prevMarker = marker.key(i);
                              stepFrames = markerValue;
                              baseTime = Math.max(baseTime, prevMarker.time);
                              }
                              }
                              }

                              step = thisComp.frameDuration*stepFrames;

                              valueAtTime(baseTime+Math.floor((time-baseTime)/step)*step)


                              If you apply this expression to a property that has keyframes applied to it, then place a layer marker at the point on the layer where you want it to be on 2's, and put the number "2" in the marker's comment field, the animation after that point will be on 2's. When you want the animation to go back to 1's, place a layer marker with the comment "1" at the point where you want the 1's to start. This should work for any nonzero integer ("0" will be treated as if it was "1"), and markers without a comment should be ignored.

                              Again, I haven't really stress-tested this, so there might be some special cases I haven't accounted for.

                              Update: For some reason when I copy the expression back into AE from the forum webpage, it looks fine when pasted, but when I hit Enter, the expression changes such that all the carriage returns are replaced by double question-marks. Pasting it into TextEdit, where it looks perfectly fine, then copying it into AE yields the same result.
                              • 12. Re: Inserting Keyframes Between Keyframes
                                Level 1
                                The first expression works just fine for 2 keyframes but falls apart when you add multiple keyframes. You end up with some really weird combinations of stepped frames. I haven't tried the second expression but it really looks interesting.

                                Posterize time would do exactly what you want no matter where the keyframes are or how many there are in your animation. I think it's an easier and faster solution.

                                Another option is to pre-compose the animated layer, change the frame rate by dividing the frame rate by the number of frames you want to repeat, then checking Preserve frame rate when nested in the Composition Settings Advanced tab. If you set the frame rate to 29.97/3 for example, you're animation would then have 3 identical frames before moving to the next frame. This is the essentially the same as posterizing time.
                                • 13. Re: Inserting Keyframes Between Keyframes
                                  A. Cobb Level 3
                                  Both expressions are designed to make sure that the the values at the actual keyframes don't get overridden by the expression, and the location of the keyframe determines the phase of the step. This means if you put the animation on 2's, and you place your keyframes an odd number of frames apart, you'll get a 1-frame step before the second keyframe. The number of keyframes shouldn't matter. If it's behaving differently for you, please post a project file, and I'll take a look at it.

                                  The first version of the expression I wrote didn't incorporate this feature, and I actually found it lacking, since I couldn't be guaranteed that the value I set for a keyframe would be the final value out of the expression.

                                  The major difference between the two expressions is that the second one looks not only for keys but for layer markers, as well.

                                  And Posterize Time is a fine solution for certain purposes, but when I was working with animation I found it to be inconvenient for a couple of reasons, first and foremost because it requires you to precompose your animation (assuming we are talking about animated transforms here). Expressions allow you to work with the animation and modify the effective frame rate in the same comp.
                                  • 14. Re: Inserting Keyframes Between Keyframes
                                    David Wigforss-Hv1BNN Level 2
                                    Now that I'm back from vacation, I thought I'd give this a shot...

                                    Aaron, this seems to work fine with 2 keyframes, but it's inconsistant with my 4 position keyframes. Between the 1st and 2nd keyframe it seems to work correctly (outputting a new value every 2 frames). However, after my 2nd keyframe, it's going every 3rd, then every 2nd, 2nd, 1, 2, 3, etc. Inconsistant...

                                    I'm working at 24fps and my keyframes are on even frames (0, 20, 92, 116).
                                    • 15. Re: Inserting Keyframes Between Keyframes
                                      David Wigforss-Hv1BNN Level 2
                                      Adobe After Effects 8.0 Keyframe Data

                                      Units Per Second 24
                                      Source Width 435
                                      Source Height 374
                                      Source Pixel Aspect Ratio 1
                                      Comp Pixel Aspect Ratio 0.9

                                      Transform Position
                                      Frame X pixels Y pixels Z pixels
                                      0 101.328 2.75 0
                                      20 129.231 55.2071 0
                                      92 47.3282 252.75 0
                                      116 73.9871 310.332 0

                                      Expression Data
                                      stepFrames = 1;

                                      prevKey = nearestKey(time);
                                      if((prevKey.time > time) && (prevKey.index > 1)) prevKey = key(prevKey.index - 1);
                                      baseTime = prevKey.time;

                                      if(marker.numKeys > 0){
                                      for(i = marker.nearestKey(time).index;
                                      i > 0 &&
                                      (marker.key(i).time > time ||
                                      parseInt(marker.key(i).comment) != (marker.key(i).comment - 0)); i--);
                                      if(i > 0){
                                      markerValue = parseInt(marker.key(i).comment);
                                      if(markerValue > 0){
                                      prevMarker = marker.key(i);
                                      stepFrames = markerValue;
                                      baseTime = Math.max(baseTime, prevMarker.time);
                                      }
                                      }
                                      }

                                      step = thisComp.frameDuration*stepFrames;

                                      valueAtTime(baseTime+Math.floor((time-baseTime)/step)*step)

                                      End of Expression Data

                                      End of Keyframe Data
                                      • 16. Re: Inserting Keyframes Between Keyframes
                                        David Wigforss-Hv1BNN Level 2
                                        Also doesn't work with my Orientation keyframes:

                                        Adobe After Effects 8.0 Keyframe Data

                                        Units Per Second 24
                                        Source Width 435
                                        Source Height 374
                                        Source Pixel Aspect Ratio 1
                                        Comp Pixel Aspect Ratio 0.9

                                        Transform Orientation
                                        Frame X degrees
                                        50 0 0 0
                                        78 301 0 0

                                        Expression Data
                                        stepFrames = 2;
                                        step = thisComp.frameDuration*stepFrames;
                                        prevKey = nearestKey(time);
                                        if((prevKey.time > time) && (prevKey.index > 1)) prevKey = key(prevKey.index - 1);
                                        valueAtTime(prevKey.time+Math.floor((time-prevKey.time)/step)*step)
                                        End of Expression Data

                                        End of Keyframe Data
                                        • 17. Re: Inserting Keyframes Between Keyframes
                                          A. Cobb Level 3
                                          I can't seem to get your keyframe data copied into AE -- the forum is screwing up some of the formatting. But I did just toss my expression in a project and tried it out with four keyframes, and I do see some idiosyncratic behavior. The expression graph looks great at first glance, but somehow some of the frames are just barely missing the steps. I'll take a look at the code and see if I can identify the problem.
                                          • 18. Re: Inserting Keyframes Between Keyframes
                                            A. Cobb Level 3
                                            I'm pretty confident it's a precision problem. When I was testing the expression, I set the frame rate of the comp to 8 FPS to make the math simpler for me to double-check, but I never did any serious testing at higher frame rates -- I probably just eyeballed the graph, which would have looked fine. Problem is, at 8 FPS the length of a frame in seconds is 0.125 -- well within the precision of a float. Not so with higher frame rates. 30 FPS and 24 FPS both yield repeating decimals when calculated in seconds, and it's possible the rounding is introducing enough imprecision to throw off my time calculations.

                                            I'll have to think about the best way to deal with this.
                                            • 19. Re: Inserting Keyframes Between Keyframes
                                              David Wigforss-Hv1BNN Level 2
                                              Thanks for relooking at this. For my current project, I decided to precomp, add expression sliders to control the transforms inside the precomp, and use Posterize Time.
                                              • 20. Re: Inserting Keyframes Between Keyframes
                                                A. Cobb Level 3
                                                Okay, I was close: the problem is a precision bug in AE's expression language (which AE probably inherits from Javascript). It causes certain float operations that should be very straightforward to evaluate incorrectly. For instance, try creating a new text layer* and putting the following expression on its Source Text property:

                                                ( 8.2 - 8 ) / .1

                                                This should evaluate to 2, but for reasons I can't fathom it actually evaluates to 1.99999999999999. In my expression I take the floor of this value, and it evaluates to 1, throwing the cadence of the expression output off by a frame.

                                                I'm working on finding a non-kludge solution.

                                                * A text layer is needed because the values displayed in AE's timeline always get rounded to two decimal places.
                                                • 21. Re: Inserting Keyframes Between Keyframes
                                                  A. Cobb Level 3
                                                  Okay, here is a new expression to try. I'm sorry to be using you as a beta tester, but this float precision thing is new to me.


                                                  stepFrames = 1; //default step value

                                                  function fixFloat(myFloat){
                                                  floatPrecision = 15;
                                                  floatStr = myFloat+"";
                                                  decPos = floatStr.indexOf(".");
                                                  decShift = floatPrecision - decPos-1;
                                                  return myFloat.toFixed(decShift);
                                                  }

                                                  prevKey = nearestKey(time);
                                                  if((prevKey.time > time) && (prevKey.index > 1)) prevKey = key(prevKey.index - 1);
                                                  baseTime = prevKey.time;

                                                  if(marker.numKeys > 0){
                                                  for(i = marker.nearestKey(time).index;
                                                  i > 0 &&
                                                  (marker.key(i).time > time ||
                                                  parseInt(marker.key(i).comment) != (marker.key(i).comment - 0)); i--);
                                                  if(i > 0){
                                                  markerValue = parseInt(marker.key(i).comment);
                                                  if(markerValue > 0){
                                                  prevMarker = marker.key(i);
                                                  stepFrames = markerValue;
                                                  baseTime = Math.max(baseTime, prevMarker.time);
                                                  }
                                                  }
                                                  }

                                                  step = thisComp.frameDuration*stepFrames;

                                                  valueAtTime(baseTime+Math.floor(fixFloat((time-baseTime)/step))*step);
                                                  • 22. Re: Inserting Keyframes Between Keyframes
                                                    David Wigforss-Hv1BNN Level 2
                                                    Improved, but I still found a problem. :) Seems to work perfectly for 24fps comp. I created 5 keyframes (1 second apart), and shifted them to different times along the timeline. Worked perfect for whatever time they were on (I kept the durations the same, just shifted all the keyframes in time).

                                                    However, Whenever I'm working with footage from the Avid (29.97), I pull it down to 23.976. I copied my keyframes, and shifted them so they were on frames (1:00, 2:00, etc). That seemed to work perfect. I shifted it to 0:1:00:00 (1min), and it still seemed fine. I then shifted the start of the keyframes to around 45 seconds, and it screwed it up.. 2 Held, 3 Held, 2 Held, etc.

                                                    So, upon my first quick test, 24fps works fine, 23.976fps is still problematic. Thanks for continuing to look at this.
                                                    • 23. Re: Inserting Keyframes Between Keyframes
                                                      A. Cobb Level 3
                                                      Thanks, I'll see if I can duplicate this.
                                                      • 24. Re: Inserting Keyframes Between Keyframes
                                                        A. Cobb Level 3
                                                        I'm having trouble duplicating the problem you are having. Any chance you can send me a project file? User ID is "aaron.cobb", domain is "mac.com" (trying to keep the spam at bay).
                                                        • 25. Re: Inserting Keyframes Between Keyframes
                                                          Level 1
                                                          OK after much trying to use the scripts you guys so lovingly prepared for me (and yourselves :P) I came up with a great work around. All i've been doing is doing up my main keyframes and then selecting them all and applying the wiggler. I just put in 12 in the frequency if its 24 fps comp (obviously you can change this for your needs) and stick in "0" as the magnitude and voila! I get keyframes every 2 frames which i can then toggle as hold keframes. It's working perfectly on the stuff i've needed it for. Pretty happy with that I must say.
                                                          • 26. Re: Inserting Keyframes Between Keyframes
                                                            David Wigforss-Hv1BNN Level 2
                                                            Wiggler does seem to work great for this.

                                                            I also tried it on a 23.976 fps comp, and after setting the Frequency to "23.976/2", it again worked great.

                                                            Thanks for this tip.
                                                            • 27. Re: Inserting Keyframes Between Keyframes
                                                              Level 1
                                                              Wow...I finally gave something back, this probably equals payback on... hmmmm...3.7% of the favours I owe you guys for stuff you have helped me with in the past. Now all I have to do is fix everything on the wishlist on the other thread and we might just make it to 100% :P

                                                              Hope it comes in handy, I've used it over and over these past few days.