ffmpeg windows 调动动态库不容易取错误log的解决办法

本文介绍如何在AV库中通过设置回调函数来记录日志信息,包括默认回调函数的实现和参数解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于不容易跟进DLL去调试,出错信息或警告信号也不容易看到,今天看源代码,其实可以设置一个回调函数,让自己的函数处理这个信息,比如写到文件中,要用的的注册回调函数的函数为:av_log_set_callback,在log.h头文件中有定义,具体参数就是回调函数名,回调函数的定义为:void (*)(void*, int, const char*, va_list);具体参数都是什么意思,我是进源代码看的,里面有一个默认的回调函数,改改就行了

void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{
    static int print_prefix=1;
    static int count;
    static char prev[1024];
    char line[1024];
    static int is_atty;
    AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
    if(level>av_log_level)
        return;
    line[0]=0;
#undef fprintf
    if(print_prefix && avc) {
        if (avc->parent_log_context_offset) {
            AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);
            if(parent && *parent){
                snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent);
            }
        }
        snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);
    }


    vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);


    print_prefix = strlen(line) && line[strlen(line)-1] == '\n';


#if HAVE_ISATTY
    if(!is_atty) is_atty= isatty(2) ? 1 : -1;
#endif


    if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
        count++;
        if(is_atty==1)
            fprintf(stderr, "    Last message repeated %d times\r", count);
        return;
    }
    if(count>0){
        fprintf(stderr, "    Last message repeated %d times\n", count);
        count=0;
    }
    strcpy(prev, line);
    sanitize(line);
    colored_fputs(av_clip(level>>3, 0, 6), line);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值