Jump to: Board index » General » Fusion

Minutes and Seconds Format for Countdown Timer?

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline
User avatar

Dave Dugdale

  • Posts: 149
  • Joined: Fri Dec 28, 2012 4:22 pm
  • Location: Colorado

Minutes and Seconds Format for Countdown Timer?

PostThu Jul 05, 2018 4:43 pm

So I found an expression for a countdown timer:

Code: Select all
Text(math.floor((10000-time)/23.976)+1)


That expression works great for counting down the seconds, however I was hoping to put that in a minutes and seconds format instead of just seconds.

Any ideas on how to format it this way, or is there an easy format expression like:


Code: Select all
Text(minutes(math.floor((10000-time)/23.976))+1)
Dave Dugdale
Learningvideo.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Jul 05, 2018 8:32 pm

Hey Dave - maybe something like the below?

Code: Select all
:startcounter=2000;framerate=30;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60; return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));


just substitute framerate = 30 with required framerate and adjust the startcounter (in seconds) as per appropriate.

I didn't fully check this, so it may require some tweaking.

cheers, Okke
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Jul 05, 2018 8:35 pm

whoopsie - startcounter is currently in frames rather than seconds...
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Jul 05, 2018 8:38 pm

Now in seconds (adjust the startseconds)

Code: Select all
:framerate=30;startseconds=120; startcounter=startseconds*framerate;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60; return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));


EDIT: btw, I'm sure this can be optimized one way or another, but it seems to work!
www.ablackbirdcalledsue.com
Offline
User avatar

michael vorberg

  • Posts: 943
  • Joined: Wed Nov 12, 2014 8:47 pm
  • Location: stuttgart, germany

Re: Minutes and Seconds Format for Countdown Timer?

PostFri Jul 06, 2018 6:39 am

you can also just right click in the text field of the Text+ node and select TimeCode, in the modifier you can select which part you want to see (Hours, minutes, seconds, frames) and a frame rate

if you now animate the "start offset" you can create a countdown that goes faster in time, backwards, ...
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostFri Jul 06, 2018 7:02 am

ha! And that's of course much more elegant :-)

Guessing, I'm loving expressions a bit too much so that I forget to look at the more obvious!

I suppose the one thing that's still handy with the expression is that you can be very flexible with the formatting.
www.ablackbirdcalledsue.com
Offline
User avatar

Dave Dugdale

  • Posts: 149
  • Joined: Fri Dec 28, 2012 4:22 pm
  • Location: Colorado

Re: Minutes and Seconds Format for Countdown Timer?

PostMon Jul 09, 2018 3:29 pm

Thanks guys for helping out! I have tried both methods and if you have a minute can you watch this video to see the issues I am having?



Ok, after making this video I found that by modifying this expression to this works well:
Code: Select all
:framerate=60;startseconds=120; startcounter=startseconds*framerate;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60; return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));
Dave Dugdale
Learningvideo.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostMon Jul 09, 2018 8:32 pm

Hey Dave - glad you worked it out. What I don't understand though is that in the updated expression you use a frame rate of 60, even though your timeline is at 23.976? Are you sure the timeline is indeed at 23.976? Sounds to me that the footage/timeline is at (or close to) 60 fps?

To address a few other points in your video:

- the missing modifier info....double click on the modifier name will show all the info.
- for more info on timecode or any other node, check the Fusion 9 Tooling Reference guide. That has got a wealth of info.

EDIT: I assume in the above that your timeline fps is set the same as your clip fps.


cheers, Okke
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostMon Jul 09, 2018 8:53 pm

BTW - I typically work in Fusion standalone, and I noticed a bit of a discrepancy between Resolve Fusion and Fusion in terms of how the expression behaves. Somehow it has to do with the way the time is interpreted. I need to do some digging!
www.ablackbirdcalledsue.com
Offline

Okke Verbart

  • Posts: 290
  • Joined: Tue Jan 17, 2017 8:40 pm

Re: Minutes and Seconds Format for Countdown Timer?

PostMon Jul 09, 2018 9:29 pm

Also, I noticed a slight error in my expression which leads to the first second being "counted down" within a single frame. The below expression corrects that. Again, change the frame rate as per appropriate.

Code: Select all
:framerate=60;startseconds=120; startcounter=((startseconds+1)*framerate)-1;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60;return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));
www.ablackbirdcalledsue.com
Offline
User avatar

Dave Dugdale

  • Posts: 149
  • Joined: Fri Dec 28, 2012 4:22 pm
  • Location: Colorado

Re: Minutes and Seconds Format for Countdown Timer?

PostWed Jul 11, 2018 3:45 pm

Okke, thanks again for your expression script it works great now. After I am done with this video I will make a video about your expression and how I used it in my project to give back to this community for others with a similar question to mine.
Dave Dugdale
Learningvideo.com
Offline

nemcok

  • Posts: 1
  • Joined: Sun Jan 06, 2019 2:25 pm
  • Real Name: David Nemcok

Re: Minutes and Seconds Format for Countdown Timer?

PostSun Jan 06, 2019 2:29 pm

How would i modify this code to "count up" from zero, instead of count down?
Offline

hlomeli

  • Posts: 1
  • Joined: Thu Sep 26, 2019 6:37 pm
  • Real Name: HECTOR LOMELI

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Sep 26, 2019 6:39 pm

Hello guys,

New user here and post. I "play" with DaVinci Resolve as hobby and had the hardest time finding a way to make a countdown timer.

After some tries, I found a super easy way to do it. I post this video on how I did it, in case anyone needs a timer, and a simple way to do it without scripts or coding.



Hope it helps.
Offline

Glynnman

  • Posts: 2
  • Joined: Thu Dec 19, 2019 4:34 pm
  • Real Name: Glynn Brockway

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Dec 19, 2019 4:38 pm

hlomeli wrote:Hello guys,

New user here and post. I "play" with DaVinci Resolve as hobby and had the hardest time finding a way to make a countdown timer.

After some tries, I found a super easy way to do it. I post this video on how I did it, in case anyone needs a timer, and a simple way to do it without scripts or coding.



Hope it helps.


I was looking for how to do this and found your video. However, as I followed your tutorial what I experienced was the timer would count down but in minutes or seconds. What I was hoping for was a 2 minute countdown that would start at 2 and increment down second by second.

I'll be giving the expression above an attempt.
Offline

Glynnman

  • Posts: 2
  • Joined: Thu Dec 19, 2019 4:34 pm
  • Real Name: Glynn Brockway

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Dec 19, 2019 4:57 pm

Okke Verbart wrote:Also, I noticed a slight error in my expression which leads to the first second being "counted down" within a single frame. The below expression corrects that. Again, change the frame rate as per appropriate.

Code: Select all
:framerate=60;startseconds=120; startcounter=((startseconds+1)*framerate)-1;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60;return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));


Thank you very much for this! Your expression here is exactly what I was needing. The only thing I changed was the first ::Text(string.format("%02.f",minutes):: to ::Text(string.format("%2.f",minutes):: so that instead of 02:00 start timer, it would show 2:00 for a cleaner appearance.
Offline

Wuzzmooz

  • Posts: 3
  • Joined: Wed Feb 26, 2020 11:18 am
  • Real Name: Jacob Thompson

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Feb 27, 2020 6:19 am

Hey all,
Just wondering if this expression could be modified so if minutes = 0 it would only show seconds?
Offline

Steven PS

  • Posts: 2
  • Joined: Thu Jun 09, 2022 9:45 pm
  • Real Name: Steven Stoops

Re: Minutes and Seconds Format for Countdown Timer?

PostThu Jun 09, 2022 9:52 pm

Here is one that I use, Wuzzmooz
Code: Select all
iif(comp.RenderEnd - time > 1439, os.date("%M:%S",(comp.RenderEnd-time)/24), os.date(":%S",(comp.RenderEnd-time)/24))
It sets the timer to be whatever the length is and automatically drops the minutes when it reaches 59 seconds. Of course you have to change the 24 to the frame rate of your project.

I just wish I could find a way to delete the leading zero in the minutes when the timer is less than ten minutes.
Offline

Steven PS

  • Posts: 2
  • Joined: Thu Jun 09, 2022 9:45 pm
  • Real Name: Steven Stoops

Re: Minutes and Seconds Format for Countdown Timer?

PostFri Jun 10, 2022 4:09 pm

Glynnman wrote:
Okke Verbart wrote:Also, I noticed a slight error in my expression which leads to the first second being "counted down" within a single frame. The below expression corrects that. Again, change the frame rate as per appropriate.

Code: Select all
:framerate=60;startseconds=120; startcounter=((startseconds+1)*framerate)-1;minutes=floor((startcounter-time)/framerate/60)%60; seconds=floor((startcounter-time)/framerate)%60;return Text(string.format("%02.f",minutes)..":"..string.format("%02.f",seconds));


Thank you very much for this! Your expression here is exactly what I was needing. The only thing I changed was the first ::Text(string.format("%02.f",minutes):: to ::Text(string.format("%2.f",minutes):: so that instead of 02:00 start timer, it would show 2:00 for a cleaner appearance.


I played around with this one and came up with this that uses the comp length
Code: Select all
:framerate=30;startseconds=comp.RenderEnd-time; startcounter=((comp.RenderEnd-time)*framerate)-1;minutes=floor((comp.RenderEnd-time)/framerate/60)%60; seconds=floor((comp.RenderEnd-time)/framerate)%60;return Text(string.format("%2.f",minutes)..":"..string.format("%02.f",seconds));
Haven't figured out how to remove the minutes when it reaches zero, though.

Return to Fusion

Who is online

Users browsing this forum: No registered users and 17 guests