How to create a Countdown in Natron

Trying to create a countdown in Natron.
Added a “Text” node, right clicked on the “Text” field, selected “Set Expression”,
added: frame/30+1

But nothing is printed.
Any tips?
need a 30min countdown with minutes:seconds:frames

use str(frame//30+1):

  • this must evaluate to a python string
  • use the integer division // for forward compatibility with python3
1 Like

Thanks for the hint, still struggling a bit with:
A.) Minutes:Seconds:Frames
B.) reverse it so it counts down not up

Tried it with this multiline expression, but my knowledge in code is just too weak:

time = (frame//30+1)
day = time // (24 * 3600)
time = time % (24 * 3600)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
str((day, hour, minutes, seconds))

This should work:

counter = 1800
fps = 24
time = counter - (frame/fps)
hour = time // 3600
time %= 3600
minutes = time // 60
time %= 60
seconds = time
return "%02d:%02d:%02d" % (minutes, seconds, frame)
1 Like

Thanks for your help, weird things happen, Natron accepts the expression when typing it in,
but when closing the window a popup appears, saying: invalid expression.

It counts down the time in the “Text Node” text window, but in viewer it stays always on 30:00:01

invalid

No error message when entering the expression in text node:

Ubuntu Linux 18.04 LTS, Natron 2.3.15 82693d4

Before, I struggled a lot to do countdown effect, but this expression helped me (I copied from Displaying a timecode in Natron), hope this helps (multi-line should be on):

# Copyright (c) 2018 -- Elie Michel
# MIT Licensed -- Please credit if you use any substantial part of conversion math

startTimecode = (00, 01, 12, 03) # for instance
frameRate = 29.97

def tc2f(timecode):
    """for frameRate = 29.97"""
    (oh, om, os, of) = timecode
    o = ((oh * 60 + om) * 60 + os) * 30 + of
    m = floor((o - 1.0) / (60 * 30))
    return int(o - 2 * (m - floor(m / 10)))

def f2tc(frame):
    frameRate = 29.97
    i = frame + (floor((frame - 1) / (frameRate * 60)) - floor((frame - 1) / (frameRate * 600))) * 2
    h = int(i / (3600 * 30))
    m = int(i / (60 * 30)) % 60
    s = int(i / 30) % 60
    f = i % 30
    return (h, m, s, f)

offset = tc2f(startTimecode) - 1
ret = "%02d:%02d:%02d;%02d" % f2tc(frame + offset)
1 Like

Yes, this finally works!

Thank you!

Edited post to include the source and the exact code. There is step-by-step guide to write timecode expression in the blog.

1 Like