Audio and video development six: FFmpeg log usage

Common log levels

In FFmpeg, error, warning, info, verboseand debugrefer to different log levels, each corresponding to a different type of log information. The specific explanation is as follows:

  • error: Output an error message, indicating that an unrecoverable error has occurred in the program, and execution needs to be stopped immediately.
  • warning: Output a warning message, indicating that an error may occur in the program, but it does not affect the overall execution of the program.
  • info: Output general information, showing that the program is running normally, not too detailed.
  • verbose: Output detailed information for debugging and optimizing the program, which can help understand the internal operation of the program.
  • debug: Output debugging information, including detailed running information inside the program, for in-depth analysis of problems that occur during the running of the program.

API

AV_LOG_SET_LEVEL

AV_LOG_SET_LEVELIt is a macro definition in FFmpeg, which is used to set the log level of FFmpeg . Its syntax is:

AV_LOG_SET_LEVEL(int level)

Where levelis the log level, its value ranges from 0 to 47, and the corresponding log levels range from panic to trace. Through this macro definition, the log level of FFmpeg can be adjusted dynamically to facilitate debugging and program optimization.

For example, the following code sets FFmpeg's log level to debug:

av_log_set_level(AV_LOG_DEBUG);

av_logIt is a function to output log information in FFmpeg, which can output log information of different levels. Its function prototype is as follows:

of_log

void av_log(void *avcl, int level, const char *fmt, ...)
  • avcl: Point to the context of the output log, which can be any type of pointer, and can generally be passed in NULL.
  • level: Indicates the level of the output log, the possible values ​​are: AV_LOG_FATAL, AV_LOG_ERROR, AV_LOG_WARNING, AV_LOG_INFO, AV_LOG_VERBOSE, AV_LOG_DEBUGand AV_LOG_TRACE, the level gradually increases, and the detail of the output information also gradually increases.
  • fmt: Formatted string for output, similar to printfthe function.
  • ...: A variable parameter list, which is a variable that outputs strings, similar to printfa function.

Use av_logthe function to output log information to control the level and output format of the log. You can output different levels of log information in different situations. The log category can print the information above it and print the information below the level. For example, if error is set, information at log levels above error and above can be printed, and information below error, such as debug, will not be printed. .

code display

Show log usage


#include <libavutil/log.h>

int main() {
    
    

    av_log_set_level(AV_LOG_ERROR);
    av_log(NULL,AV_LOG_ERROR, "print string %s, print num %d", "hhhh", 3.1415926);
    av_log(NULL,AV_LOG_DEBUG, "print string %s, print num %d", "heihei", 1024);

	return 0;
}



Only one line of log is printed

Guess you like

Origin blog.csdn.net/qq_38056514/article/details/130190749