Skip to main content
Participant
April 14, 2022
Answered

Bug using dan eberts clock expression

  • April 14, 2022
  • 3 replies
  • 677 views

I've never seen this behavior before I've got after effects updated to 22.2.1

The buggy behavior is illustrated below. It happens on whole seconds for one frame.

I've set up the clock to display in tenths of a second. Below is the clock output for every frame.

1.9, 1.9 1.9, 1.0 ,2.0 ,2.0, 2.1, 2.1, 2.1, 2.2 ... 2.9, 2.9, 2.9, 2.0, 3.0, 3.0 etc

the error is in bold

 

the video ive been given is 30.303 fps

Here is the code I'm using

 

rate = 1.0101;
//tried making the rate 30.303/30
//ive tried 1 same behavior
clockStart = -10.06501006501007;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint)

// this is all to get the clock to start at 0 in a certain part of the clip
//clockTime = clockStart + rate*(time - inPoint); start frame was 5024 then divided by 30.303
// now i cliped it so clockstart will be at frame 5024 identified by wmh so 5024-4720 / 30.303 = 10.03201003201003
//still off by one frame so add 1/30.303

if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}

t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.toFixed(1).substr(-1);
//sign + padZero(hr) + ":" + padZero(min) + ":" + padZero(sec) + "." + ms
sign + padZero(sec) + "." + ms

 

I wish I could post the file anyways thanks for taking a look.

This topic has been closed for replies.
Correct answer Buzzard_Nuts

 

Mylenium,

thanks for replying

Yes I have.

The problem is the clock actually appears to go backwards when using 1 decimal on whole seconds.

I don't know the functions well enough to understand.  where  do I find help on toFixed and substr?

Using the help pull down I  don't find it in scripting help... or expression reference...

The same behavior at 30fps  in a clean one piece of text composition.... with the following code.

rate = 1;
clockStart = 0;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}

t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.

rate = 1;
clockStart = 0;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}

t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.toFixed(1).substr(-1);


sign + padZero(sec) + "." + ms

 

(1).substr(-1);


sign + padZero(sec) + "." + ms

 

3 replies

Mathias Moehl
Community Expert
Community Expert
April 15, 2022

Good that you could already solve the issue.

By the way, if you need an easy to customize counter expression and don't want to write any code, there is one included in iExpressions:

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mylenium
Legend
April 14, 2022

Have you actually adjusted the comp framerate accordingly and/ or played around with the footage interpretation and enforced a different, more standardized framerate? Otherwise this looks perfectly normal in the sense that with your values you'll always have scenarios where two consecutive frames produce identical values do to internal rounding and quantization limits. In such a case one would rather multiply the values with a uniform value before doing the math, then divide them at the end again. I'm pretty sure there is no bug, you just reach the limits of the internal integer math.

 

Mylenium

Buzzard_NutsAuthorCorrect answer
Participant
April 14, 2022

 

Mylenium,

thanks for replying

Yes I have.

The problem is the clock actually appears to go backwards when using 1 decimal on whole seconds.

I don't know the functions well enough to understand.  where  do I find help on toFixed and substr?

Using the help pull down I  don't find it in scripting help... or expression reference...

The same behavior at 30fps  in a clean one piece of text composition.... with the following code.

rate = 1;
clockStart = 0;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}

t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.

rate = 1;
clockStart = 0;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint);

if (clockTime < 0){
sign = "-";
clockTime = -clockTime;
}else{
sign = "";
}

t = Math.floor(clockTime);
hr = Math.floor(t/3600);
min = Math.floor((t%3600)/60);
sec = Math.floor(t%60);
ms = clockTime.toFixed(1).substr(-1);


sign + padZero(sec) + "." + ms

 

(1).substr(-1);


sign + padZero(sec) + "." + ms

 

Dan Ebberts
Community Expert
Community Expert
April 14, 2022

Try this and see if it helps:

rate = 1.0101;
clockStart = -10.06501006501007;

function padZero(n){
return (n < 10 ? "0" : "") + n;
}

clockTime = clockStart + rate*(time - inPoint)
if (clockTime < 0){
  sign = "-";
  clockTime = -clockTime;
}else{
  sign = "";
}

t = padZero(clockTime.toFixed(1));
(t != 0 ? sign : "") + t
Participant
April 14, 2022

The line of code that I believe is giving me problems is

ms = clockTime.toFixed(1).substr(-1);

1 gives me tenths of a second if I use 2 it works as expected with going "backwards"