libavfromat 中是否有任何机制可以将其控制台输出重定向到自定义日志系统?
例如。我想用我的自定义记录器打印 av_dump_format 的输出。
最佳答案
FFmpeg 将日志输出打印到 stderr,并且由于 stderr 是一个 FILE,您可以打开一个管道并读取它。像这样的东西:
// 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;
}
关于c++ - 如何将 libavformat 控制台输出引导到自定义记录器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61162230/