您如何在 android logcat 中看到 av_dump_format 打印消息

how can you see av_dump_format print messsage in android logcat

我只是想知道...

如何在 android logcat 中看到 av_dump_format 打印消息?

首先,您需要在 Android.mkCMakeLists.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 )

然后link像这样将日志库添加到你的目标库

target_link_libraries( # Specifies the target library.
                       YOUR_LIB_NAME

                       # Links the log library to the target library.
                       ${log_lib} )

完成 link 将日志库添加到您的本机构建后,请执行以下操作。

  • 在文件顶部添加 #include "android/log.h"
  • 定义一个宏来打印这样的日志

#define print_log(LOG_LEVEL, TAG, ...) __android_log_print(LOG_LEVEL, TAG, __VA_ARGS__)

  • 使用特定的方法签名
  • 为您的原生 class 创建一个 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);设置日志回调

您可以从级别决定是否要从 level.

打印日志为 INFO, ERROR, WARNING or VERVOSE

构建 应用程序和运行 命令

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