我想用FFmpeg-Android-Java拆分动画的gif文件,所以我引用了这个问题Android, split gif to frames with ffmpeg 并编写了这段代码。
String path = "/storage/emulated/0/Download/mothersday-toaster.gif";
String cmd[] = {"-i",path,"-vsync","0","/storage/emulated/0/Download/output$03d.png"};
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onProgress(String message) {}
@Override
public void onFailure(String message) {Log.d("Q", "failed to convert");}
@Override
public void onSuccess(String message) {}
@Override
public void onFinish() {}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
虽然,它总是给我“未能转换”的日志。 FFMPEG已加载。我的代码有问题吗?
好的,所以解决方案非常简单。
我发现onProgress输出说它需要权限所以我注意到我忘了给我的应用程序WRITE_EXTERNAL_STORAGE权限,这是一种耻辱。而且,我将output$03d
部分更改为output%03d
。感谢Gyan的建议。