forked from Eoin-ONeill-Yokai/mlt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlt++.txt
542 lines (398 loc) · 16.3 KB
/
mlt++.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
MLT++
-----
This mlt sub-project provides a C++ wrapping for the MLT library.
Usage
-----
Use the following definitions in a Makefile to compile and link with mlt++:
CXXFLAGS=`pkg-config --cflags mlt-framework-7` -Wall
LDFLAGS=-lmlt++-7 `pkg-config --libs mlt-framework-7`
Include files for the classes can either be explicitly included, ie:
#include <mlt++/MltProducer.h>
etc
Or you can include all using:
#include <mlt++/Mlt.h>
All definitions are placed in an Mlt namespace, and adhere closely to the C
naming convention. Mappings always follow the pattern:
Factory methods:
mlt_factory_init ==> Mlt::Factory::init
mlt_factory_producer ==> Mlt::Factory::producer
mlt_factory_filter ==> Mlt::Factory::filter
mlt_factory_transition ==> Mlt::Factory::transition
mlt_factory_consumer ==> Mlt::Factory::consumer
mlt_factory_close ==> Mlt::Factory::close
NB: Factory usage for service construction is optional.
Types:
mlt_properties ==> Mlt::Properties
mlt_frame ==> Mlt::Frame
mlt_service ==> Mlt::Service
mlt_producer ==> Mlt::Producer
mlt_filter ==> Mlt::Filter
mlt_transition ==> Mlt::Transition
mlt_consumer ==> Mlt::Consumer
Methods:
mlt_type_method ==> Mlt::Type.method
ie: mlt_playlist_append ==> Mlt::Playlist.append
Parent methods are available directly on children.
Additionally, you can specify:
using namespace Mlt;
To avoid the enforced use of the Mlt:: prefix.
Enumerators and macros are reused directly from the C library.
Class Hierarchy
---------------
The currently mapped objects are shown in the following hierarchy:
Factory
Properties
Frame
Service
Consumer
Field
Filter
Multitrack
Producer
Playlist
Tractor
Transition
Special Cases
-------------
Care should be taken with wrapper objects.
Taking, as an example, the C function that returns the immediate consumer of
a service:
mlt_service mlt_service_consumer( mlt_service );
This maps to:
Mlt::Service *Mlt::Service.consumer( );
Note that you get an object back - it is never the original c++ object, but
a wrapping object. This is done to keep consistency with the C api which may
instantiate C instances - therefore it cannot be assumed that a C++ object
exists for all mlt service instances.
As such, it is mandatory that you delete these objects. The original will
not be affected. However, all other modifications (to properties or its
state of connection) will be reflected in the original object.
This approach excludes the use of RTTI to determine the real type of the
object - this can only be done by parsing the objects properties.
Objects may be invalid - always use the is_valid method to check validity
before use.
Limitations
-----------
The mechanisms for the definition of new services are deliberately
excluded from the C++ wrappings - this is done to ensure that service
networks constructed can be serialised and used by existing applications
which are based on the C API (such as melted).
Hello World
-----------
The mlt++ wrapper is a c++ wrapper for the mlt C library. As such, it
provides clean C++ access to the underlying library.
An example of use is as follows:
#include <mlt++/Mlt.h>
using namespace Mlt;
int main( void )
{
Factory::init( );
Producer p( "pango:", "Hello World" );
Consumer c( "sdl" );
c.connect( p );
c.run( );
return 0;
}
This is a fairly typical example of mlt++ usage - create a 'producer' (an
object which produces 'frames'), create a 'consumer' (an object which consumes
frames), connect them together, start the consumer and wait until done (here
we just wait for the user to close the window).
In this case, we construct a window as a consumer using the 'sdl' consumer
(SDL is a standard portable library which provides platform independent
access to accelerated video display and audio) and use the 'pango'
producer to generate frames with the words 'Hello World' (pango is a
library from the gtk toolkit).
The main point of this example is to show that mlt uses existing libraries
to provide its functionality - this keeps the framework itself very small.
Note that mlt is designed to be housed in GUI or server type applications -
typically, applications don't wait around for the consumer to be stopped in
the manner shown.
So far, we've introduced the Producer and Consumer mlt classes. We'll cover
each of these in more detail later in the tutorial, but for now, we'll
briefly cover the remaining classes.
Playlists
---------
Another simple class is the Playlist - this is direct extension of Producer
and it allows you to maintain a list of producer objects.
As a simple example of the Playlist in action, we'll convert the example
above into an application which plays multiple video or audio files.
#include <mlt++/Mlt.h>
using namespace Mlt;
int main( int argc, char **argv )
{
Factory::init( );
Playlist list;
for ( int i = 1; i < argc; i ++ )
{
Producer p( argv[i] );
if ( p.is_valid( ) )
list.append( p );
}
Consumer c( "sdl" );
c.connect( list );
c.run( );
return 0;
}
Now you can run the program as:
./player *.avi *.mp3 *.jpg etc
In this case, we construct a playlist by simply appending producers to it.
Notice that although the scope of the Producer is limited to the inner
for loop, we can safely add it to the playlist - this is due to the fact
that all mlt objects maintain reference counts and no object is really
destroyed until all the references are gone. In this case, when the list
object goes out of scope, all the producers we created will automatically
be destroyed.
Filters
-------
So far, we've shown how you can load and play media. We've given a brief
intro to the Playlist container, now it's time to start manipulating
things...
For the next example, I'll add a 'watermark' to the video - a watermark
is used by broadcasters to brand the channel and normally consists of a
logo of some sort. We'll just use some black text on a partially
transparent red background.
#include <mlt++/Mlt.h>
using namespace Mlt;
int main( int argc, char **argv )
{
Factory::init( );
Playlist list;
for ( int i = 1; i < argc; i ++ )
{
Producer p( argv[i] );
if ( p.is_valid( ) )
list.append( p );
}
Filter f( "watermark", "pango:" );
f.set( "producer.text", "MLT++" );
f.set( "producer.fgcolour", "0x000000ff" );
f.set( "producer.bgcolour", "0xff000080" );
list.attach( f );
Consumer c( "sdl" );
c.connect( list );
c.run( );
return 0;
}
Notice that the watermark filter reuses the 'pango' producer we showed in the
first example. In fact, you could use any producer here - if you wanted to
use a graphic or a video, you would just construct the filter with a full path
to that as the second argument.
We manipulate the filter using the set method - this method was also shown
in the first example.
Finally, we attach the filter to the playlist. This ensure that all frames
that are obtained from the playlist are watermarked.
Cuts
----
When you add a clip to a playlist, the a cut object is created - this is merely a
wrapper for the producer, spanning the specified in and out points.
Whenever you retrieve a clip from a playlist, you will always get a cut object.
This allows you to attach filters to a specific part of a producer and should
the position of the cut in the playlist change, then the filter will remain
correctly associated to it.
A producer and a cut are generally identical in behaviour, but should you need to
distinguish between them, you can use:
if ( producer.is_cut( ) )
and to retrieve the parent of a cut, you can use:
Producer parent = producer.parent_cut( );
Filters that are attached directly to a parent are executed before any filters
attached to the cut.
Tractor
-------
A tractor is an object that allows the manipulation of multiple video and audio
tracks.
Stepping away from the player example we've been tinkering with for a minute,
let's assume we want to do something like dub a video with some audio. This
a very trivial thing to do:
Tractor *dub( char *video_file, char *audio_file )
{
Tractor *tractor = new Tractor( );
Producer video( video_file );
Producer audio( audio_file );
tractor->set_track( video, 0 );
tractor->set_track( audio, 1 );
return tractor;
}
That's all that needs to be done - you can now connect the returned object to a
consumer, or add it to a playlist, or even apply it as a track to another tractor.
Transition
----------
Let's now assume we want to mix the audio between two tracks - to do this, we
need to introduce the concept of a transition. A transition in mlt is a service
which combines frames from two producers to produce a new frame.
Tractor *mix( char *video_file, char *audio_file )
{
Tractor *tractor = new Tractor( );
Transition mix( "mix" );
Producer video( video_file );
Producer audio( audio_file );
tractor.set_track( video, 0 );
tractor.set_track( audio, 1 );
tractor.field.plant_transition( mix, 0, 1 );
return tractor;
}
The tractor returned will now mix the audio from the original video and the
audio.
Mix
---
There is a convenience function which simplifies the process of applying
transitions betwee adjacent cuts on a playlist. This is often preferable
to use over the construction of your own tractor and transition set up.
To apply a 25 frame luma transition between the first and second cut on
the playlist, you could use:
Transition luma;
playlist.mix( 0, 25, luma );
Events
------
Typically, applications need to be informed when changes occur in an mlt++ object.
This facilitates application services such as undo/redo management, or project
rendering in a timeline type widget and many other types of operations which an
application needs.
As an example, consider the following:
class Xml
{
private:
Consumer consumer;
Tractor &tractor;
public:
Xml( MltTractor &tractor ) :
tractor( tractor ),
consumer( "xml" )
{
consumer.connect( tractor );
tractor.listen( tractor, "producer-changed",
( mlt_listener )Xml::listener );
}
static void listener( Properties *tractor, Xml *object )
{
object->activate( );
}
void activate( )
{
consumer.start( );
}
};
Now, each time the tractor is changed, the XML representation is output to
stderr.
That's All Folks...
-------------------
And that, believe it or not, is a fairly complete summary of the classes you'll
typically be interfacing with in mlt++. Obviously, there's a little more to it
than this - a couple of intrinsic classes have been glossed over (notably, the
Properties and Service base classes). The next section will cover all of the
above, but in much more detail...
DIGGING DEEPER
--------------
The previous section was designed to give you a whistle stop tour through the major
framework classes. This section will take you through the scenic route.
Introducing Base Classes
------------------------
Services in mlt are the collective noun for Producers, Filters, Transitions and
Consumer. A Service is also the base class from which all of these classes
extend. It provides the basic connectivity which has been shown throughout the
examples in the previous section.
Properties are the main way in which we communicate with the Services -
essentially, it provides get/set methods for named values. All services extend
Properties.
Properties
----------
Properties provide the general mechanism for communicating with Services -
through the Properties interface, we are able to manipulate and serialise
a services state.
For example, to dump all the properties to stdout, you can use something
like:
void dump( Properties &properties )
{
for ( int i = 0; i < properties.count( ); i ++ )
cout << Properties.get_name( i ) << " = " << Properties.get( i ) << endl;
}
Note that the properties object handles type conversion, so the following
is acceptable:
properties.set( "hello", "10.5" );
int hello_int = properties.get_int( "hello" );
double hello_double = properties.get_double( "hello" );
A couple of convenience methods are provide to examine or serialise property
objects.
For example:
properties.debug( );
will report all serialisable properties on stderr, in the form:
Object: [ ref=1, in=0, out=0, track=0, u=75, v=150, _unique_id=15,
mlt_type=filter, mlt_service=sepia ]
Services
--------
Typically, all the services are constructed via the specific classes
constructor. Often, you will receive Service objects rather than their
specific type. In order to access the extended classes interface,
you will need to create a reference.
For example, given an arbitrary Service object, you can determine its
type by using the type method - this will return a 'service_type' which
has values of producer_type, filter_type etc. Alternatively, you can
create a wrapping object and check on its validity.
bool do_we_have_a_producer( Service &service )
{
Producer producer( service );
return producer.is_valid( );
}
Events
------
Servers and MLT XML Docs
------------------------
For various reasons, you might want to serialise a producer to a string.
To do this, you just need to specify a property to write to:
Consumer xml( "xml", "buffer" );
xml.connect( producer );
xml.start( );
buffer = xml.get( "buffer" );
You can use any name you want, and you can change it using the "resource"
property. Any name with a '.' in it is considered to be a file. Hence, you
can use a xml consumer to store multiple instances of the same MLT
object - useful if you want to provide undo/redo capabilities in an
editing application.
Should you receive an XML document as a string, and you want to send it
on to a server, you can use:
Consumer client( "mvsp", "localhost:5250" );
client.set( "xml", buffer );
client.start( );
If you need to obtain an MLT object from a XML string:
Producer producer( "xml-string", buffer );
The following shows a working example of an extended server:
class ShotcutServer : public Melted
{
public:
ShotcutServer( char *id, int port ) :
Melted( id, port )
{
}
void set_receive_doc( bool doc )
{
set( "push-parser-off", doc );
}
// Reject all commands other than push/receive
Response *execute( char *command )
{
mvsp_response response = mvsp_response_init( );
mvsp_response_set_error( response, 400, "Not OK" );
return new Response( response );
}
// Push document handler
Response *received( char *command, char *doc )
{
mvsp_response response = mvsp_response_init( );
// Use doc in some way and assign Response
if ( doc != NULL )
mvsp_response_set_error( response, 200, "OK" );
return new Response( response );
}
// Push service handler
Response *push( char *command, Service *service )
{
mvsp_response response = mvsp_response_init( );
// Use service in some way and assign Response
if ( service != NULL )
mvsp_response_set_error( response, 200, "OK" );
return new Response( response );
}
};
NB: Should you be incorporating this into a GUI application, remember that the
execute, received and push methods are invoked from a thread - make sure that
you honour the locking requirements of your GUI toolkit before interacting with
the UI.