MLT官方有为MLT库提供C++包装,根据MLT的设计梳理了核心类的层级关系,如下图:

如上图可见:整个封装分为4个层级,简单介绍一下关键类的功能:
生产消费基础流程图如下:

// 默认视频图像制式设置是dv_pal(PAL特点:每秒钟有25帧,奇数场,主要应用在中国、香港、中东地区和欧洲一带,视频输出常用格式是PAL制式)
Profile profile;
// 根据profile配置与媒体资源初始化生产者
Producer producer(profile, filename);
// 默认初始化为sdl
Consumer consumer(profile);
// 防止缩小到 profile 配置的尺寸.
// 让 sdl consumer 做所有的缩放.
consumer.set("rescale", "none");
// 在文件结束时自动退出.
consumer.set("terminate_on_pause", 1);
// 从Service继承的关联消费者的能力
consumer.connect(producer);
// 启动
consumer.run();
consumer.stop();

void play(const char *filename)
{
qDebug() << filename;
Profile profile; // defaults to dv_pal
Producer producer(profile, filename);
Consumer consumer(profile); // defaults to sdl
// 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();
}
void func1()
{
Factory::init();
play("D:\\msys64\\home\\Administrator\\mltDemon\\qianyuqianxunKTV.mp4");// 替换自己本地的资源路径
Factory::close();
}
【1】MLT github链接
【2】官方代码示例