概述
Android项目中使用ffmpeg3.0.9通过命令行调用的方式解析和合成gif。简单学习总结一下。
解析gif,由gif得到一堆png
/**
* 解析gif图片
* @param gifPath gif图片地址
* @param pngDir 解析后图片保存目录
* @return
*/
public static String[] gifToPng(String gifPath, String pngDir) {
final int count = 6;
String[] commands = new String[count];
int index = 0;
commands[index++] = "ffmpeg";
commands[index++] = "-i";
commands[index++] = gifPath;
commands[index++] = "-c:v";
commands[index++] = "png";
commands[index++] = pngDir + File.separator + "image%d.png";
if (TestLog.isDebug()) {
TestLog.d(TAG, "index=" + index + ",count=" + count);
for (int i = 0 ; i < index; i++) {
TestLog.d(TAG, "commend=" + commands[i]);
}
}
return commands;
}
解析后的图片保存到指定的文件目录下,命名规则image%d.png,如下图所示: