FFmpeg的日志系统(ubuntu 环境)

1. 新建.c文件

bash 复制代码
vim ffmpeg_log.c

2. 输入文本

bash 复制代码
#include<stdio.h>
#include<libavutil/log.h>
int main()
{
        av_log_set_level(AV_LOG_DEBUG);
        av_log(NULL,AV_LOG_INFO,"hello world");
        return 0;
}

当log level < AV_LOG_DEBUG 都可以印出来

c 复制代码
#define AV_LOG_ERROR    16

/**
 * Something somehow does not look correct. This may or may not
 * lead to problems. An example would be the use of '-vstrict -2'.
 */
#define AV_LOG_WARNING  24

/**
 * Standard information.
 */
#define AV_LOG_INFO     32

/**
 * Detailed information.
 */
#define AV_LOG_VERBOSE  40

/**
 * Stuff which is only useful for libav* developers.
 */
#define AV_LOG_DEBUG    48

/**
 * Extremely verbose debugging, useful for libav* development.
 */
#define AV_LOG_TRACE    56

av_log的实质上是snprintf:

c 复制代码
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[LINE_SZ];
    AVBPrint part[4];
    char line[LINE_SZ];
    static int is_atty;
    int type[2];
    unsigned tint = 0;

    if (level >= 0) {
        tint = level & 0xff00;
        level &= 0xff;
    }

    if (level > av_log_level)
        return;
    ff_mutex_lock(&mutex);

    format_line(ptr, level, fmt, vl, part, &print_prefix, type);
    snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);

3. 编译

bash 复制代码
gcc -g -o ffmpeg_log ffmpeg_log.c -lavutil

但会提示:

bash 复制代码
fmpeg_log.c:2:9: fatal error: libavutil/log.h: 没有那个文件或目录
    2 | #include<libavutil/log.h>
      |         ^~~~~~~~~~~~~~~~~
compilation terminated.

原因是gcc 找不到libavutil,需要在编译前告知编译器libavutil在哪里

bash 复制代码
export PKG_CONFIG_PATH="/home/ffmpeg/lib/pkgconfig"
pkg-config --libs --cflags libavutil

其中pkg-config 就是找libavutil具体位置,-I 是指定头文件,-L是指定库:

bash 复制代码
-I/home/ffmpeg/include -L/home/ffmpeg/lib -lavutil 

4. 修改gcc cmd

bash 复制代码
gcc -g -o ffmpeg_log ffmpeg_log.c -I/home/ffmpeg/include -L/home/ffmpeg/lib -lavutil

or

bash 复制代码
sudo gcc -g -o ffmpeg_log ffmpeg_log.c `pkg-config -cflags --libs  libavutil`

会生成ffmpeg_log文件,执行:

bash 复制代码
$ ./ffmpeg_log 
hello world

5. ldd 查看可执行文件所依赖的库

bash 复制代码
$ ldd ffmpeg_log
	linux-vdso.so.1 (0x00007ffe051fc000)
	libavutil.so.59 => /home/ffmpeg/lib/libavutil.so.59 (0x00007a0937c00000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007a0937800000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007a0938dd4000)
	libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007a0938dbd000)
	/lib64/ld-linux-x86-64.so.2 (0x00007a0938ed6000)
相关推荐
likfishdn几秒前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean20 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=22 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水31 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸1 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
sz66cm2 小时前
Linux基础 -- ARM 32 位架构动态注入代码技术文档
linux·arm开发·架构