How to disable libavformat error messages

By default, libavformat writes error messages to stderr , Like:

Estimating duration from bitrate, this may be inaccurate

How can i turn it off? or better yet, plug it into my own neat logging function?

Edit: Redirecting stderr to another location is unacceptable since I need it for other logging purposes, I just want libavformat not to write to it.

+8
c ffmpeg libav libavcodec libavformat
source share
3 answers

av_log code, you can change the behavior by writing your own callback function for the av_log function.

From the description of this function in libavutil / log.h :

Send the specified message to the log if the level is less than or equal to the current level av_log_level. By default, all log messages are sent to STDERR. This behavior can be changed by setting another callback to the av_vlog function.

The API provides a function that allows you to define your own callback:

 void av_log_set_callback(void (*)(void*, int, const char*, va_list)); 

In your case, you can write a simple callback function that completely discards messages (or redirects them to a dedicated log, etc.) without spoiling the stderr stream.

+7
source share

Give av_log_set_level(level) try!

+5
source share

You can redirect them to a user file, redirect all cerr entries :

 #include <iostream> #include <fstream> using namespace std; int main() { ofstream file("file.txt"); streambuf *old_cerr = cerr.rdbuf(); cerr.rdbuf (file.rdbuf()); cerr << "test test test" << endl; // writes to file.txt // ... cerr.rdbuf (old_cerr); // restore orginal cerr return 0; } 

Edit: After editing the question, I warn that the code above will be redirected to the entire cerr stream to file.txt

I am not familiar with libavformat, but if its code is immutable, you can temporarily redirect cerr to a file before calling the api library and redirect it to the original cerr (however this is ugly) / p>

+1
source share

All Articles