Warning, /multimedia/kdenlive/dev-docs/fileformat.md is written in an unsupported language. File is not indexed.

0001 <!--
0002     SPDX-FileCopyrightText: 2021-2022 Julius Künzel <jk.kdedev@smartlab.uber.space>
0003     SPDX-FileCopyrightText: 2015-2023 Jean-Baptiste Mardelle <jb@kdenlive.org>
0004     SPDX-License-Identifier: CC0-1.0
0005 -->
0006 
0007 # Kdenlive File Format
0008 
0009 Kdenlive's project files (`.kdenlive` files) use an XML format, based on MLT's format (see [MLT’s XML documentation][mlt-xml-doc] and [MLT’s DTD/document type definition][mlt-xml-dtd]) to describe the source media used in a project, as well as the use of that media as in the timeline.
0010 
0011 For most media, such as video, audio, and images, Kdenlive stores only a reference in a project, but not the media itself. Only some media gets stored directly inside Kdenlive’s project files, most notably Kdenlive title and color clips.
0012 
0013 Important aspects of this file format decision are:
0014 
0015 * **MLT is able to directly render Kdenlive project files.** MLT simply ignores all the additional Kdenlive-specific project data and just sticks to its rendering information. The Kdenlive-specific data is the additional icing on top that makes working with projects much easier than editing at the (lower) rendering level.
0016 * **Kdenlive can directly include and work with MLT rendering files,** just the same way it works with other media. In fact, Kdenlive’s library clips are simply MLT rendering files, and nothing more.
0017 
0018 ## History and Generations
0019 
0020 There are different file format generations depending on the version of Kdenlive you're using.
0021 
0022 ### Generation 1
0023 
0024 Generation 1 (gen-1) projects were created and edited the last time using Kdenlive up to 0.9.10. These are the Kdenlive versions developed for KDE 4.x. (While this isn’t strictly true, we won’t go into discussions about the early KDE 3.x versions of Kdenlive.)
0025 
0026 The gen-1 projects contain a lot of project data that needs to be duplicated into the outer MLT XML data in order to MLT understanding what it needs to do. As an unfortunate consequence of this data duplicity, gen-1 projects had the habit of getting the outer MLT data out of sync with the inner Kdenlive project data. For instance, sometimes the effects as rendered got out of sync with the effect parameters as set in the Kdenlive user interface. As the proper remedy for this situation, the Kdenlive developers switched to Generation 2 as part of their porting Kdenlive to the KDE Frameworks 5 (KF5).
0027 
0028 ### Generation 2: KF5
0029 
0030 *Used in Kdenlive versions 15.04 to 17.08*
0031 
0032 With the KF5/Qt5 version of Kdenlive, we now store all Kdenlive data through MLT's xml module to remove the data duplicity from the Kdenlive project file structure. This fixed project data model results in much more stable Kdenlive project behavior. As another positive side effect, it’s now much easier to manually edit or create Kdenlive XML project files from outside Kdenlive.
0033 
0034 #### Slightly Invalid XML?
0035 
0036 When you need to process Kdenlive project files using XML tools, there’s a gotcha to be aware in case of gen-2 project files. As soon as a project makes use of track-wide effects, the project XML as written by Kdenlive becomes invalid. You won’t notice this when editing Kdenlive project files just inside Kdenlive, and render them using MLT. You will only notice when editing them using standard XML tools.
0037 
0038 The reason is that gen-2 project files used their own attributes inside a separate “kdenlive” namespace. Unfortunately, Kdenlive forgets to declare this additional namespace it uses at the beginning of every XML project document. As a simple fix, you’ll need to add the missing namespace yourself before processing the Kdenlive project file with XML tools:
0039 
0040 ```xml
0041 <?xml version='1.0' encoding='utf-8'?>
0042 <mlt xmlns:kdenlive="http://www.kdenlive.org/project" ...>
0043   ...
0044 </mlt>
0045 ```
0046 
0047 ### Generation 3: Timeline 2
0048 
0049 *Used in Kdenlive versions 19.04.0 to 20.04.3*
0050 
0051 Generation 3 projects are those projects created or edited using Kdenlive versions with the new Timeline 2 engine.
0052 
0053 ### Generation 4: Comma / Point
0054 
0055 *Used in Kdenlive versions 20.08.0 to 22.12.3, Kdenlive document version: 1.00*
0056 
0057 With version 20.08.0 a major refactoring of the project file fixed a long standing [issue with the decimal separator][comma-point-issue] (comma/point) conflict causing many crashes. Projects created with 20.08 forward are not backwards compatible.
0058 
0059 some minor updates were done to support new features, like:
0060 
0061 * 20.12.0: Mixes (in-track-transitions) were introduced
0062 
0063 ### Generation 5: Current format
0064 
0065 *Used in Kdenlive versions from 23.04.0, Kdenlive document version: 1.1*
0066 
0067 An important change was introduced with Kdenlive 23.04.0: multiple sequences. Each timeline sequence clip is embedded in an MLT *tractor*.
0068 The "main_bin" playlist lists all clips and timeline sequences used in the project as *entries*.
0069 
0070 The very last *tractor* in the project file is just a wrapper for the last opened timeline sequence, so that when playing the project file through the *melt* command line, it will play the last active sequence clip.
0071 
0072 Previously, all timeline properties were stored in the "main_bin" playlist as *kdenlive:documentproperty.*. With the new format, all timeline properties are stored inside their timeline sequence as *kdenlive:sequenceproperty.*, and only global project settings are stored in the "main_bin".
0073 
0074 ## Project XML Structure
0075 
0076 The overall structure of the XML data inside Kdenlive project files is roughly as illustrated next:
0077 
0078 ```xml
0079 <mlt producer="main_bin" ...>
0080 
0081   <!-- the profile - definition of the project profile (frame size, aspect ration, etc) -->
0082   <profile frame_rate_num="25" .../>
0083 
0084   <!-- definition of master and timeline clips used in the first sequence clips -->
0085   <producer id="producer0" .../>
0086   <producer id="producer1" .../>
0087 
0088   <!-- then comes the playlist definition - a list of the empty spaces and clips on a track -->
0089   <playlist id="playlist0">
0090     <!-- entries linking to the producers defined above -->
0091     <entry producer="producer0" in="00:00:00.000" out="00:00:04.960">
0092       <property name="kdenlive:id">3</property>
0093     </entry>
0094     <blank length="00:00:03.720"/> <!-- space between clips -->
0095     <entry producer="producer1" />
0096     ...
0097   <playlist id="playlist1"/>
0098 
0099   <!-- After that we have the tracks embedded in a tractor. Each Kdenlive timeline track is made of 2 *tracks* to allow mixes-->
0100   <tractor id="tractor0" in="00:00:00.000" out="00:02:20.840">
0101     <property name="kdenlive:..">...</property>
0102     ...
0103     <track hide="audio" producer="playlist0"/> <!-- hide audio, because this is a video track -->
0104     <track hide="audio" producer="playlist1"/>
0105   </tractor>
0106 
0107   <!-- After the tracks definition, we have the first timeline sequence tractor that has a kdenlive:uuid attribute, and transitions between the tracks -->
0108   <tractor id="tractor6" ...>
0109     <property name="kdenlive:uuid">...</property>
0110     <track hide="audio" producer="tractor0"/>
0111     <track hide="audio" producer="tractor1"/>
0112 
0113     <!-- all transitions -->
0114     <transition id="transition0"/> <!-- user transitions -->
0115     <transition id="transition1"> <!-- internally added transition (for example audio mix) -->
0116       <property name="internal_added">237</property>
0117     </transition>
0118 
0119     </tractor>
0120 
0121   <!-- If we have multiple timeline sequence clips, we repeat the above steps -->
0122   <producer id="producer3" .../>
0123   <playlist id="playlist3" ../>
0124   <tractor id="tractor7" .../>
0125   <tractor id="tractor11" ...>
0126     <property name="kdenlive:uuid">...</property>
0127     <track hide="audio" producer="tractor7"/>
0128     <track hide="audio" producer="tractor8"/>
0129   </tractor>
0130 
0131   <!-- The *main bin* playlist, keeping all project settings, and a list of all project bin clips, including the sequence clips  -->
0132   <playlist id="main_bin">
0133     <property name="kdenlive:documentproperty...">...</property>
0134     <entry producer="producer0" .../>
0135     <entry producer="producer1" .../>
0136     <entry producer="tractor6" .../>
0137     <entry producer="tractor11" .../>
0138   </playlist>
0139 
0140   <!-- the last tractor of the xml file only contains one producerm is a the main tractor, containing the default sequence clip that will be played -->
0141   <tractor id="tractor23" in="00:00:00.000" out="00:00:45.000">
0142     <property name="kdenlive:projectTractor">1</property>
0143     <track producer="tractor11" in="00:00:00.000" out="00:00:45.000"/>
0144  </tractor>
0145 
0146 </mlt>
0147 ```
0148 
0149 We avoid storing any inner Kdenlive project data that’s already present in the outer MLT data layer, this means that all information must be stored in MLT objects like Tractor, Playlist, Producer, etc.
0150 
0151 To separate these properties from other MLT properties, we prefix them with `kdenlive:`. This page lists the properties that we use in this new file format.
0152 
0153 Properties applied to project clips (MLT Producer object):
0154 
0155 | Name                 | Description |
0156 | -------------------- | ----------- |
0157 | kdenlive:clipname    | Stores the name that will be displayed for this clip in the Project Bin. |
0158 | kdenlive:folderid    | Stores a string containing the id of the folder where this clip is (empty if clip is in the root folder). |
0159 | kdenlive:zone_in     | Stores the "in" point for the play zone defined for this clip. |
0160 | kdenlive:zone_out    | Stores the "out" point for the play zone defined for this clip. |
0161 | kdenlive:originalurl | Stores the clip's original url. Useful to retrieve original url when a clip was proxied. |
0162 | kdenlive:proxy       | Stores the url for the proxy clip, or "-" if no proxy should be used for this clip. |
0163 | kdenlive:clip_type   |  |
0164 | kdenlive:id          |  |
0165 | kdenlive:file_size   |  |
0166 | kdenlive:file_hash   |  |
0167 | kdenlive:audio_max1  |  |
0168 
0169 
0170 ### Project Bin
0171 
0172 The (project) bin is represented by an MLT `<playlist>` element with the well-known id “main_bin”. This element holds project-specific (meta) data, the bin folders as well as their hierarchy, clip groups, and some more stuff.
0173 
0174 > **Note**
0175 >
0176 > While Kdenlive now mainly uses the term “bin” when talking about what formerly was the “project bin”, the early internal name “name bin” has stuck since the early days of Kdenlive.
0177 
0178 Properties applied to the Bin Playlist (MLT Playlist object "main_bin"):
0179 
0180 | Name                     | Description |
0181 | ------------------------ | ----------- |
0182 | kdenlive:folder.xxx.yyy  | This property stores the names of folders created in the Project Bin. xxx is the id of the parent folder (-1 for root) and yyy is the id for this folder. The value of this property is the name of the folder. |
0183 | kdenlive:docproperties.* | There are various properties with this prefix holding settings related to the current project, like proxy size |
0184 | kdenlive:documentnotes   |  |
0185 | kdenlive:docproperties.groups | This property holds a json structure representing the clip groups of the timeline |
0186 
0187 
0188 ### Timeline Tracks
0189 
0190 The setup of the timeline tracks is represented by an MLT `<tractor>` element, this “maintractor“ can be identified by being the last `<tractor>` in the file. The elements inside are the individual timeline tracks: these are referenced, with the actual tracks then being MLT producers.
0191 
0192 The individual Kdenlive timeline tracks can be found in form of MLT `<tractor>` elements holding `<playlist>` elements. They can also easily be identified according to their “tractor#”/“playlist#” id naming scheme; here, “#” is a number internally maintained by Kdenlive. The tracks feature additional properties that describe their title, locking state, and some more. The reason for the extra level with `<playlist>` elements are mixes (see below).
0193 
0194 There is one semi-internal track here, the built-in “black_track”. As you can see here, while it is built into Kdenlive, it isn’t so into MLT. Instead, to MLT this is just another track that happen to be created by Kdenlive. Kdenlive never shows this background track in the timeline as an individual track. But you can reference it from transitions (the composite ones, that is).
0195 
0196 ### Subtitle Track
0197 
0198 While for the user it feels like this subtitle track is a track like an audio or video track, in fact it is not. It is a "fake" track and internally a filter, the [`avfilter.subtitles`][subtitle-mlt-doc] filter to be more precise (see also [this ffmpeg doc][subtile-ffmpeg-doc]). If an internal `avfilter.subtitles` is detected, the subtitle track gets enabled.
0199 
0200 The subtitles are stored in a `*.srt` file next to the project. If your project is named `mymovie.kdenlive`, the subtitle file will be `mymovie.kdenlive.srt`. This file will only be update if you save your project, but the internal subtitle model is not sufficient during work since `avfilter.subtitles` needs a `*.srt` file to always show the up-to-date state of work in the monitor. Therefore there is another `*.srt` file in the temp directory (`/tmp` on Linux).
0201 
0202 This is how the subtitle trakc is represented in the kdenlive xml:
0203 
0204 ```xml
0205   <filter id="filter9">
0206    <property name="mlt_service">avfilter.subtitles</property>
0207    <property name="internal_added">237</property>
0208    <property name="av.filename">/tmp/1654509160006.srt</property>
0209    <property name="kdenlive:locked">1</property>
0210   </filter>
0211 ```
0212 
0213 ### Transitions (Compositions)
0214 
0215 Transitions come in two (three) flavors, but always represented by MLT `<transition>` elements:
0216 
0217 * user transitions are the ones added by, you’ve guessed it … users. These are the transitions currently shown slightly moved down and overlaying timeline tracks and their clips.
0218 * internally added transitions are basically a convenience to make the timeline do automatic audio mixing across multiple tracks, and (with more recent Kdenlive versions) transparent tracks.
0219 
0220 ### Same-Track-Transitions (Mixes)
0221 
0222 TODO
0223 
0224 ### Filters (Effect)
0225 
0226 TODO
0227 
0228 
0229 ### Not Shown
0230 
0231 * bin clip producers
0232 * proxy clips
0233 
0234 ## Further Reading
0235 
0236 * The [Kdenlive Project Analyzer][project-analyizer-blog] is kind of a (crazy) simple Kdenlive doctor, showing some statistics and details when given a Kdenlive gen-2 project file. You can even try the Kdenlive Project Analyzer [online][project-analyizer-tool] using Chrome/Chromium or Firefox. [Sources are available on GitHub.][project-analyizer-code]
0237 
0238 [mlt-xml-doc]: https://www.mltframework.org/docs/mltxml/
0239 [mlt-xml-dtd]: https://github.com/mltframework/mlt/blob/master/src/modules/xml/mlt-xml.dtd
0240 [subtitle-mlt-doc]: https://www.mltframework.org/plugins/FilterAvfilter-subtitles/
0241 [subtile-ffmpeg-doc]: https://ffmpeg.org/ffmpeg-filters.html#subtitles-1
0242 [comma-point-issue]: https://invent.kde.org/multimedia/kdenlive/-/issues/78
0243 [project-analyizer-blog]: https://thediveo-e.blogspot.de/2016/07/inside-kdenlive-projects-analyzer.html
0244 [project-analyizer-tool]: https://thediveo.github.io/kdenlive-project-analyzer/kdenlive-project-analyzer.html
0245 [project-analyizer-code]: https://github.com/TheDiveO/kdenlive-project-analyzer
0246 
0247