You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用C++20编译mlt++示例程序出现Segmentation fault问题求助

MLT++ C++20示例运行段错误问题排查

问题概述

使用C20编译MLT官方的Playlist示例及基础Consumer+Producer示例,编译成功,但执行./program file1 file2 ...时触发Segmentation fault (core dumped),通过lldb调试定位到错误发生在c.connect(p);语句。

调试详情

* thread #1, name = 'SimplePodcastMa', stop reason = signal SIGSEGV: address not mapped to object (fault address: 0x38)
    frame #0: 0x00007ffff7bc0ec0 libmlt-7.so.7`mlt_service_connect_producer + 34
libmlt-7.so.7`mlt_service_connect_producer:
->  0x7ffff7bc0ec0 <+34>: movq   0x38(%rax), %rax
    0x7ffff7bc0ec4 <+38>: movq   %rax, -0x10(%rbp)
    0x7ffff7bc0ec8 <+42>: cmpl   $-0x1, -0x34(%rbp)
    0x7ffff7bc0ecc <+46>: jne    0x7ffff7bc0ed5 ; <+55>
(lldb) up
frame #1: 0x00007ffff7f8fc00 libmlt++-7.so.7`Mlt::Service::connect_producer(Mlt::Service&, int) + 92
libmlt++-7.so.7`Mlt::Service::connect_producer:
->  0x7ffff7f8fc00 <+92>: movq   -0x8(%rbp), %rbx
    0x7ffff7f8fc04 <+96>: leave
    0x7ffff7f8fc05 <+97>: retq

libmlt++-7.so.7`Mlt::Service::insert_producer:
    0x7ffff7f8fc06 <+0>:  endbr64
(lldb) up
frame #2: 0x00007ffff7f85cf6 libmlt++-7.so.7`Mlt::Consumer::connect(Mlt::Service&) + 44
libmlt++-7.so.7`Mlt::Consumer::connect:
->  0x7ffff7f85cf6 <+44>: leave
    0x7ffff7f85cf7 <+45>: retq

libmlt++-7.so.7`Mlt::Consumer::start:
    0x7ffff7f85cf8 <+0>:  endbr64
    0x7ffff7f85cfc <+4>:  pushq  %rbp
(lldb) up
frame #3: 0x0000555555555634 SimplePodcastMaker`main(argc=1, argv=0x00007fffffffdc78) at main.cpp:47:14
   44       Profile profile;
   45       Producer p( profile, "pango:", "Hello World" );
   46       Consumer c( profile, "sdl" );
-> 47       c.connect( p );
   48       c.run( );
   49       return 0;
   50   }

复现代码

#include <mlt++/Mlt.h>

using namespace std;
using namespace Mlt;

int main(int argc, char **argv)
{
    Factory::init( );
    Profile profile;
    Producer p( profile, "pango:", "Hello World" );
    Consumer c( profile, "sdl" );
    c.connect( p );
    c.run( );
    return 0;
}

解决建议

  • 检查对象有效性:MLT对象创建失败时会持有空内部句柄,后续操作会触发段错误。添加有效性检查:
    if (!p.is_valid() || !c.is_valid()) {
        cerr << "Producer或Consumer创建失败" << endl;
        return 1;
    }
    
  • 确保Profile初始化正确:默认构造的Profile可能未加载有效配置,尝试使用内置预设或指定配置文件:
    Profile profile("hd720"); // 使用720p预设
    
  • 验证C++标准兼容性:C20的ABI可能与MLT库编译时的标准不匹配,尝试降级到C17编译,或确认MLT库是用C20编译的。
  • 检查依赖库完整性:SDL Consumer需要正确安装SDL库,确保运行时能找到libsdl2.so等动态库。
  • 排查Pango producer问题:尝试替换Pango producer为本地视频文件,比如Producer p(profile, "test.mp4");,确认是否是Pango模块的问题。

内容的提问来源于stack exchange,提问作者Aitor Gomila

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 01:16:08