0

I am using Lottie Animation Library and I want to record that animation view as video but this library does not have any video exporting support so I am trying to find my own solution and,

This is what I have tried so far.

    animationView.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {

            if((animationView.getFrame()) != previous ){
                // getting single frame
                previous = animationView.getFrame();
                FrameLayout view = frameLayout;
                Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                view.draw(canvas);
                bitmaps.add(bitmap);
            }

        }
    });

So above code addAnimatorUpdateListener runs every time when the animation is being updated so this function store all the bitmaps in the array.

for(Bitmap bitmap:bitmaps){
                    OutputStream stream;
                    try {
                        counter++;
                        stream = new FileOutputStream(imageFolder.getAbsolutePath()+"/test-"+counter+".png");
                        bitmap.compress(Bitmap.CompressFormat.PNG,100,stream);
                        Log.i(tag, "onAnimationEnd: " + "converting... " + String.valueOf(counter) + "of " + String.valueOf(animationView.getMaxFrame()));
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                        Log.i(tag, "onAnimationEnd: " + e.getMessage());
                    }

                }

When the animation ends Than above code convert all the images from the bitmaps array and stores them in the temporary folder. and then I am using FFmpeg-Android to convert the video from the images in mp4.

FFmpeg command

String[] fcommand = new String[]{"-i", path + "test-%1d.png", "-c:v", "libx264", "-vf", "fps=30", "-pix_fmt", "yuv420p", path + String.valueOf(new Date()) +".mp4"};

From this command, I am generating video at 30 FPS.

Issues that I am facing right now

  • Video is not so smooth even at 30 fps (420p).
  • (Bitmap.createBitmap(view.getDrawingCache()); 30 times in one second? is it possible?

TL;DR

I just want to capture the bitmaps of a specific view at 30 fps how I can achieve this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Kartik Garasia
  • 1,324
  • 1
  • 18
  • 27
  • I have been on [this](https://stackoverflow.com/q/46497611/295004) Question thread, And I am able to generate a video but still, it's laggy so I am looking for that solution but thanks anyway. – Kartik Garasia Mar 29 '19 at 14:29
  • Just record the screen with a screenrecorder – Omkar T Nov 23 '21 at 05:22

0 Answers0