calculate progress and callback

calculate progress and callback
pull/166/head
xufulong 5 years ago
parent ac4819648c
commit 719fe8e564
  1. 8
      app/src/main/cpp/ffmpeg/ffmpeg.c
  2. 9
      app/src/main/cpp/ffmpeg/ffmpeg.h
  3. 17
      app/src/main/cpp/ffmpeg_cmd.c
  4. 4
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java

@ -1849,6 +1849,13 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
} }
} }
int64_t report_position = FFABS(pts) / AV_TIME_BASE;
int64_t report_duration = 0;
if(input_files) {
report_duration = input_files[0]->ctx->duration / AV_TIME_BASE;
}
progress_callback((int) report_position, (int) report_duration, STATE_RUNNING);
if (is_last_report) if (is_last_report)
print_final_stats(total_size); print_final_stats(total_size);
} }
@ -4929,6 +4936,7 @@ int run(int argc, char **argv)
// exit_program(received_nb_signals ? 255 : main_return_code); // exit_program(received_nb_signals ? 255 : main_return_code);
end: end:
av_log(NULL, AV_LOG_INFO, "FFmpeg result=%d\n", main_return_code); av_log(NULL, AV_LOG_INFO, "FFmpeg result=%d\n", main_return_code);
progress_callback(100, 100, main_return_code == 0 ? STATE_FINISH : STATE_ERROR);
ffmpeg_cleanup(0); ffmpeg_cleanup(0);
return main_return_code; return main_return_code;
} }

@ -667,4 +667,13 @@ int hwaccel_decode_init(AVCodecContext *avctx);
int run(int argc, char **argv); int run(int argc, char **argv);
enum ProgressState {
STATE_INIT,
STATE_RUNNING,
STATE_FINISH,
STATE_ERROR,
};
void progress_callback(int position, int duration, int state);
#endif /* FFTOOLS_FFMPEG_H */ #endif /* FFTOOLS_FFMPEG_H */

@ -9,9 +9,20 @@
#define ALOGW(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_WARN, TAG, FORMAT, ##__VA_ARGS__); #define ALOGW(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_WARN, TAG, FORMAT, ##__VA_ARGS__);
#define ALOGD(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_DEBUG, TAG, FORMAT, ##__VA_ARGS__); #define ALOGD(TAG, FORMAT, ...) __android_log_vprint(ANDROID_LOG_DEBUG, TAG, FORMAT, ##__VA_ARGS__);
JNIEnv *ff_env;
jclass ff_class;
jmethodID ff_method;
void log_callback(void*, int, const char*, va_list); void log_callback(void*, int, const char*, va_list);
void init(JNIEnv *env) {
ff_env = env;
ff_class = (*env)->FindClass(env, "com/frank/ffmpeg/FFmpegCmd");
ff_method = (*env)->GetStaticMethodID(env, ff_class, "onProgressCallback", "(III)V");
}
FFMPEG_FUNC(jint, handle, jobjectArray commands) { FFMPEG_FUNC(jint, handle, jobjectArray commands) {
init(env);
// set the level of log // set the level of log
av_log_set_level(AV_LOG_INFO); av_log_set_level(AV_LOG_INFO);
// set the callback of log, and redirect to print android log // set the callback of log, and redirect to print android log
@ -57,3 +68,9 @@ void log_callback(void* ptr, int level, const char* format, va_list args) {
break; break;
} }
} }
void progress_callback(int position, int duration, int state) {
if (ff_env && ff_class && ff_method) {
(*ff_env)->CallStaticVoidMethod(ff_env, ff_class, ff_method, position, duration, state);
}
}

@ -122,4 +122,8 @@ public class FFmpegCmd {
private native static String handleProbe(String[] commands); private native static String handleProbe(String[] commands);
public static void onProgressCallback(int position, int duration, int state) {
Log.e("FFmpegCmd", "onProgress position=" + position + "--duration=" + duration);
}
} }
Loading…
Cancel
Save