如何将 libavformat 控制台输出传输到自定义记录器?

问题描述 投票:0回答:2

libavfromat 中是否有任何机制可以将其控制台输出重定向到自定义日志系统?

例如我想用我的自定义记录器打印 av_dump_format 的输出。

c++ logging ffmpeg console libavformat
2个回答
0
投票

参见:https://ffmpeg.org/doxygen/6.0/group__lavu__log.html#ga14034761faf581a8b9ed6ef19b313708

static void callback(void * avcl, int level, const char * fmt, va_list va)
{
}

av_log_set_callback(callback);

-1
投票

FFmpeg 将日志输出打印到 stderr,并且由于 stderr 是一个文件,因此您可以打开一个管道并读取它。像这样的东西:

// Input and output pipe
int pipes[2];
pipe(pipes);
dup2(pipes[1], STDERR_FILENO);
// Close the output pipe, we're not writing to it
close(pipes[1]);
// Open the input pipe so we can read from it
FILE* inputFile = fdopen(pipes[0], "r");
char readBuffer[256];

// Create a new thread and do this
while (1) {
    fgets(readBuffer, sizeof(readBuffer), inputFile);

    // Do whatever you want with readBuffer here
    std::cout << readBuffer << std::endl;
}
© www.soinside.com 2019 - 2024. All rights reserved.