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”
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