How to calculate millisecond offset of the next frame?

Suppose an MLT XML file has a playlist like this:

<playlist id="playlist0">
  <entry producer="producer0" in="00:00:00.000" out="00:00:03.971"/>
  <entry producer="producer1" in="00:00:01.001" out="00:00:03.003"/>

I’ve gathered that I need to keep track of a “virtual playhead” if I want to know the absolute start time of a producer (as in, offset in milliseconds from the beginning of the timeline). For instance, given a project using 30000/1001 drop frame, each frame is 33.3666 milliseconds, which if added to the “out” position of producer0, puts the start of producer1 at 00:00:04.004.

My concern is that I’ll suffer time drift if I add 33 milliseconds to advance the playhead to each next clip over the course of an hour because the fractional 0.3666 milliseconds won’t be represented.

So my question is how to “officially” advance the virtual playhead through a playlist in a drop frame project to get the absolute in/out of each clip, and predict the “in” point of a next clip if one were added. The calculations for this are probably in the Shotcut source code already, and a pointer to them is all I would need. The goal is processing an MLT file with an external tool to synchronize other streams in a container to a Shotcut video. Thanks.

Basically, you convert the time to a integer number of frames, add or subtract frames, and convert the frame count to a time value. The code is in MLT :


You can also just put bare frame counts in wherever you see time. Shotcut uses time values to make it more flexible when changing fps.

1 Like

Those code snippets will work perfectly. Thanks a million, and bonus thanks for insanely fast response time!

This topic was automatically closed after 90 days. New replies are no longer allowed.