c++ - 如何将 libavformat 控制台输出引导到自定义记录器?

标签 c++ logging ffmpeg console libavformat

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/

相关文章:

c++ - 用户定义类的输入流

spring - Spring项目中如何添加 Sentry 监控

laravel - 使用在mac中工作的ffmpeg命令向视频添加文本但在ubuntu中出错?

android - 我可以在 Android 应用程序中使用 FFmpeg 的库吗?

c++ - 为什么 Clang 优化这段代码?

c++ - 错误 : overflow in implicit constant conversion [-Werror=overflow]

c++ - 使用多态时如何避免向下转换?

python - 父进程和子进程都可以访问记录器吗?

python - Django 日志记录 : Cannot create logs per day

c++ - 将 FFmpeg 与 Direct Show 结合使用