Android 用ffmpeg生成Gif 各种排列组合的性能测试结果

Gif 测试

bmps -> Animated gif encode   -> 质量不错,  慢死,   10帧大概要两分钟

bmps 》 png  》avi 》gif    保存 png 速度太慢,  两秒钟一张,最后一步图片失真

bmps 》jpg 》 avi 》 gif  保存图片速度明显好于png,  最后一步图片失真

bmps 》 jpg 》gif   可以用ffmpeg里面的参数来保证gif图片元素在位移不太大的情况下 不那么失真, 不过效果有限


用到的ffmpeg的命令:

    public String water_mark(String input1, String input2) {
        String output = getTmpPath("")+"output.mp4";

        String merge = "ffmpeg -i "+input1+" -y -strict -2 -vf movie="+input2+"[watermark];[in][watermark]overlay=0:0[out] "+output;

        runParams(merge.split(" "));
        return output;

    }

    public String mp42gif(String input1,String input2){
        String[] params = new String[8];
        params[0] = "ffmpeg";
        params[1] = "-i";
        params[2] = input1;
        params[3] = "-t";
        params[4] = "5";
        params[5] = "-pix_fmt";
        params[6] = "rgb24";


        String DCIM = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM + File.separator;
        params[7] = input2;

        runParams(params);

        return null;
    }

    public String video_merge_gif(String input1, String input2){
        String[] params = new String[4];
        params[0] = "ffmpeg";
        params[1] = "-i";
        params[2] = input1;
        String DCIM = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM + File.separator;
        params[3] = DCIM+"image%d.jpg";

        runParams(params);

        return null;
    }

    public String gif2mp4(String input1, String input2){
        String[] params = new String[4];
        params[0] = "ffmpeg";
        params[1] = "-i";
        params[2] = input1;
        params[3] = input2;

        runParams(params);

        return null;
    }


    public String video_merge_test(String input1, String input2,ArrayList viewArrayList,String output){

//        String test = "ffmpeg -y -i "+input1+" -i "+input2;
        int k=0;
        for(ScaleAndRotateGifView view:viewArrayList){
            Utility.copyFile(view.getImagePath(), getTmpPath(k + "") + ".gif");
//            test+=" -ignore_loop 0 -i "+getTmpPath(k+"")+".gif";
            k++;
        }
//        test+=" -strict -2 -filter_complex [0:0]pad=iw:ih[a];[a][1:0]overlay=0";
//        char temp = 'b';
//        int i = 2;
//        for(ScaleAndRotateGifView view:viewArrayList){
//            test+="["+temp+"];["+temp+"]["+i+":0]overlay=0:h";
//            temp++;
//            i++;
//        }
//        test+=" -shortest "+output;

        String test="ffmpeg -y -i "+input1+" -i "+input2+" -ignore_loop 0 -i "+getTmpPath("0.gif")+" -ignore_loop 0 -i "+getTmpPath("1.gif")+" -strict -2 -filter_complex [0:0]pad=iw:ih[a];[a][1:0]overlay=0[b];[b][2:0]overlay=0:h[c];[c][3:0]overlay=w:h -shortest "+output;
        String[] params = test.split(" ");

        runParams(params);

        return null;
    }


    public String splitGif(String input1,String input2){
        String[] params = new String[6];
        params[0] = "ffmpeg";
        params[1] = "-i";
        params[2] = input1;
        params[3] = "-r";
        params[4] = "10";
        params[5] = input2;

        App.getCurrentApp().runParams(params);

        return null;
    }
    public String preparePalettegen(){
        String input1 = DCIM + "testgif" + (it + 1) + ".jpg";
        String tempPNG = App.getCurrentApp().getTmpPath("palettegen.png");

        String param = "ffmpeg -y -i " + input1 +
                " -vf palettegen -y " + tempPNG;
        App.getCurrentApp().runParams(param.split(" "));
        return tempPNG;
    }

    public String img2gif(String input1,String input2){
        String tempPNG = preparePalettegen();

        String command = "ffmpeg -f image2 -framerate 5 -i "+input1+" -i "+tempPNG+" -filter_complex fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse "+input2;
        String[] params = command.split(" ");

        App.getCurrentApp().runParams(params);

        return null;
    }


 
  

你可能感兴趣的:(ffmpeg,Android)