|
|
@ -2,6 +2,7 @@ package com.github.xch168.ffmpeg.invoker.demo; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ProgressDialog; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
@ -15,12 +16,15 @@ import com.github.xch168.ffmpeg.invoker.FFmpegInvoker; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
|
|
|
public class FFmpegTestActivity extends AppCompatActivity { |
|
|
|
public class FFmpegTestActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
private ProgressDialog mProgressDialog; |
|
|
|
|
|
|
|
|
|
|
|
private String videoPath = "/storage/emulated/0/DCIM/Camera/fb639313f7f3d58cc793f20095439c88.mp4"; |
|
|
|
private String videoPath = "/storage/emulated/0/DCIM/Camera/fb639313f7f3d58cc793f20095439c88.mp4"; |
|
|
|
|
|
|
|
|
|
|
|
private FFmpegInvoker.Callback mCallback = new FFmpegInvoker.Callback() { |
|
|
|
private FFmpegInvoker.Callback mCallback = new FFmpegInvoker.Callback() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onSuccess() { |
|
|
|
public void onSuccess() { |
|
|
|
Looper.prepare(); |
|
|
|
Looper.prepare(); |
|
|
|
|
|
|
|
hideProgress(); |
|
|
|
Toast.makeText(FFmpegTestActivity.this, "处理成功", Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.makeText(FFmpegTestActivity.this, "处理成功", Toast.LENGTH_SHORT).show(); |
|
|
|
Looper.loop(); |
|
|
|
Looper.loop(); |
|
|
|
} |
|
|
|
} |
|
|
@ -28,13 +32,14 @@ public class FFmpegTestActivity extends AppCompatActivity { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onFailure() { |
|
|
|
public void onFailure() { |
|
|
|
Looper.prepare(); |
|
|
|
Looper.prepare(); |
|
|
|
|
|
|
|
hideProgress(); |
|
|
|
Toast.makeText(FFmpegTestActivity.this, "处理失败", Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.makeText(FFmpegTestActivity.this, "处理失败", Toast.LENGTH_SHORT).show(); |
|
|
|
Looper.loop(); |
|
|
|
Looper.loop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onProgress(float progress) { |
|
|
|
public void onProgress(float progress) { |
|
|
|
|
|
|
|
updateProgress((int) progress); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -49,13 +54,42 @@ public class FFmpegTestActivity extends AppCompatActivity { |
|
|
|
context.startActivity(intent); |
|
|
|
context.startActivity(intent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showProgress() { |
|
|
|
|
|
|
|
if (mProgressDialog == null) { |
|
|
|
|
|
|
|
mProgressDialog = new ProgressDialog(this); |
|
|
|
|
|
|
|
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); |
|
|
|
|
|
|
|
mProgressDialog.setCanceledOnTouchOutside(false); |
|
|
|
|
|
|
|
mProgressDialog.setMax(100); |
|
|
|
|
|
|
|
mProgressDialog.setTitle("正在处理"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mProgressDialog.setProgress(0); |
|
|
|
|
|
|
|
mProgressDialog.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void hideProgress() { |
|
|
|
|
|
|
|
if (mProgressDialog != null) { |
|
|
|
|
|
|
|
runOnUiThread(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
mProgressDialog.hide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateProgress(int percent) { |
|
|
|
|
|
|
|
mProgressDialog.setProgress(percent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void cutVideo(View view) { |
|
|
|
public void cutVideo(View view) { |
|
|
|
|
|
|
|
showProgress(); |
|
|
|
String savePath = getSaveDir() + "out.mp4"; |
|
|
|
String savePath = getSaveDir() + "out.mp4"; |
|
|
|
String cmd = "ffmpeg -y -ss 1 -t 100 -accurate_seek -i " + videoPath + " -codec copy " + savePath; |
|
|
|
String cmd = "ffmpeg -y -ss 1 -t 300 -accurate_seek -i " + videoPath + " -codec copy " + savePath; |
|
|
|
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback); |
|
|
|
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void extractFrame(View view) { |
|
|
|
public void extractFrame(View view) { |
|
|
|
|
|
|
|
showProgress(); |
|
|
|
String savePath = getSaveDir() + "out.png"; |
|
|
|
String savePath = getSaveDir() + "out.png"; |
|
|
|
String cmd = "ffmpeg -ss 10 -i " + videoPath + " -vframes 1 -y " + savePath; |
|
|
|
String cmd = "ffmpeg -ss 10 -i " + videoPath + " -vframes 1 -y " + savePath; |
|
|
|
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback); |
|
|
|
FFmpegInvoker.exec(cmd.split(" "), 100, mCallback); |
|
|
|