[MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (3)

premise

  1. By reading [MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (1), the following two points are satisfied:
    1. Understand the hierarchical relationship of MLT's core C++ packaging
    2. Master using MLT's Consumer (sdl) to consume Producer (MP4)
  2. By reading [MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (2), the following two points are satisfied:
    1. Understand Service (service abstract base class) and Filter (filter abstract service class)
    2. 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:
insert image description here

Core class analysis

Properties

insert image description here

[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

  1. The filter is only set to width
    Please add image description
  2. The filter is only set for height
    Please add image description

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

Source code download link

References

[1] MLT github link

Guess you like

Origin blog.csdn.net/MichaelKongChina/article/details/126307431