libavfromat 中是否有任何机制可以将其控制台输出重定向到自定义日志系统?
例如我想用我的自定义记录器打印 av_dump_format 的输出。
参见: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);
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;
}