handle ffprobe cmd

handle ffprobe cmd
pull/107/head
xufulong 5 years ago
parent 58a8c5c8af
commit db450ae573
  1. 30
      app/src/main/java/com/frank/ffmpeg/FFmpegCmd.java
  2. 29
      app/src/main/java/com/frank/ffmpeg/handler/FFmpegHandler.java
  3. 2
      app/src/main/java/com/frank/ffmpeg/listener/OnHandleListener.java

@ -10,6 +10,10 @@ public class FFmpegCmd {
System.loadLibrary("media-handle");
}
private final static int RESULT_SUCCESS = 1;
private final static int RESULT_ERROR = 0;
//开子线程调用native方法进行音视频处理
public static void execute(final String[] commands, final OnHandleListener onHandleListener){
new Thread(new Runnable() {
@ -21,7 +25,7 @@ public class FFmpegCmd {
//调用ffmpeg进行处理
int result = handle(commands);
if(onHandleListener != null){
onHandleListener.onEnd(result);
onHandleListener.onEnd(result, null);
}
}
}).start();
@ -40,8 +44,32 @@ public class FFmpegCmd {
return fastStart(inputFile, outputFile);
}
/**
* execute probe cmd internal
* @param commands commands
* @param onHandleListener onHandleListener
*/
public static void executeProbe(final String[] commands, final OnHandleListener onHandleListener) {
new Thread(new Runnable() {
@Override
public void run() {
if(onHandleListener != null) {
onHandleListener.onBegin();
}
//execute ffprobe
String result = handleProbe(commands);
int resultCode = !TextUtils.isEmpty(result) ? RESULT_SUCCESS : RESULT_ERROR;
if(onHandleListener != null) {
onHandleListener.onEnd(resultCode, result);
}
}
}).start();
}
private native static int handle(String[] commands);
private native static int fastStart(String inputFile, String outputFile);
private native static String handleProbe(String[] commands);
}

@ -50,7 +50,7 @@ public class FFmpegHandler {
}
@Override
public void onEnd(int result) {
public void onEnd(int resultCode, String resultMsg) {
Log.i(TAG, "handle onEnd...");
if(isContinue) {
mHandler.obtainMessage(MSG_CONTINUE).sendToTarget();
@ -61,4 +61,31 @@ public class FFmpegHandler {
});
}
/**
* execute probe cmd
* @param commandLine commandLine
*/
public void executeFFprobeCmd(final String[] commandLine) {
if(commandLine == null) {
return;
}
FFmpegCmd.executeProbe(commandLine, new OnHandleListener() {
@Override
public void onBegin() {
Log.i(TAG, "handle ffprobe onBegin...");
mHandler.obtainMessage(MSG_BEGIN).sendToTarget();
}
@Override
public void onEnd(int resultCode, String resultMsg) {
Log.i(TAG, "handle ffprobe onEnd result=" + resultMsg);
if(isContinue) {
mHandler.obtainMessage(MSG_CONTINUE).sendToTarget();
}else {
mHandler.obtainMessage(MSG_FINISH).sendToTarget();
}
}
});
}
}

@ -6,5 +6,5 @@ package com.frank.ffmpeg.listener;
*/
public interface OnHandleListener {
void onBegin();
void onEnd(int result);
void onEnd(int resultCode, String resultMsg);
}

Loading…
Cancel
Save