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, pipe it to my own neat logging function?
Edit: Redirecting stderr to somewhere else is not acceptable since I need it for other logging purposes, I just want libavformat to not write to it.
include this header file
add this code will disable the log
Give
av_log_set_level(level)
a try!You can redirect them to a custom file, it will redirect all cerr entry:
Edit: After editing the question, i warn about above code that it will redirect all
cerr
entry stream tofile.txt
I'm not familiar with libavformat, but if its code is unchangeable, you can temporary redirect
cerr
to a file before calling library's api and redirect it to originalcerr
again.(However this is ugly way)Looking through the code, it appears 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:
The API provides a function that will allow you to define your own callback:
In your case, you could write a simple callback function that discards the messages altogether (or redirects them to a dedicated log, etc.) without tainting your
stderr
stream.