我只是想知道...
如何在 android logcat 中看到 var_dump 格式的打印消息?
最佳答案
首先,您需要在您的Android.mk
中启用日志。或 CMakeLists.txt
文件
如果您使用的是 NDK 构建,则添加
LOCAL_LDLIBS := -llog
给您的
Android.mk
文件。或者
如果您使用的是 CMake 构建,则首先使用
find_library( # Defines the name of the path variable that stores the
# location of the NDK library.
log_lib
# Specifies the name of the NDK library that
# CMake needs to locate.
log )
然后像这样将日志库链接到您的目标库
target_link_libraries( # Specifies the target library.
YOUR_LIB_NAME
# Links the log library to the target library.
${log_lib} )
完成将日志库链接到 native 构建后,请执行以下操作。
#include "android/log.h"
在文件的顶部。 #define print_log(LOG_LEVEL, TAG, ...) __android_log_print(LOG_LEVEL, TAG, __VA_ARGS__)
Callback
使用特定的方法签名 static void callback(void *ptr, int level, const char *fmt, va_list vl)
{
if (level > av_log_get_level())
return;
va_list vl2;
char line[1024];
static int print_prefix = 1;
va_copy(vl2, vl);
av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
va_end(vl2);
print_log(ANDROID_LOG_INFO, "FFMPEG", "%s", line);
}
av_log_set_level(32);
av_log_set_callback(callback);
设置日志回调您可以从级别决定是否要将日志打印为
INFO, ERROR, WARNING or VERVOSE
来自 level
.构建 应用程序和 运行命令
ffmpeg -hide_banner -i /storage/emulated/0/input.mp4
您应该在 logcat 中看到类似的内容。
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/input.mp4':
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: Metadata:
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: major_brand :
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: isom
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: minor_version :
2020-04-03 11:41:49.154 25142-25259/com.example.ffmpeg I/FFMPEG: 512
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: compatible_brands:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: isomiso2avc1mp41
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: encoder :
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Lavf57.83.100
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Duration:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 00:00:58.10
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: , start:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 0.000000
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: , bitrate:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 3716 kb/s
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Stream #0:0
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: (und)
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: : Video: h264 (avc1 / 0x31637661), yuv420p, 1080x1350, 3588 kb/s
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: ,
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 29.99 fps,
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 29.97 tbr,
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 1000k tbn,
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: 2000k tbc
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: (default)
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Metadata:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: handler_name :
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: VideoHandler
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Stream #0:1
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: (und)
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: : Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 124 kb/s
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: (default)
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: Metadata:
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: handler_name :
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: SoundHandler
2020-04-03 11:41:49.155 25142-25259/com.example.ffmpeg I/FFMPEG: At least one output file must be specified
2020-04
关于android - 如何在 android logcat 中看到 var_dump 格式的打印消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60619580/