Analysis of Production and Consumption Architecture of MLT Multimedia Framework
premise
- By reading [MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (1), the following two points are satisfied:
- Understand the hierarchical relationship of MLT's core C++ packaging
- Master using MLT's Consumer (sdl) to consume Producer (MP4)
- By reading [MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (2), the following two points are satisfied:
- Understand Service (service abstract base class) and Filter (filter abstract service class)
- Master adding Filter to Producer
What can I get from this article?
This article will transform the width and height attributes of the filter attached to the producer on the basis of [MLT] MLT Multimedia Framework Production and Consumption Architecture Analysis (2) , as shown below:
Core class analysis
Properties
[MLT] Analysis of the production and consumption architecture of the MLT multimedia framework (1) simply demonstrates the simple process of the producer (initialized as a video resource) being consumed by the consumer (initialized as SDL). [MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (2) In (1), the video producer is simply processed and a video filter is added. As shown in the figure above, this section introduces a new encapsulation for the filter setting properties: Properties (property class) , which provides a general mechanism for communicating with the Service, and we can manipulate and serialize the Service state . This section only briefly introduces the methods we are going to use, and we will fully analyze the property encapsulation later.
// 属性类
// 此类重载了大量的序列化的方法,供各种各样的场景使用
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(char*)
* @return 是否设置成功的错误码
*/
int set( const char *name, const char *value );
/**
* @brief set_string 序列化方法
* @param name 要设置的属性key
* @param value 属性值(char*)
* @return 是否设置成功的错误码
*/
int set_string( const char *name, const char *value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(int)
* @return 是否设置成功的错误码
*/
int set( const char *name, int value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(int64_t)
* @return 是否设置成功的错误码
*/
int set( const char *name, int64_t value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(double)
* @return 是否设置成功的错误码
*/
int set( const char *name, double value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(double)
* @param size 默认传0
* @param destroy 析构方法
* @param serial 序列化方法
* @return 是否设置成功的错误码
*/
int set( const char *name, void *value, int size, mlt_destructor destroy = NULL, mlt_serialiser serial = NULL );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(mlt_color)
* @return 是否设置成功的错误码
*/
int set( const char *name , mlt_color value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param value 属性值(mlt_rect)
* @return 是否设置成功的错误码
*/
int set( const char *name, mlt_rect value );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param x x值
* @param y y值
* @param w width值
* @param h height值
* @param opacity opacity值
* @return 是否设置成功的错误码
*/
int set( const char *name, double x, double y, double w, double h, double opacity = 1.0 );
/**
* @brief set 序列化方法
* @param name 要设置的属性key
* @param properties 属性值(Properties)
* @return
*/
int set( const char *name, Properties& properties );
Add filters for producers
// 创建马赛克滤镜
Mlt::Filter *filter = new Mlt::Filter(profile, "frei0r.pixeliz0r");
// 使用从属性类继承的序列化能力对马赛克滤镜的宽高属性进行设置
filter->set(qUtf8Printable("0"), 0.000); // width不做变化
filter->set(qUtf8Printable("1"), 0.300); // height做变化
// 使用从父类Service中继承的订阅能力添加滤镜
producer.attach(*filter);
Demon display
Modify the Filter (mosaic) effect
- The filter is only set to width
- The filter is only set for height
code
Profile profile; // defaults to dv_pal
Producer producer(profile, filename);
Consumer consumer(profile); // defaults to sdl
Mlt::Filter *filter = new Mlt::Filter(profile, "frei0r.pixeliz0r");
filter->set(qUtf8Printable("0"), 0.300);
filter->set(qUtf8Printable("1"), 0.300);
producer.attach(*filter);
// Prevent scaling to the profile size.
// Let the sdl consumer do all scaling.
consumer.set("rescale", "none");
// Automatically exit at end of file.
consumer.set("terminate_on_pause", 1);
consumer.connect(producer);
consumer.run();
consumer.stop();
Affiliate code download link
References
[1] MLT github link