2

for whatsapp stickers i am generating animated gif using AnimatedGifEncoder and saving it as webp, but whatsapp does not accept it, so i need someone who guide me how to convert list of bitmaps into animated webp without using ffmpeg or covert the generated git into animated webp.

have tried this library but it throws the follow exception Not supported FourCC: I.C.C.P.

code is as follows:

    public boolean transform(List<Bitmap> bitmaps) {

    if (bitmaps == null || bitmaps.isEmpty()) {
        throw new IllegalArgumentException("Bitmaps is empty!");
    }

    //-----------------initiate the encoder----------------------
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    //----------------- encoder.start(bos) ----------------------
    encoder.start(bos);
    encoder.setRepeat(0);
    encoder.setQuality(quality);

    final int size = bitmaps.size();
    Bitmap sourceBmp;
    Bitmap resultBbm;
    for (int i = 0; i < size; i++) {
        sourceBmp = bitmaps.get(i);
        if (sourceBmp == null) {
            continue;
        }

        // result bitmap
        resultBbm = ThumbnailUtils.extractThumbnail(sourceBmp, sourceBmp.getWidth() / scaleX,
                sourceBmp.getHeight() / scaleY, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

        try {
            encoder.addFrame(resultBbm);
            if (onTransformProgressListener != null) {
                onTransformProgressListener.onProgress(i, size);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.gc();
            break;
        } finally {
            if (!sourceBmp.isRecycled()) {
                sourceBmp.recycle();
            }
            if (!resultBbm.isRecycled()) {
                resultBbm.recycle();
            }
        }
    }
    //----------------- encoder.finish() ----------------------
    encoder.finish();
    bitmaps.clear();

    byte[] data = bos.toByteArray();
    File saveFile = new File(outputPath);

    if (!saveFile.getParentFile().exists()) {
        saveFile.getParentFile().mkdirs();
    }

    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(saveFile);
        fos.write(data);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return saveFile.exists() && saveFile.length() > 0;
}
Usama Saeed US
  • 984
  • 11
  • 18
  • When you say you tried that library but it does not work, what actually happened? Can you show the code and errors from that? For this code, you say it does not accept it, but what actually happens? What error do you get? – David Conrad Sep 20 '21 at 14:22
  • it throws the following exception: Not supported FourCC: I.C.C.P. – Usama Saeed US Sep 20 '21 at 14:43
  • 3
    checkout this example https://github.com/b4rtaz/android-webp-encoder/blob/master/app/src/main/java/com/n4no/webpencoder/app/MainActivity.java – user16930239 Sep 24 '21 at 21:48
  • In Readme , there is TODO for alpha channel. What does that mean? Does this class work for images containing transprancies – CrackerKSR Mar 22 '22 at 08:56

0 Answers0