Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.
- step-by-step guide to making your iOS extension in under an hour
- library for data conversion between ActionScript and native code
- tutorials
- infographics
- code included
Today’s article is a response to a question we found ourselves answering quite a lot on the e-mail since the release of our Gameplay Recorder Native Extension for iOS.
The question was:
How does Gameplay Recorder affect performance?
The performance of an app that uses it, that is. In other words:
- does the ANE affect your app’s frame rate and how much;
- does it matter what resolution you choose for recording your gameplay.
Intro
Let us first have a look at the phases of the gameplay screen recording that have the potential to affect an app’s performance:
- Rendering a frame on screen.
- Requesting a copy of the rendered frame, or a portion of it, in the form of BitmapData, say from Starling.
- Transferring that BitmapData buffer to the native side, where it can be encoded as a video frame.
Phase 1 and 2 is where the ANE minimal or no control.
Phase 1 depends on how heavy your scene and game logic are. If you have a large number of items on screen and/or lenghty physics calculations to perform, the frame rate will suffer.
For phase 2 Starling uses Context3D.drawToBitmapData() function for which Adobe warn: “This is potentially a very slow operation that can take up to a second. Use with care.” (read the full descriotion here).
Phase 3 is where we have done optimizations to make sure that adding a frame to the video will have a minimal impact on your app’s performance.
Test results
Performance of phase 2 is resolution dependent, so I ran several tests with different resolutions to measure the time required by each of the phases.
To minimise the impact of the scene size on the tests I used the five rotating squares from the video we published earlier. The desired FPS was set to 30. In other words, every frame will need at most 33 milliseconds to draw itself. Tests were performed on my old iPad2 with iOS 5.1.
All results were measured for the average performance of 1-minute video capture both for release and for debug builds.
Resolution | Scene Drawing | drawToBitmapData() | Encode video frame (in the ANE) | FPS |
480×320 | 0.0089 ms | 22.54 ms | 1.75 ms | 30 |
640×480 | 0.0098 ms | 59.30 ms | 4.70 ms | 14.8 – 15 |
1024×768 | 0.015 ms | 217.98 ms | 13.1 ms | 4.3 |
Resolution | Scene Drawing | drawToBitmapData() | Encode video frame (in the ANE) | FPS |
480×320 | 0.32 ms | 32.72 ms | 2.11 ms | 28.9 – 30 |
640×480 | 0.30 ms | 67.28 ms | 4.78 ms | 11.6 – 12 |
1024×768 | 0.31 ms | 237.55 ms | 13.18 ms | 3.9 – 4 |
Verdict
From the test results above it’s easy to see that one bottleneck is how fast AIR copies a Context3D back buffer to BitmapData. Respectively, the larger the resolution, the more time that takes.
A useful tip would be to limit the screen capture only to the objects that you need from the scene, rather than recording the full scene. Gameplay recording with a resolution of 640 x 480 leaves the app with a playable frame rate.
The Gameplay Recorder Native Extension for iOS impact on the game loop is negligible and varies between 2ms to 13ms for large resolutions.
Brian
It is really nice with a insigt in the ANE performance, thanks a lot.
The performance does not really seem to match my needs (640×640 at 30fps)
Its is posible to invoke the timestep manually? instead of the ANEs timer? In a “stop-motion kind of way”
So that I record a new frame to the video when my application is done rendering and drawing the bitmap? For eg. recording at 10 fps, but the result will be a 30fps video.
I hope you understand my question
Are you planning an Android version of this ANE?
Sincerely Brian
Hristo
Hi Brian,
Apologies for the delay!
I’m afraid that doing stop motion animation is not possible at the moment because it will confuse the video encoder’s logic.
In terms of frame rate and speed will an ANE for a native screen recording library like Kamcord or Everyplay work better for your needs?
We haven’t had enough interest in an Android version of the ANE yet to justify our spending time on it. However, we’d be happy to do it if enough people ask for it. Anyone interested?
Greetings,
Hristo
Nenu martz
1-Is it possible to use this extension to record audio only?
2-Is it possible to use this extension if I do not use Starling?
Hristo
Hi Nenu,
Thank you for your interest in our Gameplay Recorder ANE.
About your questions:
1. Gameplay Recorder ANE doesn’t record sound;
2. Yes, you can record anything that could draw itself into a BitmapData. You could find an example here, take a look at Step 4: Recording video.
What kind of applications are you working on?
Cheers,
Hristo