【问题标题】:How to channel libavformat console output to custom logger?如何将 libavformat 控制台输出引导到自定义记录器?
【发布时间】:2020-07-24 11:56:21
【问题描述】:

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

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

【问题讨论】:

  • @JesperJuhl 我不确定如何为此制定搜索查询。我认为您的批评是不合理的 - 即使有问题的主题在文档中进行了详细描述,我仍然认为在 stackoverflow 上对这个问题有一个正确的答案是有用的,原因有很多: - 谷歌很可能会给你参考 stackoverflow比 libavformat 文档 - 如何制定搜索查询(我的情况)并不总是很明显 - 在堆栈溢出时存在有关某些内容的信息使其对新人更具吸引力

标签: c++ logging ffmpeg console libavformat


【解决方案1】:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多