using DaVinci Resolve's expressions, how to display current position in time:milliseconds instead of time:subframes?
Assistant
To display the current position in time:milliseconds instead of time:subframes in DaVinci Resolve's Fusion expressions, you can calculate the milliseconds from the current frame number and frame rate, then format the output accordingly.
Here's how you can do it:
Calculate the Total Seconds:
Get the current frame number using the built-in variable time.
Retrieve the composition's frame rate using comp:GetPrefs("Comp.FrameFormat.Rate").
Calculate the total seconds by dividing the frame number by the frame rate.
Extract Minutes, Seconds, and Milliseconds:
Calculate the minutes by dividing the total seconds by 60 and taking the floor of the result.
Calculate the remaining seconds using the modulo operation.
Calculate the milliseconds by taking the fractional part of the total seconds, multiplying by 1000, and then taking the floor of the result.
Format the Time String:
Use string.format to create a formatted string displaying minutes, seconds, and milliseconds.
Expression Example:
lua
-- Get the current frame number
frames = time
-- Get the frame rate of the composition
fps = comp:GetPrefs("Comp.FrameFormat.Rate") or 24 -- Default to 24 if not available
-- Calculate total seconds
total_seconds = frames / fps
-- Calculate minutes and remaining seconds
minutes = math.floor(total_seconds / 60)
seconds = math.floor(total_seconds % 60)
-- Calculate milliseconds
milliseconds = math.floor((total_seconds * 1000) % 1000)
-- Format the time string as "MM:SS.mmm"
string.format("%02d:%02d.%03d", minutes, seconds, milliseconds)
Usage Instructions:
In a Text+ Node:
Create a Text+ node in the Fusion page.
In the text field, enter the expression above.
Ensure that you start the expression with an = sign if required.
Example Output:
If you're at frame 75 with a frame rate of 30 fps:
Total seconds = 75 / 30 = 2.5 seconds
Minutes = 0
Seconds = 2
Milliseconds = 500
Formatted Time:00:02.500
This expression will dynamically update to display the current time in minutes:seconds.milliseconds format as the playhead moves, giving you a time representation in milliseconds instead of subframes.
Note: This expression uses Lua, which is the scripting language used in Fusion expressions within DaVinci Resolve. Ensure that your expression editor is set to Lua if necessary.
By calculating milliseconds from the current frame and frame rate and formatting the output, you can display the current time in minutes:seconds:milliseconds format instead of using subframes.
**Answer: Use an expression that converts frames to milliseconds and formats time like this: