2016-07-30

Inside Kdenlive Projects: Internally Added Transitions

In order to provide a smooth user experience when working with tracks, Kdenlive has to perform some behind-the-scene tricks to make its MLT engine work as expected. This is where the so-called internally added transitions come in...


Internally added transitions are automatically created and maintained by Kdenlive itself. There are two types of them:
  • for automatic audio mixing across all audio and video tracks,
  • for transparent tracks using automatic compositing across video tracks.

Internally Added Transitions


Due to the way MLT works, transitions are not attached to clips or tracks as one may expect, but instead they are specified inside a <tractor>. In case of Kdenlive projects, transitions will live inside the "maintractor", that is, <tractor id="maintractor">, following the MLT model for the tractor/transition hierarchy. For example:
<mlt>
  <tractor id="maintractor">
    <transition id="transition8">
      <property name="a_track">0</property>
      <property name="b_track">3</property>
      <property name="mlt_service">mix</property>
      <property name="always_active">1</property>
      <property name="combine">1</property>
      <property name="internal_added">237</property>
    </transition>
  </tractor>
</mlt>
All internally added transitions are specially marked: they get an additional <property> with the name "kdenlive:internal_added" and the magic value of "237". This way the internally added transitions are easily differentiated from user-created transitions.

The "mlt_service" property then controls which type of transition is to be used. It thus differentiates between audio mixing and video compositing. More on the details and differences below.

In MLT, transitions merge audio and video frames from an upper "B" track onto a lower "A" track. If you happen to swap A and B so that the B track is lower than the A track, then MLT automatically swaps the A and B track references. We will look into the particular A/B track indices in more detail below.

Finally, these internally added transitions are "always active", in the sense that they cover the complete timeline. This avoids having to specify the in and out points and having to update the out point as soon as the total project length changes.

Audio Mix Transitions




The "combine" property is specific to the audio "mix" transition: Kdenlive always activates this option. This instructs MLT to mix audio using a low-pass filter in order to prevent affecting the audio levels.

For all internally added audio mix transitions, the "A" track is always the bottommost (and hidden) "Black" track (with id="black_track") and thus 0. The "B" track index then is within the range of all tracks in the project. For instance, for a project with timeline five tracks, the B indices range from 1 to 5.

Video Compositing Transitions


Automatic track compositing, also known as transparent tracks, has been introduced with Kdenlive 15.08 (if my memory serves me right). Users can set each video track, except the lowest video track, to either transparent or opaque. With the upcoming 16.08 release, Kdenlive will ditch this per-track model in favor of the much simpler and yet more robust timeline compositing model: a single control instead of per-track settings.

So while the user interface to transparent tracks has changed, the underlying concept of internally added transitions hasn't. However, the actual type of compositing transition has changed between 15.08 and 16.08:
  • Kdenlive 16.08+: the exact transition type depends on the timeline composition mode set in this particular project...
    • preview mode: uses the "composite" transition that favors performance over precision, causing luma bleeding. Due to this tradeoff it's intented for preview only, but not necessarily for final rendering.
    • high quality mode: uses the new "qtblend" transition which performs better than the previous "frei0r.cairoblend" while still keeping quality.
    • none mode simply removes all existing internally added video compositing transitions.
  • Kdenlive 15.08-16.04: uses the "frei0r.cairoblend" transition. It produces a decent quality at the cost of performance.
Internally, the management of these automatic compositing transitions has been received a big improvement: Kdenlive 16.08 now destroys all old transitions and completely rebuilds them whenever the user either changes the timeline compositing mode, or adds or removes timeline tracks.

Before that, the internally added video compositing transitions sometimes started a life of their own, with duplicates or missing family members. My Kdenlive Project Analyzer is a nice tool to shed some light onto the innards of your Kdenlive projects. One of my own Kdenlive projects had a whooping 234 video compositing transitions for just 9 video tracks...!

Please note that the "A" track is always the lowest video track. Audio-only tracks are left out and no internally added compositing transitions are ever created for them.