Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App screen recording on android to capture 15 frames per second

After a lot of searching and days of experiments I haven't found a straight-forward solution.

I'm developing an app that user will interact with a pet on the screen and i want to let him save it as video.

Is there any "simple" way to capture the screen of the app itself?

I found a workaround (to save some bitmaps every second and then pass them to an encoder) but it seems too heavy. I will happy even with a framerate of 15fps

It seems to be possible, i.e. there is a similar app that does this, its called "Talking Tom"

like image 485
DevN Avatar asked Dec 11 '12 23:12

DevN


People also ask

How many FPS is a screen recording?

A screen recording, sometimes called a screencast or video screen capture, is a digital recording of rendered scenes (ideally 60 frames per second) on a computer screen, often containing audio narration as well as a webcam or facecam video of the narrator.

How do I record 60fps video on Android?

Download and Install Screen recorder – No Ads application from the Play Store. Open the app and give all the permissions. Now, tap on the Hamburger icon and select Settings from the menu. Head over to the Video Settings > Frame Rate and select the desired framerate.


1 Answers

It really depends on the way you implement your "pet view". Are you drawing on a Canvas? OpenGl ES? Normal Android view hierarchy?

Anyway, there is no magical "recordScreenToVideo()" like one of the comments said.

You need to:

  • Obtain bitmaps representing your "frames". This depends on how you implement your view. If you draw yourself (Canvas or OpenGL), then save your raw pixel buffers as frames. If you use the normal view hierarchy, subclass Android's onDraw and save the "frames" that you get on the canvas. The frequency of the system's call to onDraw will be no less than the actual "framerate" of the screen. If needed, duplicate frames afterwards to supply a 15fps video.

  • Encode your frames. Seems like you already have a mechanism to do that, you just need it to be more efficient.

Ways you can optimize encoding:

  • Cache your bitmaps (frames) and encode afterwards. This will work only if your expected video will be relatively short, otherwise you'll get out of storage.
  • Record only at the framerate that your app actually generates (depending on the way you draw) and use an encoder parameter to generate a 15fps video (without actually supplying 15 frames per second).
  • Adjust quality settings to current device. Can be done by performing a hidden CPU cycle test on app startup and defining some thresholds.
  • Encode only the most relevant portion of the screen.
  • Again, really depending on the way you implement - if you can save some "history data", and then convert that to frames without having to do it in real time, that would be best. For example, "move", "smile", "change color" - or whatever your business logic is, since you didn't elaborate on that. Your "generate movie" function will animate this history data as a frame sequence (without drawing to the screen) and then encode.

Hope that helps

like image 131
SirKnigget Avatar answered Oct 23 '22 10:10

SirKnigget