使用 FFMPEG 库来解决您的问题。感谢您的 writeminds 使 ffmpeg 在 Android 上变得简单
1.implementation 'com.writingminds:FFmpegAndroid:0.3.2'
-
初始化 ffmpeg
private void setUpFFmpeg() {
ffmpeg = FFmpeg.getInstance(context);
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {
Log.d("Event ", "onStart");
}
@Override
public void onFailure() {
Log.d("Event ", "onFailure");
}
@Override
public void onSuccess() {
Log.d("Event ", "onSuccess");
}
@Override
public void onFinish() {
Log.d("Event ", "onFinish");
}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
}
}
use FFMPEG命令 https://stackoverflow.com/a/50501220/9558451就像上面发布的@Mahesh Keshvala 一样。干得好@Mahesh
-
then execFFmpegBinary(complexCommand);
会是这样
private void execFFmpegBinary(String[] command){
try {
ffmpeg.execute(commands, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
Log.d("Event ", "onStart");
}
@Override
public void onProgress(String message) {
Log.e("Event ", "onProgress - " + message);
}
@Override
public void onFailure(String message) {
Log.e("Event ", "onFailure - " + message);
}
@Override
public void onSuccess(String message) {
Log.e("Event ", "onSuccess - " + message);
}
@Override
public void onFinish() {
Log.e("Event ", "onFinish");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
}
尝试剪切视频命令
String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", inputFileAbsolutePath, "-t", "" + (endMs - startMs) / 1000, "-s", "320x240", "-r", "15", "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};
要了解有关 ffmpeg android 的更多信息,请参阅这个链接 https://androidlearnersite.wordpress.com/2017/03/17/ffmpeg-video-editor/