From 52d648811e60223a454cf2612e824ddd6a88cdee Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Thu, 7 May 2020 01:33:30 +0800 Subject: [PATCH] handle multi command handle multi command --- .../main/java/com/frank/ffmpeg/FFmpegCmd.java | 30 +++++++++++++++++++ .../frank/ffmpeg/handler/FFmpegHandler.java | 30 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java b/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java index bfd7b65..4bcfd42 100644 --- a/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java +++ b/app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java @@ -1,9 +1,12 @@ package com.frank.ffmpeg; import android.text.TextUtils; +import android.util.Log; import com.frank.ffmpeg.listener.OnHandleListener; +import java.util.List; + /** * The JNI interface of handling FFmpeg command * Created by frank on 2018/1/23 @@ -39,6 +42,33 @@ public class FFmpegCmd { }).start(); } + /** + * Execute FFmpeg multi commands + * @param commands the String array of command + * @param onHandleListener the callback for executing command + */ + public static void execute(final List commands, final OnHandleListener onHandleListener) { + new Thread(new Runnable() { + @Override + public void run() { + if (onHandleListener != null) { + onHandleListener.onBegin(); + } + //call JNI interface to execute FFmpeg cmd + int result = 0; + int count = 0; + for (String[] command : commands) { + result = handle(command); + count ++; + Log.i("FFmpegCmd", count + " result=" + result); + } + if (onHandleListener != null) { + onHandleListener.onEnd(result, null); + } + } + }).start(); + } + /** * Using FastStart to moov box in front of mdat box * diff --git a/app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java b/app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java index 3d55560..0e185a2 100644 --- a/app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java +++ b/app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java @@ -8,6 +8,8 @@ import com.frank.ffmpeg.listener.OnHandleListener; import com.frank.ffmpeg.model.MediaBean; import com.frank.ffmpeg.tool.JsonParseTool; +import java.util.List; + /** * Handler of FFmpeg and FFprobe * Created by frank on 2019/11/11. @@ -64,6 +66,34 @@ public class FFmpegHandler { }); } + /** + * execute multi commands of FFmpeg + * + * @param commandList the list of command + */ + public void executeFFmpegCmds(final List commandList) { + if (commandList == null) { + return; + } + FFmpegCmd.execute(commandList, new OnHandleListener() { + @Override + public void onBegin() { + Log.i(TAG, "handle onBegin..."); + mHandler.obtainMessage(MSG_BEGIN).sendToTarget(); + } + + @Override + public void onEnd(int resultCode, String resultMsg) { + Log.i(TAG, "handle onEnd..."); + if (isContinue) { + mHandler.obtainMessage(MSG_CONTINUE).sendToTarget(); + } else { + mHandler.obtainMessage(MSG_FINISH).sendToTarget(); + } + } + }); + } + /** * execute the command of FFprobe *