diff --git a/app/src/main/cpp/ffmpeg/ffmpeg.c b/app/src/main/cpp/ffmpeg/ffmpeg.c index c49b1d6..1ab4b35 100644 --- a/app/src/main/cpp/ffmpeg/ffmpeg.c +++ b/app/src/main/cpp/ffmpeg/ffmpeg.c @@ -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) print_final_stats(total_size); } @@ -4929,6 +4936,7 @@ int run(int argc, char **argv) // exit_program(received_nb_signals ? 255 : main_return_code); end: 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); return main_return_code; } diff --git a/app/src/main/cpp/ffmpeg/ffmpeg.h b/app/src/main/cpp/ffmpeg/ffmpeg.h index e376704..5204ea3 100644 --- a/app/src/main/cpp/ffmpeg/ffmpeg.h +++ b/app/src/main/cpp/ffmpeg/ffmpeg.h @@ -667,4 +667,13 @@ int hwaccel_decode_init(AVCodecContext *avctx); 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 */ diff --git a/app/src/main/cpp/ffmpeg_cmd.c b/app/src/main/cpp/ffmpeg_cmd.c index ed6548c..7ae7d8d 100644 --- a/app/src/main/cpp/ffmpeg_cmd.c +++ b/app/src/main/cpp/ffmpeg_cmd.c @@ -9,9 +9,20 @@ #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__); +JNIEnv *ff_env; +jclass ff_class; +jmethodID ff_method; + 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) { + init(env); // set the level of log av_log_set_level(AV_LOG_INFO); // set the callback of log, and redirect to print android log @@ -56,4 +67,10 @@ void log_callback(void* ptr, int level, const char* format, va_list args) { ALOGI(FFMPEG_TAG, format, args); 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); + } } \ No newline at end of file diff --git a/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java b/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java index 38a5854..9bdb5bc 100644 --- a/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java +++ b/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java @@ -122,4 +122,8 @@ public class FFmpegCmd { 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); + + } } \ No newline at end of file