1 Framework Documentation
3 Copyright (C) 2004 Ushodaya Enterprises Limited
4 Author: Charles Yates <charles.yates@pandora.be>
5 Last Revision: 2004-03-20
13 MLT is a multimedia framework designed for television broadcasting. As such,
14 it provides a pluggable architecture for the inclusion of new audio/video
15 sources, filters, transitions and playback devices.
17 The framework provides the structure and utility functionality on which
18 all of the MLT applications and services are defined.
20 On its own, the framework provides little more than 'abstract classes' and
21 utilities for managing resources, such as memory, properties, dynamic object
22 loading and service instantiation.
24 This document is split roughly into 3 sections. The first section provides a
25 basic overview of MLT, the second section shows how it's used and the final
26 section shows structure and design, with an emphasis on how the system is
32 This document is provided as a 'road map' for the framework and should be
33 considered mandatory reading for anyone wishing to develop code at the MLT
38 1. framework maintainers;
40 3. application developers;
41 4. anyone interested in MLT.
43 The emphasis of the document is in explaining the public interfaces, as
44 opposed to the implementation details.
46 It is not required reading for the MLT client/server integration - please
47 refer to valerie.txt and dvcp.txt for more details on this area.
50 SECTION 1 - BASIC OVERVIEW
51 --------------------------
53 Basic Design Information:
57 The framework has no dependencies other than the standard C99 and POSIX
60 It follows a basic Object Oriented design paradigm, and as such, much of the
61 design is loosely based on the Producer/Consumer design pattern.
63 It employs Reverse Polish Notation for the application of audio and video FX.
65 The framework is designed to be colour space neutral - the currently
66 implemented modules, however, are very much 8bit YUV422 oriented. In theory,
67 the modules could be entirely replaced.
69 A vague understanding of these terms is assumed throughout the remainder of
75 The general structure of an MLT 'network' is simply the connection of a
76 'producer' to a 'consumer':
79 |Producer|-->|Consumer|
82 A typical consumer requests MLT Frame objects from the producer, does
83 something with them and when finished with a frame, closes it.
85 /\ A common confusion with the producer/consumer terminology used here is
86 /!!\ that a consumer may 'produce' something. For example, the libdv consumer
87 \!!/ produces DV and the libdv producer seems to consume DV. However, the
88 \/ naming conventions refer only to producers and consumers of MLT Frames.
90 To put it another way - a producer produces MLT Frame objects and a consumer
91 consumes MLT Frame objects.
93 An MLT Frame essentially provides an uncompressed image and its associated
96 Filters may also be placed between the producer and the consumer:
98 +--------+ +------+ +--------+
99 |Producer|-->|Filter|-->|Consumer|
100 +--------+ +------+ +--------+
102 A service is the collective name for producers, filters, transitions and
105 The communications between a connected consumer and producer or service are
106 carried out in 3 phases:
112 MLT employs 'lazy evaluation' - the image and audio need not be extracted
113 from the source until the get image and audio methods are invoked.
115 In essence, the consumer pulls from what it's connected to - this means that
116 threading is typically in the domain of the consumer implementation and some
117 basic functionality is provided on the consumer class to ensure realtime
126 Before we go in to the specifics of the framework architecture, a working
127 example of usage is provided.
129 The following simply provides a media player:
133 #include <framework/mlt.h>
135 int main( int argc, char *argv[] )
137 // Initialise the factory
138 if ( mlt_factory_init( NULL ) == 0 )
140 // Create the default consumer
141 mlt_consumer hello = mlt_factory_consumer( NULL, NULL );
143 // Create via the default producer
144 mlt_producer world = mlt_factory_producer( NULL, argv[ 1 ] );
146 // Connect the producer to the consumer
147 mlt_consumer_connect( hello, mlt_producer_service( world ) );
149 // Start the consumer
150 mlt_consumer_start( hello );
152 // Wait for the consumer to terminate
153 while( !mlt_consumer_is_stopped( hello ) )
156 // Close the consumer
157 mlt_consumer_close( hello );
159 // Close the producer
160 mlt_producer_close( world );
163 mlt_factory_close( );
167 // Report an error during initialisation
168 fprintf( stderr, "Unable to locate factory modules\n" );
175 This is a simple example - it doesn't provide any seeking capabilities or
176 runtime configuration options.
178 The first step of any MLT application is the factory initialisation - this
179 ensures that the environment is configured and MLT can function. The factory
180 is covered in more detail below.
182 All services are instantiated via the factories, as shown by the
183 mlt_factory_consumer and mlt_factory_producer calls above. There are similar
184 factories for filters and transitions. There are details on all the standard
185 services in services.txt.
187 The defaults requested here are a special case - the NULL usage requests
188 that we use the default producers and consumers.
190 The default producer is "fezzik". This producer matches file names to
191 locate a service to use and attaches 'normalising filters' (such as scalers,
192 deinterlacers, resamplers and field normalisers) to the loaded content -
193 these filters ensure that the consumer gets what it asks for.
195 The default consumer is "sdl". The combination of fezzik and sdl will
196 provide a media player.
198 In this example, we connect the producer and then start the consumer. We
199 then wait until the consumer is stopped (in this case, by the action of the
200 user closing the SDL window) and finally close the consumer, producer and
201 factory before exiting the application.
203 Note that the consumer is threaded - waiting for an event of some sort is
204 always required after starting and before stopping or closing the consumer.
206 Also note, you can override the defaults as follows:
208 $ MLT_CONSUMER=westley ./hello file.avi
210 This will create a westley xml document on stdout.
212 $ MLT_CONSUMER=westley MLT_PRODUCER=avformat ./hello file.avi
214 This will play the video using the avformat producer directly, thus it will
215 bypass the normalising functions.
217 $ MLT_CONSUMER=libdv ./hello file.avi > /dev/dv1394
219 This might, if you're lucky, do on the fly, realtime conversions of file.avi
220 to DV and broadcast it to your DV device.
225 As shown in the 'Hello World' example, factories create service objects.
227 The framework itself provides no services - they are provided in the form of
228 a plugin structure. A plugin is organised in the form of a 'module' and a
229 module can provide many services of different types.
231 Once the factory is initialised, all the configured services are available
234 The complete set of methods associated to the factory are as follows:
236 int mlt_factory_init( char *prefix );
237 const char *mlt_factory_prefix( );
238 char *mlt_environment( char *name );
239 mlt_producer mlt_factory_producer( char *name, void *input );
240 mlt_filter mlt_factory_filter( char *name, void *input );
241 mlt_transition mlt_factory_transition( char *name, void *input );
242 mlt_consumer mlt_factory_consumer( char *name, void *input );
243 void mlt_factory_close( );
245 The mlt_factory_prefix returns the path to the location of the installed
246 modules directory. This can be specified in the mlt_factory_init call
247 itself, or it can be specified via the MLT_REPOSITORY environment variable,
248 or in the absence of either of those, it will default to the install
249 prefix/shared/mlt/modules.
251 The mlt_environment provides read only access to a collection of name=value
252 pairs as shown in the following table:
254 +------------------+------------------------------------+------------------+
255 |Name |Description |Values |
256 +------------------+------------------------------------+------------------+
257 |MLT_NORMALISATION |The normalisation of the system |PAL or NTSC |
258 +------------------+------------------------------------+------------------+
259 |MLT_PRODUCER |The default producer |"fezzik" or other |
260 +------------------+------------------------------------+------------------+
261 |MLT_CONSUMER |The default consumer |"sdl" or other |
262 +------------------+------------------------------------+------------------+
263 |MLT_TEST_CARD |The default test card producer |any producer |
264 +------------------+------------------------------------+------------------+
266 These values are initialised from the environment variables of the same
269 As shown above, a producer can be created using the 'default normalising'
270 producer, and they can also be requested by name. Filters and transitions
271 are always requested by name - there is no concept of a 'default' for these.
276 As shown in the services.txt document, all services have their own set of
277 properties than can be manipulated to affect their behaviour.
279 In order to set properties on a service, we need to retrieve the properties
280 object associated to it. For producers, this is done by invoking:
282 mlt_properties properties = mlt_producer_properties( producer );
284 All services have a similar method associated to them.
286 Once retrieved, setting and getting properties can be done directly on this
289 mlt_properties_set( properties, "name", "value" );
291 A more complete description of the properties object is found below.
296 So far, we've shown a simple producer/consumer configuration - the next
297 phase is to organise producers in playlists.
299 Let's assume that we're adapting the Hello World example, and wish to queue
300 a number of files for playout, ie:
304 Instead of invoking mlt_factory_producer directly, we'll create a new
305 function called create_playlist. This function is responsible for creating
306 the playlist, creating each producer and appending to the playlist.
308 mlt_producer create_playlist( int argc, char **argv )
310 // We're creating a playlist here
311 mlt_playlist playlist = mlt_playlist_init( );
313 // We need the playlist properties to ensure clean up
314 mlt_properties properties = mlt_playlist_properties( playlist );
316 // Loop through each of the arguments
318 for ( i = 1; i < argc; i ++ )
320 // Create the producer
321 mlt_producer producer = mlt_factory_producer( NULL, argv[ i ] );
323 // Add it to the playlist
324 mlt_playlist_append( playlist, producer );
326 // Close the producer (see below)
327 mlt_producer_close( producer );
330 // Return the playlist as a producer
331 return mlt_playlist_producer( playlist );
334 Notice that we close the producer after the append. Actually, what we're
335 doing is closing our reference to it - the playlist creates its own reference
336 to the producer on append and insert, and it will close its reference
337 when the playlist is destroyed[*].
339 Note also that if you append multiple instances of the same producer, it
340 will create multiple references to it.
342 Now all we need do is to replace these lines in the main function:
344 // Create a normalised producer
345 mlt_producer world = mlt_factory_producer( NULL, argv[ 1 ] );
350 mlt_producer world = create_playlist( argc, argv );
352 and we have a means to play multiple clips.
354 [*] This reference functionality was introduced in mlt 0.1.2 - it is 100%
355 compatable with the early mechanism of registering the reference and
356 destructor with the properties of the playlist object.
361 Inserting filters between the producer and consumer is just a case of
362 instantiating the filters, connecting the first to the producer, the next
363 to the previous filter and the last filter to the consumer.
367 // Create a producer from something
368 mlt_producer producer = mlt_factory_producer( ... );
370 // Create a consumer from something
371 mlt_consumer consumer = mlt_factory_consumer( ... );
373 // Create a greyscale filter
374 mlt_filter filter = mlt_factory_filter( "greyscale", NULL );
376 // Connect the filter to the producer
377 mlt_filter_connect( filter, mlt_producer_service( producer ), 0 );
379 // Connect the consumer to filter
380 mlt_consumer_connect( consumer, mlt_filter_service( filter ) );
382 As with producers and consumers, filters can be manipulated via their
383 properties object - the mlt_filter_properties method can be invoked and
384 properties can be set as needed.
386 The additional argument in the filter connection is an important one as it
387 dictates the 'track' on which the filter operates. For basic producers and
388 playlists, there's only one track (0), and as you will see in the next
389 section, even multiple tracks have a single track output.
392 Multiple Tracks and Transitions:
394 MLT's approach to multiple tracks is governed by two requirements:
396 1) The need for a consumer and producer to communicate with one another via
398 2) The desire to be able to serialise and manipulate a 'network' (or filter
399 graph if you prefer).
401 We can visualise a multitrack in the way that an NLE presents it:
403 +-----------------+ +-----------------------+
405 +---------------+-+--------------------------+-+---------------------+
407 +------------------------------+
409 The overlapping areas of track 0 and 1 would (presumably) have some kind of
410 transition - without a transition, the frames from b1 and b2 would be shown
411 during the areas of overlap (ie: by default, the higher numbered track takes
412 precedence over the lower numbered track).
414 MLT has a multitrack object, but it is not a producer in the sense that it
415 can be connected directly to a consumer and everything will work correctly.
416 A consumer would treat it precisely as it would a normal producer, and, in
417 the case of the multitrack above, you would never see anything from track 1
418 other than the transitions between the clips - the gap between a1 and a2
419 would show test frames.
421 This happens because a consumer pulls one frame from the producer it's
422 connected to while a multitrack will provide one frame per track.
423 Something, somewhere, must ensure that all frames are pulled from the
424 multitrack and elect the correct frame to pass on.
426 Hence, MLT provides a wrapper for the multitrack, which is called a
427 'tractor', and its the tractors task to ensure that all tracks are pulled
428 evenly, the correct frame is output and that we have 'producer like'
431 Thus, a multitrack is conceptually 'pulled' by a tractor as shown here:
435 | +------+ | +-------+
436 | |track0|-|--->|tractor|
440 | |track1|-|--->|---o---|--->
445 | +------+ | +-------+
448 With a combination of the two, we can now connect multitracks to consumers.
449 The last non-test card will be retrieved and passed on.
451 The tracks can be producers, playlists, or even other tractors.
453 Now we wish to insert filters and transitions between the multitrack and the
454 tractor. We can do this directly by inserting filters directly between the
455 tractor and the multitrack, but this involves a lot of connecting and
456 reconnecting left and right producers and consumers, and it seemed only fair
457 that we should be able to automate that process.
459 So in keeping with our agricultural theme, the concept of the 'field' was
460 born. We 'plant' filters and transitions in the field and the tractor pulls
461 the multitrack (think of a combine harvester :-)) over the field and
462 produces a 'bail' (sorry - kidding - frame :-)).
464 Conceptually, we can see it like this:
468 | +------+ | +-------------+ +-------+
469 | |track0|-|--->|field |--->|tractor|
470 | +------+ | | | |\ |
471 | | | filters | | \ |
472 | +------+ | | and | | \ |
473 | |track1|-|--->| transitions |--->|---o---|--->
474 | +------+ | | | | / |
476 | +------+ | | | |/ |
477 | |track2|-|--->| |--->| |
478 | +------+ | +-------------+ +-------+
481 In reality, we create a field first, and from that we obtain a multitrack
482 and a tractor. We can then populate the multitrack, field and finally,
483 connect the tractor to the consumer.
485 The reasoning behind this is possibly flawed - it might have made more
486 sense to produce the tractor and have it encapsulate the field and the
487 multitrack as that is how it looks to a connected consumer:
489 +-----------------------------------------------+
490 |tractor +--------------------------+ |
491 | +----------+ | +-+ +-+ +-+ +-+ | |
492 | |multitrack| | |f| |f| |t| |t| | |
493 | | +------+ | | |i| |i| |r| |r| | |
494 | | |track0|-|--->| |l|- ->|l|- ->|a|--->|a|\| |
495 | | +------+ | | |t| |t| |n| |n| | |
496 | | | | |e| |e| |s| |s| |\ |
497 | | +------+ | | |r| |r| |i| |i| | \|
498 | | |track1|-|- ->| |0|--->|1|--->|t|--->|t|-|--o--->
499 | | +------+ | | | | | | |i| |i| | /|
500 | | | | | | | | |o| |o| |/ |
501 | | +------+ | | | | | | |n| |n| | |
502 | | |track2|-|- ->| | |- ->| |--->|0|- ->|1|/| |
503 | | +------+ | | | | | | | | | | | |
504 | +----------+ | +-+ +-+ +-+ +-+ | |
505 | +--------------------------+ |
506 +-----------------------------------------------+
508 An example will hopefully clarify this.
510 Let's assume that we want to provide a 'watermark' to our hello world
511 example. We have already extended the example to play multiple clips,
512 and now we will place a text based watermark, reading 'Hello World' in
513 the top left hand corner:
515 mlt_producer create_tracks( int argc, char **argv )
518 mlt_field field = mlt_field_init( );
520 // Obtain the multitrack
521 mlt_multitrack multitrack = mlt_field_multitrack( field );
523 // Obtain the tractor
524 mlt_tractor tractor = mlt_field_tractor( field );
526 // Obtain a composite transition
527 mlt_transition transition = mlt_factory_transition( "composite", "10%,10%:15%x15%" );
530 mlt_producer track0 = create_playlist( argc, argv );
532 // Create the watermark track - note we NEED fezzik for scaling here
533 mlt_producer track1 = mlt_factory_producer( "fezzik", "pango" );
535 // Get the length of track0
536 mlt_position length = mlt_producer_get_playtime( track0 );
538 // Set the properties of track1
539 mlt_properties properties = mlt_producer_properties( track1 );
540 mlt_properties_set( properties, "text", "Hello\nWorld" );
541 mlt_properties_set_position( properties, "in", 0 );
542 mlt_properties_set_position( properties, "out", length - 1 );
543 mlt_properties_set_position( properties, "length", length );
544 mlt_properties_set_int( properties, "a_track", 0 );
545 mlt_properties_set_int( properties, "b_track", 1 );
547 // Now set the properties on the transition
548 properties = mlt_transition_properties( transition );
549 mlt_properties_set_position( properties, "in", 0 );
550 mlt_properties_set_position( properties, "out", length - 1 );
552 // Add our tracks to the multitrack
553 mlt_multitrack_connect( multitrack, track0, 0 );
554 mlt_multitrack_connect( multitrack, track1, 1 );
556 // Now plant the transition
557 mlt_field_plant_transition( field, transition, 0, 1 );
559 // Now set the properties on the tractor
560 properties = mlt_tractor_properties( tractor );
561 mlt_properties_set_data( properties, "multitrack", multitrack, 0, ( mlt_destructor )mlt_multitrack_close, NULL );
562 mlt_properties_set_data( properties, "field", field, 0, ( mlt_destructor )mlt_field_close, NULL );
563 mlt_properties_set_data( properties, "track0", track0, 0, ( mlt_destructor )mlt_producer_close, NULL );
564 mlt_properties_set_data( properties, "track1", track1, 0, ( mlt_destructor )mlt_producer_close, NULL );
565 mlt_properties_set_data( properties, "transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
567 // Return the tractor
568 return mlt_tractor_producer( tractor );
571 Now all we need do is to replace these lines in the main function:
574 mlt_producer world = create_playlist( argc, argv );
578 // Create a watermarked playlist
579 mlt_producer world = create_tracks( argc, argv );
581 and we have a means to play multiple clips with a horribly obtrusive
582 watermark - just what the world needed, right? ;-)
584 Incidentally, the same thing could be achieved with the more trivial
585 watermark filter inserted between the producer and the consumer.
588 SECTION 3 - STRUCTURE AND DESIGN
589 --------------------------------
593 The mlt framework consists of an OO class hierarchy which consists of the
594 following public classes and abstractions:
609 Each class defined above can be read as extending the classes above and to
612 The following sections describe the properties, stacking/queuing and memory
613 pooling functionality provided by the framework - these are key components
614 and a basic understanding of these is required for the remainder of the
620 The properties class is the base class for the frame and service classes.
622 It is designed to provide an efficient lookup table for various types of
623 information, such as strings, integers, floating points values and pointers
624 to data and data structures.
626 All properties are indexed by a unique string.
628 The most basic use of properties is as follows:
630 // 1. Create a new, empty properties set;
631 mlt_properties properties = mlt_properties_new( );
633 // 2. Assign the value "world" to the property "hello";
634 mlt_properties_set( properties, "hello", "world" );
636 // 3. Retrieve and print the value of "hello";
637 printf( "%s\n", mlt_properties_get( properties, "hello" ) );
639 // 4. Reassign "hello" to "world!";
640 mlt_properties_set( properties, "hello", "world!" );
642 // 5. Retrieve and print the value of "hello";
643 printf( "%s\n", mlt_properties_get( properties, "hello" ) );
645 // 6. Assign the value "0" to "int";
646 mlt_properties_set( properties, "int", "0" );
648 // 7. Retrieve and print the integer value of "int";
649 printf( "%d\n", mlt_properties_get_int( properties, "int" ) );
651 // 8. Assign the integer value 50 to "int2";
652 mlt_properties_set_int( properties, "int2", 50 );
654 // 9. Retrieve and print the double value of "int2";
655 printf( "%s\n", mlt_properties_get( properties, "int2" ) );
657 Steps 2 through 5 demonstrate that the "name" is unique - set operations on
658 an existing "name" change the value. They also free up memory associated to
659 the previous value. Note that it also possible to change type in this way
662 Steps 6 and 7 demonstrate that the properties object handles deserialisation
663 from strings. The string value of "0" is set, the integer value of 0 is
666 Steps 8 and 9 demonstrate that the properties object handles serialisation
669 To show all the name/value pairs in a properties, it is possible to iterate
672 for ( i = 0; i < mlt_properties_count( properties ); i ++ )
673 printf( "%s = %s\n", mlt_properties_get_name( properties, i ),
674 mlt_properties_get_value( properties, i ) );
676 Note that properties are retrieved in the order in which they are set.
678 Properties are also used to hold pointers to memory. This is done via the
681 uint8_t *image = malloc( size );
682 mlt_properties_set_data( properties, "image", image, size, NULL, NULL );
684 In this example, we specify that the pointer can be retrieved from
685 properties by a subsequent request to get_data:
687 image = mlt_properties_get_data( properties, "image", &size );
691 image = mlt_properties_get_data( properties, "image", NULL );
693 if we don't wish to retrieve the size.
697 1) The allocated memory remains after the properties object is closed unless
698 you specify a destructor. In the case above, this can be done with:
700 mlt_properties_set_data( properties, "image", image, size, free, NULL );
702 When the properties are closed, or the value of "image" is changed, the
703 destructor is invoked.
705 2) The string value returned by mlt_properties_get is NULL. Typically, you
706 wouldn't wish to serialise an image as a string, but other structures
707 might need such functionality - you can specify a serialiser as the last
708 argument if required (declaration is char *serialise( void * )).
710 Properties also provides some more advanced usage capabilities.
712 It has the ability to inherit all serialisable values from another properties
715 mlt_properties_inherit( this, that );
717 It has the ability to mirror properties set on this on another set of
720 mlt_properties_mirror( this, that );
722 After this call, all serialisable values set on this are passed on to that.
727 Stacks and queues are essential components in the MLT framework. Being of a
728 lazy disposition, we elected to implement a 'Double Ended Queue' (deque) -
729 this encapsulates the functionality of both.
731 The API of the deque is defined as follows:
733 mlt_deque mlt_deque_init( );
734 int mlt_deque_count( mlt_deque this );
735 int mlt_deque_push_back( mlt_deque this, void *item );
736 void *mlt_deque_pop_back( mlt_deque this );
737 int mlt_deque_push_front( mlt_deque this, void *item );
738 void *mlt_deque_pop_front( mlt_deque this );
739 void *mlt_deque_peek_back( mlt_deque this );
740 void *mlt_deque_peek_front( mlt_deque this );
741 void mlt_deque_close( mlt_deque this );
743 The stacking operations are used in a number of places:
745 * Reverse Polish Notation (RPN) image and audio operations
748 The queuing operations are used in:
750 * the consumer base class;
751 * consumer implementations may require further queues.
756 The MLT framework provides memory pooling capabilities through the mlt_pool
757 API. Once initilialised, these can be seen as a straightforward drop in
758 replacement for malloc/realloc/free functionality.
760 The background behind this API is that malloc/free operations are
761 notoriously inefficient, especially when dealing with large blocks of memory
762 (such as an image). On linux, malloc is optimised for memory allocations
763 less than 128k - memory blocks allocated of these sizes or less are retained
764 in the process heap for subsequent reuse, thus bypassing the kernel calls
765 for repeated allocation/frees for small blocks of memory. However, blocks of
766 memory larger than that require kernel calls and this has a detrimental
767 impact on performance.
769 The mlt_pool design is simply to hold a list of stacks - there is one stack
770 per 2^n bytes (where n is between 8 and 31). When an alloc is called, the
771 requested size is rounded to the next 2^n, the stack is retrieved for that
772 size, and an item is popped or created if the stack is empty.
774 Each item has a 'header', situated immediately before the returned address -
775 this holds the 'stack' to which the item belongs.
777 When an item is released, we retrieve the header, obtain the stack and push
780 Thus, from the programmers point of view, the API is the same as the
781 traditional malloc/realloc/free calls:
783 void *mlt_pool_alloc( int size );
784 void *mlt_pool_realloc( void *ptr, int size );
785 void mlt_pool_release( void *release );
790 A frame object is essentially defined as:
800 The life cycle of a frame can be represented as follows:
802 +-----+----------------------+-----------------------+---------------------+
803 |Stage|Producer |Filter |Consumer |
804 +-----+----------------------+-----------------------+---------------------+
805 | 0.0 | | |Request frame |
806 +-----+----------------------+-----------------------+---------------------+
807 | 0.1 | |Receives request | |
808 | | |Request frame | |
809 +-----+----------------------+-----------------------+---------------------+
810 | 0.2 |Receives request | | |
811 | |Generates frame for | | |
812 | |current position | | |
813 | |Increments position | | |
814 +-----+----------------------+-----------------------+---------------------+
815 | 0.3 | |Receives frame | |
816 | | |Updates frame | |
817 +-----+----------------------+-----------------------+---------------------+
818 | 0.4 | | |Receives frame |
819 +-----+----------------------+-----------------------+---------------------+
821 Note that neither the filter nor the consumer have any conception of
822 'position' until they receive a frame. Speed and position are properties of
823 the producer, and they are assigned to the frame object when the producer
826 Step 0.3 is a critical one here - if the filter determines that the frame is
827 of interest to it, then it should manipulate the image and/or audio stacks
828 and properties as required.
830 Assuming that the filter deals with both image and audio, then it should
831 push data and methods on to the stacks which will deal with the processing.
832 This can be done with the mlt_frame_push_image and audio methods. In order for
833 the filter to register interest in the frame, the stacks should hold:
836 [ producer_get_image ] [ data1 ] [ data2 ] [ filter_get_image ]
839 [ producer_get_audio ] [ data ] [ filter_get_audio ]
841 The filter_get methods are invoked automatically when the consumer invokes a
842 get_image on the frame.
844 +-----+----------------------+-----------------------+---------------------+
845 |Stage|Producer |Filter |Consumer |
846 +-----+----------------------+-----------------------+---------------------+
847 | 1.0 | | |frame_get_image |
848 +-----+----------------------+-----------------------+---------------------+
849 | 1.1 | |filter_get_image: | |
850 | | | pop data2 and data1 | |
851 | | | frame_get_image | |
852 +-----+----------------------+-----------------------+---------------------+
853 | 1.2 |producer_get_image | | |
854 | | Generates image | | |
855 +-----+----------------------+-----------------------+---------------------+
856 | 1.3 | |Receives image | |
857 | | |Updates image | |
858 +-----+----------------------+-----------------------+---------------------+
859 | 1.4 | | |Receives image |
860 +-----+----------------------+-----------------------+---------------------+
862 Obviously, if the filter isn't interested in the image, then it should leave
863 the stack alone, and then the consumer will retrieve its image directly from
866 Similarly, audio is handled as follows:
868 +-----+----------------------+-----------------------+---------------------+
869 |Stage|Producer |Filter |Consumer |
870 +-----+----------------------+-----------------------+---------------------+
871 | 2.0 | | |frame_get_audio |
872 +-----+----------------------+-----------------------+---------------------+
873 | 2.1 | |filter_get_audio: | |
875 | | | frame_get_audio | |
876 +-----+----------------------+-----------------------+---------------------+
877 | 2.2 |producer_get_audio | | |
878 | | Generates audio | | |
879 +-----+----------------------+-----------------------+---------------------+
880 | 2.3 | |Receives audio | |
881 | | |Updates audio | |
882 +-----+----------------------+-----------------------+---------------------+
883 | 2.4 | | |Receives audio |
884 +-----+----------------------+-----------------------+---------------------+
886 And finally, when the consumer is done with the frame, it should close it.
888 Note that a consumer may not evaluate both image and audio for any given
889 frame, especially in a realtime environment. See 'Realtime Considerations'
892 By default, a frame has the following properties:
894 +------------------+------------------------------------+------------------+
895 |Name |Description |Values |
896 +------------------+------------------------------------+------------------+
897 |_position |The producers frame position |0 to n |
898 +------------------+------------------------------------+------------------+
899 |_speed |The producers speed |double |
900 +------------------+------------------------------------+------------------+
901 |image |The generated image |NULL or pointer |
902 +------------------+------------------------------------+------------------+
903 |alpha |The generated alpha mask |NULL or pointer |
904 +------------------+------------------------------------+------------------+
905 |width |The width of the image | |
906 +------------------+------------------------------------+------------------+
907 |height |The height of the image | |
908 +------------------+------------------------------------+------------------+
909 |normalised_width |The normalised width of the image |720 |
910 +------------------+------------------------------------+------------------+
911 |normalised_height |The normalised height of the image |576 or 480 |
912 +------------------+------------------------------------+------------------+
913 |progressive |Indicates progressive/interlaced |0 or 1 |
914 +------------------+------------------------------------+------------------+
915 |top_field_first |Indicates top field first |0 or 1 |
916 +------------------+------------------------------------+------------------+
917 |audio |The generated audio |NULL or pointer |
918 +------------------+------------------------------------+------------------+
919 |frequency |The frequency of the audio | |
920 +------------------+------------------------------------+------------------+
921 |channels |The channels of the audio | |
922 +------------------+------------------------------------+------------------+
923 |samples |The samples of the audio | |
924 +------------------+------------------------------------+------------------+
925 |aspect_ratio |The sample aspect ratio of the image|double |
926 +------------------+------------------------------------+------------------+
927 |test_image |Used to indicate no image available |0 or 1 |
928 +------------------+------------------------------------+------------------+
929 |test_audio |Used to indicate no audio available |0 or 1 |
930 +------------------+------------------------------------+------------------+
932 The consumer can attach the following properties which affect the default
933 behaviour of a frame:
935 +------------------+------------------------------------+------------------+
936 |test_card_producer|Synthesise test images from here |NULL or pointer |
937 +------------------+------------------------------------+------------------+
938 |consumer_aspect_ |Apply this aspect ratio to the test |double |
939 |ratio |card producer | |
940 +------------------+------------------------------------+------------------+
941 |rescale.interp |Use this scale method for test image|"string" |
942 +------------------+------------------------------------+------------------+
944 While most of these are mainly self explanatory, the normalised_width and
945 normalised_height values require a little explanation. These are required
946 to ensure that effects are consistently handled as PAL or NTSC, regardless
947 of the consumers or producers width/height image request.
949 The test_image and audio flags are used to determine when images and audio
950 should be synthesised.
952 Additional properties may be provided by the producer implementation, and
953 filters, transitions and consumers may add additional properties to
954 communicate specific requests. These are documented in modules.txt.
956 The complete API for the mlt frame is as follows:
958 mlt_frame mlt_frame_init( );
959 mlt_properties mlt_frame_properties( mlt_frame this );
960 int mlt_frame_is_test_card( mlt_frame this );
961 int mlt_frame_is_test_audio( mlt_frame this );
962 double mlt_frame_get_aspect_ratio( mlt_frame this );
963 int mlt_frame_set_aspect_ratio( mlt_frame this, double value );
964 mlt_position mlt_frame_get_position( mlt_frame this );
965 int mlt_frame_set_position( mlt_frame this, mlt_position value );
966 int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable );
967 uint8_t *mlt_frame_get_alpha_mask( mlt_frame this );
968 int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples );
969 int mlt_frame_push_get_image( mlt_frame this, mlt_get_image get_image );
970 mlt_get_image mlt_frame_pop_get_image( mlt_frame this );
971 int mlt_frame_push_frame( mlt_frame this, mlt_frame that );
972 mlt_frame mlt_frame_pop_frame( mlt_frame this );
973 int mlt_frame_push_service( mlt_frame this, void *that );
974 void *mlt_frame_pop_service( mlt_frame this );
975 int mlt_frame_push_audio( mlt_frame this, void *that );
976 void *mlt_frame_pop_audio( mlt_frame this );
977 void mlt_frame_close( mlt_frame this );
982 The service base class extends properties and allows 0 to m inputs and 0 to
983 n outputs and is represented as follows:
993 Descendents of service impose restrictions on how inputs and outputs can be
994 connected and will provide a basic set of properties. Typically, the service
995 instance is encapsulated by the descendent in order for it to ensure that
996 its connection rules are followed.
998 A service does not define any properties when constructed. It should be
999 noted that producers, filters and transitions my be serialised (say, via the
1000 westley consumer), and care should be taken to distinguish between
1001 serialisable and transient properties. The convention used is to prefix
1002 transient properties with an underscore.
1004 The public interface is defined by the following functions:
1006 int mlt_service_init( mlt_service this, void *child );
1007 mlt_properties mlt_service_properties( mlt_service this );
1008 int mlt_service_connect_producer( mlt_service this, mlt_service producer, int index );
1009 int mlt_service_get_frame( mlt_service this, mlt_frame_ptr frame, int index );
1010 void mlt_service_close( mlt_service this );
1012 Typically, only direct descendents of services need invoke these methods and
1013 developers are encouraged to use those extensions when defining new services.
1018 A producer has 0 inputs and 1 output:
1028 A producer provides an abstraction for file readers, pipes, streams or any
1029 other image or audio input.
1031 When instantiated, a producer has the following properties:
1033 +------------------+------------------------------------+------------------+
1034 |Name |Description |Values |
1035 +------------------+------------------------------------+------------------+
1036 |mlt_type |The producers type |mlt_producer |
1037 +------------------+------------------------------------+------------------+
1038 |_position |The producers frame position |0 to n |
1039 +------------------+------------------------------------+------------------+
1040 |_speed |The producers speed |double |
1041 +------------------+------------------------------------+------------------+
1042 |fps |The output frames per second |25 or 29.97 |
1043 +------------------+------------------------------------+------------------+
1044 |in |The in point in frames |0 to length - 1 |
1045 +------------------+------------------------------------+------------------+
1046 |out |The out point in frames |in to length - 1 |
1047 +------------------+------------------------------------+------------------+
1048 |length |The length of the input in frames |0 to n |
1049 +------------------+------------------------------------+------------------+
1050 |aspect_ratio |aspect_ratio of the source |0 to n |
1051 +------------------+------------------------------------+------------------+
1052 |eof |end of clip behaviour |"pause" or "loop" |
1053 +------------------+------------------------------------+------------------+
1054 |resource |Constructor argument (ie: file name)|"<resource>" |
1055 +------------------+------------------------------------+------------------+
1057 Additional properties may be provided by the producer implementation.
1059 The public interface is defined by the following functions:
1061 mlt_producer mlt_producer_new( );
1062 int mlt_producer_init( mlt_producer this, void *child );
1063 mlt_service mlt_producer_service( mlt_producer this );
1064 mlt_properties mlt_producer_properties( mlt_producer this );
1065 int mlt_producer_seek( mlt_producer this, mlt_position position );
1066 mlt_position mlt_producer_position( mlt_producer this );
1067 mlt_position mlt_producer_frame( mlt_producer this );
1068 int mlt_producer_set_speed( mlt_producer this, double speed );
1069 double mlt_producer_get_speed( mlt_producer this );
1070 double mlt_producer_get_fps( mlt_producer this );
1071 int mlt_producer_set_in_and_out( mlt_producer this, mlt_position in, mlt_position out );
1072 mlt_position mlt_producer_get_in( mlt_producer this );
1073 mlt_position mlt_producer_get_out( mlt_producer this );
1074 mlt_position mlt_producer_get_playtime( mlt_producer this );
1075 mlt_position mlt_producer_get_length( mlt_producer this );
1076 void mlt_producer_prepare_next( mlt_producer this );
1077 void mlt_producer_close( mlt_producer this );
1082 The public interface is defined by the following functions:
1084 int mlt_filter_init( mlt_filter this, void *child );
1085 mlt_filter mlt_filter_new( );
1086 mlt_service mlt_filter_service( mlt_filter this );
1087 mlt_properties mlt_filter_properties( mlt_filter this );
1088 mlt_frame mlt_filter_process( mlt_filter this, mlt_frame that );
1089 int mlt_filter_connect( mlt_filter this, mlt_service producer, int index );
1090 void mlt_filter_set_in_and_out( mlt_filter this, mlt_position in, mlt_position out );
1091 int mlt_filter_get_track( mlt_filter this );
1092 mlt_position mlt_filter_get_in( mlt_filter this );
1093 mlt_position mlt_filter_get_out( mlt_filter this );
1094 void mlt_filter_close( mlt_filter );
1099 The public interface is defined by the following functions:
1101 int mlt_transition_init( mlt_transition this, void *child );
1102 mlt_transition mlt_transition_new( );
1103 mlt_service mlt_transition_service( mlt_transition this );
1104 mlt_properties mlt_transition_properties( mlt_transition this );
1105 int mlt_transition_connect( mlt_transition this, mlt_service producer, int a_track, int b_track );
1106 void mlt_transition_set_in_and_out( mlt_transition this, mlt_position in, mlt_position out );
1107 int mlt_transition_get_a_track( mlt_transition this );
1108 int mlt_transition_get_b_track( mlt_transition this );
1109 mlt_position mlt_transition_get_in( mlt_transition this );
1110 mlt_position mlt_transition_get_out( mlt_transition this );
1111 mlt_frame mlt_transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame );
1112 void mlt_transition_close( mlt_transition this );
1117 The public interface is defined by the following functions:
1119 int mlt_consumer_init( mlt_consumer this, void *child );
1120 mlt_service mlt_consumer_service( mlt_consumer this );
1121 mlt_properties mlt_consumer_properties( mlt_consumer this );
1122 int mlt_consumer_connect( mlt_consumer this, mlt_service producer );
1123 int mlt_consumer_start( mlt_consumer this );
1124 mlt_frame mlt_consumer_get_frame( mlt_consumer this );
1125 mlt_frame mlt_consumer_rt_frame( mlt_consumer this );
1126 int mlt_consumer_stop( mlt_consumer this );
1127 int mlt_consumer_is_stopped( mlt_consumer this );
1128 void mlt_consumer_close( mlt_consumer );
1131 Specialised Producers:
1133 There are two major types of specialised producers - playlists and tractors.
1135 The following sections describe these.
1140 mlt_playlist mlt_playlist_init( );
1141 mlt_producer mlt_playlist_producer( mlt_playlist this );
1142 mlt_service mlt_playlist_service( mlt_playlist this );
1143 mlt_properties mlt_playlist_properties( mlt_playlist this );
1144 int mlt_playlist_count( mlt_playlist this );
1145 int mlt_playlist_clear( mlt_playlist this );
1146 int mlt_playlist_append( mlt_playlist this, mlt_producer producer );
1147 int mlt_playlist_append_io( mlt_playlist this, mlt_producer producer, mlt_position in, mlt_position out );
1148 int mlt_playlist_blank( mlt_playlist this, mlt_position length );
1149 mlt_position mlt_playlist_clip( mlt_playlist this, mlt_whence whence, int index );
1150 int mlt_playlist_current_clip( mlt_playlist this );
1151 mlt_producer mlt_playlist_current( mlt_playlist this );
1152 int mlt_playlist_get_clip_info( mlt_playlist this, mlt_playlist_clip_info *info, int index );
1153 int mlt_playlist_insert( mlt_playlist this, mlt_producer producer, int where, mlt_position in, mlt_position out );
1154 int mlt_playlist_remove( mlt_playlist this, int where );
1155 int mlt_playlist_move( mlt_playlist this, int from, int to );
1156 int mlt_playlist_resize_clip( mlt_playlist this, int clip, mlt_position in, mlt_position out );
1157 void mlt_playlist_close( mlt_playlist this );