7 Replies Latest reply on Jun 23, 2014 5:36 PM by guyofgod

    Deleting every nth frame (again)

    sinious Most Valuable Participant

      Hey all,

       

      I have a video where every single 5th frame is a duplicate. So I need frames 0,1,2,3 - 5,6,7,8 - 10,11,12,13 - etc...

       

      I've seen this post but I myself am not familiar with expressions enough to write it just by what the person is suggesting.

       

      I found a few suggestions such as:

       

      f = timeToFrames();

      n = Math.floor(f/5);

      framesToTime(n+f);

       

      Also this from a random YouTube video I can't find:

       

      f = timeToFrames();

      p = Math.floor(f/1);

      framesToTime(p*1.5);

       

      Neither work. The frames start jumping erratically. 2 frames at a time, then 150 frames, etc etc.

       

      In general programming to iterate and skip every nth number I'd just do a modulos check and skip any 0 sum. Something like:

       

      f = timeToFrames();

      n = f % 5;

      if (n == 0) { f++; }

      framesToTime(f);

       

      This also produces some really odd frame counts although it doesn't jump to the hundreds eratically. It just doesn't work.

       

      How would I skip every 5th frame?

       

      Thanks for tips!

        • 1. Re: Deleting every nth frame (again)
          Mylenium Most Valuable Participant

          Neither work. The frames start jumping erratically. 2 frames at a time, then 150 frames, etc etc.

           

          That would only be true, if the framerate is a fractional one like 23.96 or whtever. Of course this messes with the logic of discrete frames as integer values, if you don't have any precautions built into your code. Just the same happens when multiplying back with fractional values like in the second example or adding back the normal time as per the first example. Time in AE is a "real" time, not an arbitrary multipication of frames with a fixed factor. What you are seeing is perfectly normal. And your own code doesn't work, because you are not running a loop - AE does not store persistent variables, it can only accumulate values over time. Therefore your code only increments by one frame every 5 frames and returns a much smaller value. Additionally, of course you are missing the else statement, so your code doesn't know what to do when the condition is not met and the whole expression breaks. It's simply sloppy syntax (no offense).

           

          Mylenium

          • 2. Re: Deleting every nth frame (again)
            sinious Most Valuable Participant

            Here's a 5 second example of PHP iterating over the same logic perfectly. Regardless, my code didn't have an 'else' because it never needed one.

             

            What my code attempt did, that do I do NOT claim should work, just an attempt, is ONLY add +1 to the value of the current frame IF the modulos returned 0 (it was a nth frame to remove). The next line of code is run regardless if I'm skipping or not, so I don't need an else.

             

            Thanks for reminding me to include details. The footage is 1920x1080p 30fps ap1.0 video from a stock video site. They repeat every 5th frame for some reason. I'm simply trying to remove it.

             

            Now that we know we're working with 30 and not 23.976 or 29.97, does this make a difference in the script?

             

            edit:

             

            Regarding the persistence, this is just me making an assumption with the already previously addmittedly lack of expression knowledge. I would assume that this script is run every single frame. I would then assume f = timeToFrames(); is my iterating value. That's what I'm depending on.

             

            Here's what I don't understand. Is this able to actually skip the playhead +1 frames? That is my intention on export. To skip the playhead over that frame.

             

            re-edit:

             

            In the expression manual:

            Though the expression language is based on a scripting language, a subtle but important difference exists between a script and an expression: Whereas a script tells an application to do something, an expression says that a property is something.

             

            I think I'm beginning to understand a bit about what you're saying. I can't skip the playhead because I can't do that. I have to somehow come up with a way to calculate what frame I should be showing regardles of the current time. The current time will always progress from start to finish but my calculation needs to do the work of re-adjusting what the actual time should be, controlling what is showed.

             

            If I have no persistence, yes, I'm a bit lost on how I'm supposed to figure out what frame I showed last. I'm going to need to use the current time to figure out how many times I've cut a frame out by then and add that to where I am, no? And that's the logic that looks like what the very first bit of code I posted seems to do.

            • 3. Re: Deleting every nth frame (again)
              Dave LaRonde Level 6

              You could jump through all those hoops in AE, but if it's at all possible, I heartily recommend the following:

               

              Apply a vigorous Dope Slap to the back of the head of the genius who thought creating 3:2 pulldown was as simple as putting 23.976 footage into a 27.97 timeline.  Insist that Einstein give you 23.976 files.  If Einstein needs 29.97 video for ultimate delivery, you can do it easily and CORRECTLY in AE from a 23.976 comp.

               

              I hope for your sake and sanity that it's possible.

              1 person found this helpful
              • 4. Re: Deleting every nth frame (again)
                Mylenium Most Valuable Participant

                Here's a 5 second example of PHP iterating over the same logic perfectly.

                 

                Sure, but PHP automatically stores every valid last value of a function and fetches it in the next cycle. So unless it is an invalid data type or an invalid result (division by zero etc.), it will always return true and evaluate. AE dimply doesn't have any such thing. Therefore f++ does nothing but increment any value assigned to that variable until either the internal limit is reached and the engine runs out of iterations or the counter overflows for other reasons. Without any further logic this is useless.

                 

                And that's the logic that looks like what the very first bit of code I posted seems to do.

                 

                No, it doesn't. It merely returns the current time quantized to the next possible value fullfilling the equation, so at 5 frames it will skip the 5th frame and at 10frames the 10th only, but not the 5th. If you will, it doesn't tighten the gap as in fact at frame 10 you actually want it to skip frame 9 after frame 5 has been excised. Again, your only chance is to count all frames, which could be doen with an if()else() statement inside a loop (pseudo code):

                 

                for(f < x,f=0,f++)

                {

                if (n%5 == 0)

                {f-1}

                else

                {f}

                }

                 

                f is your frame, x the comp duration in frames. The rest should fall in place, if you have programming experience.

                 

                Mylenium

                • 5. Re: Deleting every nth frame (again)
                  sinious Most Valuable Participant

                  We paid $500 for a short clip of this HD car driving by. Amazingly, no, they don't have the correct fps source (we already asked).

                   

                  I'm taking the cop-out..

                   

                  Exporting a sequence of images, rm *5].png, rm *0].png, reimport, done..

                   

                  Thanks anyhow

                   

                  edit:

                   

                  Mylenium~

                   

                  Mylenium wrote:

                   

                  for(f < x,f=0,f++)

                  {

                  if (n%5 == 0)

                  {f-1}

                  else

                  {f}

                  }


                   

                  In the spirit of understand anyhow I'd like to determine what you mean. I've never seen a for(condition, evaluation, iterator) constructed like that so I'll reconstruct it to my knowledge as AE is said to use ECMAScript 1.2 so I should be familiar..

                   

                  Nope... Nope I tried but I cannot see the logic in the script at all. There are magical things going on here. I see no assignment, just an iterator that will actually cause an infinite loop as you're iterating f at the same time you seem to want to subtract 1 from it every time modulos is 0.

                   

                  e.g. as soon as f = 5, modulos returns 0 thus f is 4, script runs again and iterates to 5, rinse repeat infinitely.

                   

                  I know that the last 'value' is automagically applied to the current property so that's how I assume f is being applied to the time. I just don't see why you want to subtract from f and not add to it.

                  • 6. Re: Deleting every nth frame (again)
                    wiclies Level 1

                    try this as your Time remapping expression:

                     

                    framesToTime(Math.floor(timeToFrames()*1.25)+0);

                     

                    IMPORTANT: you must replace the "+0" at the end of the expression with an integer between 0 and 4 WHO SUITS YOUR NEEDS. "+1" worked for me, but your video surce determines this number, so you 'll have to try all 5 integers.

                    Not an elegant solution at all, but it worked for me.

                    • 7. Re: Deleting every nth frame (again)
                      guyofgod

                      wiclies wrote:

                       

                      try this as your Time remapping expression:

                       

                      framesToTime(Math.floor(timeToFrames()*1.25)+0);

                       

                      IMPORTANT: you must replace the "+0" at the end of the expression with an integer between 0 and 4 WHO SUITS YOUR NEEDS. "+1" worked for me, but your video surce determines this number, so you 'll have to try all 5 integers.

                      Not an elegant solution at all, but it worked for me.

                      I know this is old, but logged in to thank you willies! Your script did exactly what I needed.

                       

                      In my case, for search engine benefits, the render farm we used for rendering out 3D mograph from C4D threw a garbage duplicate of frame 1 in our render every 5th frame (sequence images). I didn't want to delete every 5th frame, even though I had it in a sequence, because then I would get errors from After Effects thinking I was missing those frames.

                       

                      I was ripping my hair out - thanks for this again - an admin or mod should definitely set this as the "correct answer".