Audio and video learning introduction technology article serial:
- Technology development stories will be serialized
- SDL Introduction and engineering configuration
- SDL Creates Windows and displays colors
- SDL Message Loop and Event Response
- SDL loads pictures and displays them
- SDL load YUV file and display
- SDL Play YUV video files
- 【 audio and Video serial-007 】 basic Learning chapter -SDL Play PCM audio file (1)
- 【 audio and Video serial-008 】 basic Learning -SDL Play PCM audio files (下)
- [Audio and Video serial-009] Season 2 FFmpeg build simple player
Audio and video serialized series has been stopped for some time, it is estimated that it will lose fans again, pick up and continue to update ~~~
The rest of the article will focus on FFmpeg. For example, this article will start with simple log printing.
Log printing basic use
The av_log() method is provided in FFmpeg to print the log. It is declared as follows:
void av_log(void *avcl, int level, const char *fmt, ...)
Copy the code
Where the level parameter refers to the log level, FMT and… Represents the log content, just like calling print to print information.
Specific use is as follows:
av_log(nullptr,AV_LOG_INFO,"this is INFO log color");
av_log(nullptr,AV_LOG_DEBUG,"this is DEBUG log color");
av_log(nullptr,AV_LOG_WARNING,"this is WARNING log color");
av_log(nullptr,AV_LOG_ERROR,"this is ERROR log color");
Copy the code
Like Android logging, FFmpeg has multiple levels of logging.
#define AV_LOG_FATAL 8
#define AV_LOG_ERROR 16
#define AV_LOG_WARNING 24
#define AV_LOG_INFO 32
#define AV_LOG_VERBOSE 40
#define AV_LOG_DEBUG 48
#define AV_LOG_TRACE 56
Copy the code
Look at the INFO, DEBUG, and ERROR levels and you’ll feel deja vu.
These values are multiples of 8, increasing from smallest to largest.
Set the log printing level
The current log printing level can be set and obtained in FFmpeg.
// Set the log printing level
void av_log_set_level(int level);
// Get the log printing level
int av_log_get_level(void);
Copy the code
For example, if you set the current level to AV_LOG_INFO, anything below that level will not be printed.
So what is a lower level? A smaller number indicates a higher level, and a larger number indicates a lower level.
For example, if the AV_LOG_INFO level is set to 32, logs at the AV_LOG_DEBUG level will not be printed, which has a lower level of 48. AV_LOG_ERROR is printed and has a value of 16, which is a higher level.
Custom log printing
In FFmpeg, you can register a log callback with the av_log_set_callback function, in which you can customize the log printing method.
The av_log_set_callback function is declared as follows:
void av_log_set_callback(void (*callback)(void*, int level, const char* fmt, va_list));
Copy the code
Level specifies the level of the log callback. FMT and va_list are the contents of the log callback.
Here is how to do it:
static void log_callback(void *ptr, int level, const char *fmt, va_list vaList) {
switch (level) {
case AV_LOG_DEBUG:
logD(fmt, vaList);
break;
case AV_LOG_VERBOSE:
logV(LOG_MAGENTA, fmt, vaList);
break;
case AV_LOG_INFO:
logI(fmt, vaList);
break;
case AV_LOG_WARNING:
logW(fmt, vaList);
break;
case AV_LOG_ERROR:
logE(fmt, vaList);
break;
default:
log(fmt, vaList);
break; }}Copy the code
Do log level distribution on switch, the specific printing method is taught macro defined function.
The color of log output is adjusted according to different levels, as shown in the following figure:
Note that if custom log printing is registered, some of the log information inside FFmpeg will also be printed by custom methods, in addition to the logs we will print by calling the av_log method.
Customize the log printing color
In general, log printing is defined through macro functions.
#define logD(format,...) \
logging(LOG_GREEN,format,##__VA_ARGS__)
Copy the code
Where ##__VA_ARGS__ means variable argument macro, corresponding to the function inside the three point variable argument… .
The specific function is as follows:
static void logging(const char * color ,const char *fmt, va_list vaList)
{
// Set the log print color
printf("%s [av-beginner]: ",color);
// Print the content
vprintf( fmt, vaList );
// End log color setting
printf(LOG_NONE "\n" );
}
static void logging(const char * color ,const char *fmt, ...)
{
va_list vaList;
va_start( vaList, fmt );
logging(color,fmt,vaList);
va_end(vaList);
}
Copy the code
This involves variable parameters and log color printing. Expand on log color printing.
The color of a character in a terminal is controlled by an escape sequence, such as a line break in a terminal, which is the \n operation. The same is true for color control.
The specific display format is as follows:
\033[Display mode; foreground color; background color m Output string \033[0m
or
\e[Display mode; foreground color; background color m Output string \e[0m
When calling the print function to print information, do as follows:
// Prints the log content in red
printf("\033[0;31m print red color log \033[0m\n");Copy the code
The above can print the red log information, the specific content about display mode, foreground color, background color, etc., will be covered in the following article.
conclusion
The above is the audio and video basic learning serialized 010.
Simple explanation of FFmpeg log printing content, this article specific code see the warehouse:
Github.com/glumes/av-b…
The repository code will be updated earlier than this article. To get a head start on what’s next, follow the code. Welcome star.
Limited, please add the wechat ezglumes if there are any misunderstandings