我在我的一个项目中使用 FFmpeg 进行视频压缩。在 Android 10 (Google Pixel 3a) 上,对于发送执行的任何命令,它会直接进入 onFailure(String message),并显示空消息。
所以我在我的应用程序 gradle 文件中指定了 (api 'com.writingminds:FFmpegAndroid:0.3.2'),
指定清单中的权限(android.permission.WRITE_EXTERNAL_STORAGE)
So I do:
InitializationCallback initializationCallback = new InitializationCallback();
try {
FFmpeg.getInstance(context).loadBinary(initializationCallback);
} catch (FFmpegNotSupportedException e) {
initializationCallback.onFailure();
initializationCallback.onFinish();
}
初始化得很好,没有问题。
Later:
void getData(File inputFile) {
//inputFile points to: /storage/emulated/0/Android/data/{package_name}/files/temp_files/temp_1.mp4
String[] cmd = ("-i " + inputFile.getAbsolutePath()).split(" ");
try {
FFmpeg.getInstance(App.instance).execute(cmd, this);
} catch (FFmpegCommandAlreadyRunningException e) {
throw new Error(e);
}
}
@Override
public void onStart() {
//This method is called
}
@Override
public void onSuccess(String message) {
//This method is NOT called
extractAvailableData(message);
}
@Override
public void onProgress(String message) {
//This method is NOT called
extractAvailableData(message);
}
@Override
public void onFailure(String message) {
//This method is called and the message is empty
extractAvailableData(message);
}
@Override
public void onFinish() {
//This method is called
}
如果我做类似的事情:
String command = "-i ***/file1.mp4 -map 0:v -map 0:a -preset ultrafast -s:v 750:350 ***/file2.mp4";
//file2.mp4 is a non existent file at this point
// (***) --> is just a replacement for the full path of the file, just to keep things shorter here.
String[] cmd = command.split(" ");
try {
FFmpeg.getInstance(App.instance).execute(cmd, this);
} catch (FFmpegCommandAlreadyRunningException e) {
throw new Error(e);
}
给出相同的结果,没有视频转换,只是调用 onFailure("Nothing")
即使我这样做:
String[] cmd = {"-version"};
try {
FFmpeg.getInstance(App.instance).execute(cmd, this);
} catch (FFmpegCommandAlreadyRunningException e) {
throw new Error(e);
}
我什么也没得到,根本没有输出。
到目前为止,我仅在 Android 10 上遇到此问题,在其他设备上运行良好。