android - 如何在 android logcat 中看到 var_dump 格式的打印消息

标签 android ffmpeg logcat

我只是想知道...
如何在 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使用特定的方法签名
  • 为您的 native 类提供函数
    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/

    相关文章:

    python - 命名文件输出moviepy ffmpeg

    java - Android Studio 应用向用户显示错误消息

    java - android admob真实广告无法加载代码为0的广告请求 - ERROR_CODE_INTERNAL_ERROR

    ffmpeg - ffmpeg 5.0 与 ffmpeg 4.1.1 的 Concat 失败

    ios - 当 audioqueue 播放从 ffmpeg 解码的 lpcm 时,音频队列的耗时超过了媒体的持续时间

    android - 有人知道这个Android类的功能吗? "com.google.apps.tiktok.tracing.db"?

    android - 如何在特定模块的 logcat 中获取详细日志记录

    android - 在 JNI Android 中写入标准输出?没有 <android/log.h>

    android - sqlite 数据库 hardcode/data/db_path android

    android - NFC读卡器获取错误android