Recording on-screen in-app on Android to capture 15 frames per second

After many searches and days of experimentation, I did not find a direct solution.

I am developing an application that the user will interact with the pet on the screen, and I want him to save it as a video.

Is there any “simple” way to capture the screen of the application itself?

I found a workaround (to save some bitmaps every second and then pass them to the encoder), but it seems too heavy. I will be happy even with a frame rate of 15 frames per second

It seems perhaps i.e. there is a similar application that does this, it is called "Talking Tom"

+8
android screen-capture
source share
1 answer

It really depends on how you implement your “pet view”. Do you draw on canvas? OpenGl ES? Normal Android view hierarchy?

In any case, there is no magic "recordScreenToVideo ()", as in one of the comments.

You need:

  • Get bitmaps representing your "frames". It depends on how you implement your presentation. If you draw yourself (Canvas or OpenGL), then save your raw pixel buffers as frames. If you use the usual hierarchy of views, subclass Android onDraw and save the “frames” that you get on the canvas. The onDraw system call frequency will be no less than the actual "frame rate" of the screen. Duplicate frames after this if necessary to provide video at 15 frames per second.

  • Encode your frames. It seems that you already have a mechanism for this, you just need it to be more efficient.

Coding optimization methods:

  • Cache your raster images (frames) and subsequent encoding. This will only work if your expected video is relatively short, otherwise you will exit the repository.
  • Recording is performed only at the frame rate created by your application (depending on how you draw), and use the encoder parameter to generate video at a frequency of 15 frames per second (without actually feeding 15 frames per second).
  • Adjust the quality settings for the current device. It can be done by performing a hidden test of the CPU cycle at application startup and determining some threshold values.
  • Encode only the most relevant part of the screen.
  • Again, it really depends on how you implement it - if you can save some “history data” and then convert it into frames without having to do it in real time, that would be better. For example, "moving", "smile", "color change" or any of your business logic, since you did not specify this. Your "generate movie" function will animate this story data as a sequence of frames (without drawing on the screen) and then encode.

Hope that helps

+1
source share

All Articles