首先,您应该正确初始化 ffmpeg。
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext);
// please add following method after
ffmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() {
@Override
public void onFailure() {
// probably your device not supported
}
@Override
public void onSuccess() {
// you should init flag here (isLoaded, isReady etc.)
}
仅在那之后onSuccess()
您可以使用命令进行工作。
那么请检查以下内容answer https://superuser.com/a/556031作者:内克比德勋爵。
所以你的代码应该是这样的:
if (isFFmpegLoaded) {
// ffmpeg.execute(commands from link from the answer)
}
请不要忘记删除命令字符串和“ffmpeg”单词中的所有空格。
为了使命令更具可读性,我建议像这样构建命令:
final String[] command = new String[11]; // example of the first command in the answer
command[0] = "-y";
command[1] = "-ss";
command[2] = "30";
command[3] = "-t";
command[4] = "3";
command[5] = "-i";
command[6] = "-t";
command[7] = "filePath";
command[8] = "-vf";
command[9] = "fps=10,scale=320:-1:flags=lanczos,palettegen";
command[10] = "palette.png";
请确保您具有处理文件的存储权限,以防您使用外部存储。
基于这个策略 ffmpeg 对我来说效果很好。谢谢,祝你好运!