1. ffmpeg 日志系统
ffmpeg libavutil 模块提供了日志功能,提供了日志等级,日志回调,日志打印等接口
main.cpp
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#define __STDC_CONSTANT_MACROS #pragma comment(lib, "avutil.lib") #pragma comment(lib, "avcodec.lib") #pragma comment(lib, "avdevice.lib") #pragma comment(lib, "avfilter.lib") #pragma comment(lib, "avformat.lib") #pragma comment(lib, "swresample.lib") #pragma comment(lib, "swscale.lib") extern "C"{ #include "libavutil/log.h" #include "zlog.h" #include <stdio.h> } // 日志 int log_test() { av_log_set_level(AV_LOG_DEBUG); // 设置日志级别 //av_log_set_callback(log_callback); ZLOG_DEBUG("ffmpeg log test : %d", 111); ZLOG_INFO("ffmpeg log test : %d", 111); ZLOG_WARNING("ffmpeg log test : %d", 111); ZLOG_ERROR("ffmpeg log test : %d", 111); return 0; } int main(int argc, char* argv[]) { log_test(); return 0; }
zlog.h的封装,封装一下日志宏,添加一些常用的日志信息
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58#ifndef __ZLOG_H__ #define __ZLOG_H__ #include <time.h> #ifdef __cplusplus //告诉编译器,这部分代码按C语言的格式进行编译,而不是C++的 extern "C"{ #endif #include "libavutil/log.h" inline const char* level_to_str(int level) { if (level == AV_LOG_DEBUG) return "D"; else if (level == AV_LOG_INFO) return "I"; else if (level == AV_LOG_WARNING) return "W"; else if (level == AV_LOG_ERROR) return "E"; else return "U"; } inline void zlog_format(int level, const char* file, int line, const char* format, ...) { time_t loacl_time; char time_str[128]; // 获取本地时间 time(&loacl_time); tm t; localtime_s(&t, &loacl_time); strftime(time_str, sizeof(time_str), "%Y.%m.%d %X", &t); va_list ap; va_start(ap, format); char fmt_str[2048]; vsnprintf_s(fmt_str, sizeof(fmt_str), format, ap); va_end(ap); av_log(NULL, level, "[%s] [%s] %s:%d %sn", level_to_str(level), time_str, file, line, fmt_str); } #define ZLOG_DEBUG(format, ...) zlog_format(AV_LOG_DEBUG, __FILE__, __LINE__, format, ##__VA_ARGS__); #define ZLOG_INFO(format, ...) zlog_format(AV_LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__); #define ZLOG_WARNING(format, ...) zlog_format(AV_LOG_WARNING, __FILE__, __LINE__, format, ##__VA_ARGS__); #define ZLOG_ERROR(format, ...) zlog_format(AV_LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__); #ifdef __cplusplus } #endif #endif
这里没有写日志文件,暂时只做学习用
最后
以上就是义气面包最近收集整理的关于ffmpeg 学习笔记 日志的简单封装的全部内容,更多相关ffmpeg内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复