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