Feature: add level of ffmpeg log

pull/221/head
xufuji456 2 years ago
parent fac7760eec
commit 3903f821da
  1. 16
      app/src/main/cpp/ffmpeg_cmd.c
  2. 2
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java

@ -3,10 +3,10 @@
#include "ffmpeg_jni_define.h"
#define FFMPEG_TAG "FFmpegCmd"
#define INPUT_SIZE (4 * 1024)
#define INPUT_SIZE (8 * 1024)
#define ALOGI(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_INFO, TAG, FORMAT, ##__VA_ARGS__);
#define ALOGE(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_ERROR, TAG, FORMAT, ##__VA_ARGS__);
#define ALOGI(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_INFO, TAG, FORMAT, ##__VA_ARGS__)
#define ALOGE(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_ERROR, TAG, FORMAT, ##__VA_ARGS__)
int err_count;
JNIEnv *ff_env;
@ -21,7 +21,7 @@ void init(JNIEnv *env) {
err_count = 0;
ff_class = (*env)->FindClass(env, "com/frank/ffmpeg/FFmpegCmd");
ff_method = (*env)->GetStaticMethodID(env, ff_class, "onProgressCallback", "(III)V");
msg_method = (*env)->GetStaticMethodID(env, ff_class, "onMsgCallback", "(Ljava/lang/String;)V");
msg_method = (*env)->GetStaticMethodID(env, ff_class, "onMsgCallback", "(Ljava/lang/String;I)V");
}
FFMPEG_FUNC(jint, handle, jobjectArray commands) {
@ -56,12 +56,12 @@ FFMPEG_FUNC(void, cancelTaskJni, jint cancel) {
cancel_task(cancel);
}
void msg_callback(const char *format, va_list args) {
void msg_callback(const char *format, va_list args, int level) {
if (ff_env && msg_method) {
char *ff_msg = (char *) malloc(sizeof(char) * INPUT_SIZE);
vsprintf(ff_msg, format, args);
jstring jstr = (*ff_env)->NewStringUTF(ff_env, ff_msg);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr);
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, msg_method, jstr, level);
free(ff_msg);
}
}
@ -71,14 +71,14 @@ void log_callback(void *ptr, int level, const char *format, va_list args) {
case AV_LOG_INFO:
ALOGI(FFMPEG_TAG, format, args);
if (format && strncmp("silence", format, 7) == 0) {
msg_callback(format, args);
msg_callback(format, args, 3);
}
break;
case AV_LOG_ERROR:
ALOGE(FFMPEG_TAG, format, args);
if (err_count < 10) {
err_count++;
msg_callback(format, args);
msg_callback(format, args, 6);
}
break;
default:

@ -160,7 +160,7 @@ public class FFmpegCmd {
}
}
public static void onMsgCallback(String msg) {
public static void onMsgCallback(String msg, int level) {
if (msg != null && !msg.isEmpty()) {
Log.e(TAG, "from native msg=" + msg);

Loading…
Cancel
Save