]> git.sesse.net Git - mlt/blob - docs/westley.txt
5625c5d4e7fd8c3d2c075d973ffff13e1bc72764
[mlt] / docs / westley.txt
1 WESTLEY
2 -------
3
4 Preamble:
5
6         Westley is the MLT projects XML serialisation/deserialisation format -
7         as such, it closely mirrors the internal structure of the MLT API.
8
9         If you just want to go straight to the DTD, then see 
10         mlt/src/modules/westley.dtd, which gets installed at 
11         $(prefix)/share/mlt/modules/westley.dtd. Currently, the westley parser is
12         non-validating.
13
14
15 Introduction:
16
17         A westley document is essentially a list of 'producers' - a producer is
18         an mlt object which generates mlt frames (images and associated audio
19         samples). 
20         
21         There are 3 types of producer:
22         
23         * Basic Producers - these are typically file or device oriented feeds; 
24         * Playlists - these are arrangements of multiple producers;
25         * Multitracks - these are the fx encapsulators.
26
27         In the mlt model, producers are created and attached to 'consumers' -
28         consumers are software playback components (such as SDL), or wrappers for
29         hardware drivers (such as bluefish) or even the westley serialising
30         consumer itself (the latter doesn't receive frames - it merely
31         interrogates the connected producer for its configuration).
32
33         Although westley was defined as a serialisation mechanism for instantiated 
34         MLT components, this document will concentrate on the hand authoring of 
35         westley documents.
36
37
38 Rules:
39
40         As shall become apparent through the remainder of this document, the basic
41         tenet of westley authoring is to organise the document in the following
42         manner:
43
44         1) create producer elements for each unique media clip in the project;
45         2) create playlists for each track;
46         3) create a multitrack and specify filters and transitions;
47         4) adding global filters.
48
49         While other uses of westley exist, the approach taken here is to maximise
50         efficiency for complex projects. 
51
52
53 Basic Producers:
54
55         The simplest westley document is:
56
57         <westley>
58           <producer id="producer0">
59             <property name="resource">clip1.dv</property>
60           </producer>
61         </westley>
62
63         The westley wrapping is of course superfluous here - loading this document
64         with MLT is identical to loading the clip directly. 
65
66         Of course, you can specify additional properties. For example, consider an
67         MPEG file with multiple soundtracks - you could define a westley document to
68         ensure that the second audio track is loaded:
69
70         <westley>
71           <producer id="producer0">
72             <property name="resource">clip1.mpeg</property>
73             <property name="audio_track">1</property>
74           </producer>
75         </westley>
76
77         NB: This relies on the mpeg being handled by the avformat producer, rather
78         than the mcmpeg one. See services.txt for more details.
79
80         A more useful example comes with the pango producer for a text producer.
81
82         TODO: pango example...
83
84         Notes:
85
86         1) It is better not to specify in/out points when defining basic producers
87         as these can be specified in the playlists. The reasoning is that in/out
88         restricts the amount of the clip available, and could lead to the same clip
89         being loaded multiple times if you need different regions of the clip
90         elsewhere;
91         2) A westley can be specified as a resource, so westleys can naturally
92         encapsulate other westleys.
93
94
95 Playlists:
96
97         Playlists provide a 'collection' structure for producers. These can be used
98         to define 'tracks' in the multitrack approach, or simple playlists for
99         sequential, single track playout.
100
101         As an example, the following defines two basic producers and a playlist with 3
102         items:
103
104         <westley>
105           <producer id="producer0">
106             <property name="resource">clip1.dv</property>
107           </producer>
108           <producer id="producer1">
109             <property name="resource">clip2.dv</property>
110           </producer>
111           <playlist id="playlist0">
112             <entry producer="producer0" in="0" out="2999"/>
113             <entry producer="producer1" in="0" out="999"/>
114             <entry producer="producer0" in="3000" out="6999"/>
115           </playlist>
116         </westley>
117
118         Here we see how the playlist defines the in/out points of the basic
119         producers.
120
121         Notes:
122
123         1) All in/out points are absolute frame positions relative to the producer
124         being appended to the playlist;
125         2) Westley documents are currently authored for a specific normalisation;
126         3) The last 'producer' in the document is the default for play out;
127         4) Playlists can reference the same producer multiple times. In/out regions
128         do not need to be contiguous - duplication and skipping is acceptable.
129
130
131 Interlude - Introducing Multitracks:
132
133         So far we've defined basic producers and playlists/tracks - the tractor is
134         the element that allows us to arrange our tracks and specify filters and
135         transitions. Similarly to a playlist, a tractor is a container.
136
137         Note that MLT doesn't see a filter or a transition as a producer in the
138         normal sense - filters and transitions are passive when it comes to seeking.
139         Internally, seeks are carried out on the producers. This is an important
140         point - MLT does not follow a traditional graph oriented model.
141
142         Visualising an MLT tractor and it's interaction with the consumer will
143         assist here:
144
145         +----------------------------------------------+
146         |tractor                                       |
147         | +----------+    +-+    +-+    +-+    +-+     |
148         | |multitrack|    |f|    |f|    |t|    |t|     |
149         | | +------+ |    |i|    |i|    |r|    |r|     |
150         | | |track0|-|--->|l|- ->|l|- ->|a|--->|a|\    |
151         | | +------+ |    |t|    |t|    |n|    |n| \   |
152         | |          |    |e|    |e|    |s|    |s|  \  |
153         | | +------+ |    |r|    |r|    |i|    |i|   \ |    +--------+
154         | | |track1|-|- ->|0|--->|1|--->|t|--->|t|-----|--->|consumer|
155         | | +------+ |    | |    | |    |i|    |i|   / |    +--------+
156         | |          |    | |    | |    |o|    |o|  /  |         ^
157         | | +------+ |    | |    | |    |n|    |n| /   |         |
158         | | |track2|-|- ->| |- ->| |--->|0|- ->|1|/    |         |
159         | | +------+ |    | |    | |    | |    | |     |         |
160         | +----------+    +-+    +-+    +-+    +-+     |         |
161         +----------------------------------------------+         |
162                ^                                                 |
163                |                                                 |
164         +-----------+                                            |
165         |APPLICATION|--------------------------------------------+
166         +-----------+
167
168         Internally, all frames from all tracks pass through all the filters and
169         transitions - these are told which tracks to deal and which regions of the
170         tracks to work on. 
171
172         Note that the application communicates with the producer - it can alter
173         playback speed, position, or even which producer is connected to which
174         consumer. 
175         
176         The consumer receives the first non-blank frame (see below). It has no say
177         in the order in which gets them (the sdl consumer when used with inigo might 
178         appear to be an exception - it isn't - it simply has a route back to the 
179         application to allow the application to interpret key presses).
180
181         Whether this is better or worse than a traditional graph approach is a moot
182         point. The author of this document likes it anyway :-).
183
184
185 Tractors:
186
187         To create a multitrack westley, we can use two playlists and introduce a
188         tractor. For the purposes of demonstration, I'll add a filter here too:
189
190         <westley>
191           <producer id="producer0">
192             <property name="resource">clip1.dv</property>
193           </producer>
194           <producer id="producer1">
195             <property name="resource">clip2.dv</property>
196           </producer>
197           <playlist id="playlist0">
198             <entry producer="producer0" in="0" out="2999"/>
199             <blank length="1000"/>
200             <entry producer="producer0" in="3000" out="6999"/>
201           <playlist id="playlist1">
202             <blank length="3000"/>
203             <entry producer="producer1" in="0" out="999"/>
204           </playlist>
205           <tractor id="tractor0">
206             <multitrack>
207               <track producer="playlist0"/>
208               <track producer="playlist1"/>
209             </multitrack>
210             <filter>
211               <property name="track">0</property>
212               <property name="mlt_service">greyscale</property>
213             </filter>
214           </tractor>
215         </westley>
216         
217         Here we see that blank frames are inserted into the first playlist and a
218         blank is provided at the beginning of the second - this can be visualised in
219         the traditional timeline widget as follows:
220
221         +-------+   +-------------+
222         |a      |   |a            |
223         +-------+---+-------------+
224                 |b  |
225                 +---+
226         
227         Adding the filter on the top track, gives us:
228
229         +-------+   +-------------+
230         |a      |   |a            |
231         +-------+---+-------------+
232         |greyscale                |
233         --------+---+-------------+
234                 |b  |
235                 +---+
236         
237         Note that it's only applied to the visible parts of the top track.
238
239         The requirement to apply a filter to the output, as opposed to a specific 
240         track leads us to the final item in the Rules section above. As an example, 
241         let's assume we wish to watermark all output, then we could use the 
242         following:
243
244         <westley>
245           <producer id="producer0">
246             <property name="resource">clip1.dv</property>
247           </producer>
248           <producer id="producer1">
249             <property name="resource">clip2.dv</property>
250           </producer>
251           <playlist id="playlist0">
252             <entry producer="producer0" in="0" out="2999"/>
253             <blank length="1000"/>
254             <entry producer="producer0" in="3000" out="6999"/>
255           <playlist id="playlist1">
256             <blank length="3000"/>
257             <entry producer="producer1" in="0" out="999"/>
258           </playlist>
259           <tractor id="tractor0">
260             <multitrack>
261               <track producer="playlist0"/>
262               <track producer="playlist1"/>
263             </multitrack>
264             <filter>
265               <property name="track">0</property>
266               <property name="mlt_service">greyscale</property>
267             </filter>
268           </tractor>
269           <tractor id="tractor1">
270             <multitrack>
271               <track producer="tractor0"/>
272             </multitrack>
273             <filter>
274               <property name="mlt_service">watermark</property>
275               <property name="resource">watermark1.png</property>
276             </filter>
277           </tractor>
278         </westley>
279         
280         Here we employ another tractor and we define a single track (being the
281         tractor we previously defined) and apply a watermarking filter there.
282
283         This is simply provided as an example - the watermarking functionality could
284         be better handled at the playout stage itself (ie: as a filter automatically
285         placed between all producers and the consumer).
286
287         Tracks act like "layers" in an image processing program like the GIMP. The 
288         bottom-most track takes highest priority and higher layers are overlays 
289         and do not appear unless there are gaps in the lower layers or unless
290         a transition is applied that merges the tracks on the specifed region.
291         Practically speaking, for A/B video editing it does not mean too much, 
292         and it will work as expected; however, as a general rule apply any CGI
293         (graphic overlays with pixbuf or titles with pango) on tracks higher than
294         your video tracks. Also, this means that any audio-only tracks that are
295         lower than your video tracks will play rather than the audio from the video
296         clip. Remember, nothing is affected like mixing or compositing until one
297         applies a transition or appropriate filter.
298         
299         <westley>
300           <producer id="producer0">
301                 <property name="resource">clip1.dv</property>
302           </producer>
303           <playlist id="playlist0">
304                 <entry producer="producer0"/>
305           </playlist>
306           <producer id="producer1">
307                 <property name="resource">clip2.mpeg</property>
308           </producer>
309           <playlist id="playlist1">
310                 <blank length="50"/>
311                 <entry producer="producer1"/>
312           </playlist>
313           <tractor id="tractor0" in="0" out="315">
314                 <multitrack id="multitrack0">
315                   <track producer="playlist0"/>
316                   <track producer="playlist1"/>
317                 </multitrack>
318                 <transition id="transition0" in="50" out="74">
319                   <property name="a_track">0</property>
320                   <property name="b_track">1</property>
321                   <property name="mlt_service">luma</property>
322                 </transition>
323                 <transition id="transition1" in="50" out="74">
324                   <property name="a_track">0</property>
325                   <property name="b_track">1</property>
326                   <property name="mlt_service">mix</property>
327                   <property name="start">0.0</property>
328                   <property name="end">1.0</property>
329                 </transition>
330           </tractor>
331         </westley>
332
333         A "luma" transition is a video wipe processor that takes a greyscale bitmap
334         for the wipe definition. When one does not specify a bitmap, luma performs
335         a dissolve. The "mix" transition does an audio mix, but it interpolates
336         between the gain scaling factors between the start and end properties - 
337         in this example, from 0.0 (none of track B) to 1.0 (all of track B). 
338         Because the bottom track starts out with a gap specified using the <blank>
339         element, the upper track appears during the blank segment. See the demos and
340         services.txt to get an idea of the capabilities of the included transitions.
341
342 Flexibility:
343
344         The information presented above is considered the MLT Westley "normal"
345         form. This is the output generated by the westley consumer, for example,
346         when used with inigo. It is the output generated when you use the
347         "Westley to File" consumer in the demo script, which beginners will find
348         most useful for learning to use westley XML. This section describes 
349         alternative forms the westley producer accepts.
350
351         First of all, the normal form is more of a linear format with producers
352         and playlists defined prior to their usage in a multitrack. Westley
353         also accepts a hierarchical format with producers as children of tracks
354         or playlist entries and with playlists as children of tracks:
355
356         <westley>
357           <tractor>
358             <multitrack>
359               <track>
360                 <playlist>
361                   <entry>
362                     <producer>
363                       <property name="resource">clip1.dv</property>
364                     </producer>
365                   </entry>
366                 </playlist>
367               </track>
368             </multitrack>
369           </tractor>
370         </westley>
371
372         Obviously, this example is meant to demonstrate hierarchy and not effective
373         use of playlist or multitrack!
374
375         Secondly, as part of error handling, westley is forgiving if you fail to
376         supply <tractor>, <track>, and <entry> where one can be understood. This
377         affords an abbreviated syntax that is less verbose and perhaps less 
378         intimidating for a human to read and understand. One can simplify the
379         above example as:
380
381         <westley>
382           <multitrack>
383             <playlist>
384               <producer>
385                 <property name="resource">clip1.dv</property>
386               </producer>
387             </playlist>
388           </multitrack>
389         </westley>
390
391         Yes, filters and transitions can be added to the above example after the
392         closing multitrack tag (</multitrack>) because it is still enclosed within
393         the westley body tags.
394
395         If you specify in and out on a producer and it has been enclosed within
396         an <entry> or <playlist>, then the edit points apply to the playlist
397         entry and not to the producer itself. This facilitates re-use of media:
398
399         <playlist>
400           <producer id="clip1" in="25" out="78">
401             <property name="resource">clip1.dv</property>
402           </producer>
403           <entry producer="clip1" in="119" out="347"/>
404         </playlist>
405
406         In the above example, the producer attribute of the entry element is 
407         a reference to the preceding producer. All references must follow the 
408         definition. The edit points supplied on the producer above will not affect
409         the entry that references it below because westley knows the clip is a 
410         playlist entry and optimises this situation. The advantage is that one
411         does not need to determine every clip to be included ahead of time 
412         and specify them outside the context of the mutlitrack timeline.
413
414         This form of authoring will be easier for many to visualise as a non-linear 
415         editor's timeline. Here is a more complex example:
416
417         <westley>
418           <multitrack>
419             <playlist>
420               <producer id="foo" in="100" out="149">
421                 <property name="resource">clip2.mpeg</property>
422               </producer>
423               <blank length="25"/>
424               <entry producer="foo" in="10" out="59"/>
425             </playlist>
426             <playlist>
427               <blank length="25"/>
428               <producer id="bar" in="100" out="199">
429                 <property name="resource">clip3.mpeg</property>
430               </producer>
431               <entry out="99" producer="bar"/>
432             </playlist>
433           </multitrack>
434           <filter mlt_service="greyscale" track="0"/>
435           <transition mlt_service="luma" in="25" out="49" a_track="0" b_track="1"/>
436           <transition mlt_service="luma" in="75" out="99" a_track="0" b_track="1">
437             <property name="reverse" value="1"/>
438           </transition>
439         </westley>
440
441         Did you notice something different in the last example? Properties can be 
442         expressed using XML attributes on the element as well. However, only 
443         non-service-specific properties are supported in this way. For example,
444         "mlt_service" is available to any producer, filter, or transition. However,
445         "resource" is actually service-specific. Notice the syntax of the last 
446         property, on the last transition. Westley accepts property values using 
447         the "value" attribute as well as using element text.
448
449         We have seen a few different ways of expressing property values. There are
450         a couple more for properties that can accept XML data. For example, the
451         GDK pixbuf producer with librsvg can handle embedded SVG, and the Pango
452         producer can handle embedded Pango markup. You can enclose the embedded XML
453         using a CDATA section:
454
455         <property name="resource"><![CDATA[ <svg>...</svg> ]]></property>
456
457         Please ensure the opening CDATA tag immediately follows the opening
458         property tag and that the section closing tag immediately precedes the
459         closing property tag.
460
461         However, westley can also accept inline embedded XML:
462
463         <property name="resource">
464           <svg>
465           </svg>
466         </property>
467
468         Currently, there is no namespace handling so a conflict will occur only on 
469         any embedded XML that contains an element named "property" because 
470         westley collects embedded XML until it reaches a closing property tag.
471         
472         
473 Entities and Parameterisation:
474         
475         The westley producer parser supports XML entities. An example:
476         
477         <?xml version="1.0"?>
478         <!DOCTYPE westley [
479                 <!ENTITY msg "Hello world!">
480         ]>
481         <westley>
482           <producer id="producer0">
483                 <property name="mlt_service">pango</property>
484                 <property name="text">&msg;</property>
485           </producer>
486         </westley>
487         
488         If you are embedding another XML document into a property value not using
489         a CNODE section, then any DOCTYPE section must be relocated before any of
490         the xml elements to be well-formed. See demo/dvg.westley for an example.
491         
492         Entities can be used to parameterise westley! Using the above example, the
493         entity declared serves as the default value for &msg;. The entity content
494         can be overridden from the resource property supplied to the westley
495         producer. The syntax is the familiar, url-encoded query string used with
496         HTTP, e.g.: file?name=value&name=value...
497         
498         There are a couple of rules of usage. The Miracle LOAD command and inigo
499         command line tool require you to preface the URL with "westley:" because
500         the query string destroys the filename extension matching peformed by
501         Fezzik. Also, inigo looks for '=' to tokenise property settings. Therefore, 
502         one uses ':' between name and value instead of '='. Finally, since inigo
503         is run from the shell, one must enclose the URL within single quotes to 
504         prevent shell filename expansion, or similar.
505         
506         Needless to say, the ability to parameterise westley XML compositions is
507         an extremely powerful tool. An example for you to play with is available in 
508         demo/entity.westley. Try overriding the name from inigo:
509         inigo 'westley:entity.westley?name:Charlie'
510         
511         Technically, the entity declaration is not needed in the head of the XML
512         document if you always supply the parameter. However, you run the risk
513         of unpredictable behviour without one. Therefore, it is safest and a best
514         practice to always supply an entity declaration. It is improves the 
515         readability as one does not need to search for the entity references to 
516         see what parameters are available.
517         
518
519 Tips and Technique:
520
521         If one finds the above hierarchical, abbreviated format intuitive,
522         start with a simple template and fill and extend as needed:
523                 <westley>
524                   <multitrack>
525                     <playlist>
526                     </playlist>
527                     ...add a playlist for each track...
528                   </multitrack>
529                   ...add filters and transitions...
530                 </westley>
531                 
532         By using a playlist for each track, it is easier to iteratively add new 
533         clips and blank regions as you develop the project.     You will not have to
534         use <track> or later add <playlist> when necessary.
535         
536         A more advanced template that allows sequencing multitracks is:
537                 <playlist>
538                   <entry>
539                     <multitrack>
540                       <playlist>
541                       </playlist>
542                       ...add a playlist for each track...
543                     </multitrack>
544                     ...add filters and transitions...
545                   </entry>
546                   
547                   <entry>
548                     <multitrack>
549                       <playlist>
550                       </playlist>
551                       ...add a playlist for each track...
552                     </multitrack>
553                     ...add filters and transitions...
554                   </entry>
555                 </playlist>
556
557         If you end up making a collection of templates for various situations, then
558         consider using XML Entities to make the template more effective by moving
559         anything that should parameterised into an entity.
560
561         If you want to have a silent, black background for audio and video fades,
562         then make the top track simply <producer mlt_service="colour"/>. Then,
563         use composite and volume effects. See the "Fade from/to black/silence"
564         demo for an example (demo/mlt_fade_black).
565         
566         If you apply the reverse=1 property to a transition like "luma," then
567         be careful because it also inherently swaps the roles of A and B tracks.
568         Therefore, you need to might need to swap the a_track and b_track values
569         if it did not turn out the way you expected. See the "Clock in and out"
570         for an example (demo/mlt_clock_in_and_out).