I Would like to ask, if it's possible to improve performance for MediaProjection
.
Edited after fadden answer.
Pseudo structure of app:
1) Fullscreen FrameLayout in AppCompatActivity:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/cameraPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
2) Camera Preview with SurfaceView
class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
3) Add Camera Preview to FrameLayout
frameLayout.addView(CameraPreview)
4) Create input surface:
Surface mSurface = MediaCodec.createInputSurface();
5) Create virtual display and render the virtual display to Surface.
MediaProjection.createVirtualDisplay(
"virtualDisplay",
720, //width
1280, //height
320, //dpi
DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
mSurface,
null,
null);
6) Using MediaMuxer
for Audio/Video mux streams.
For example, for 10s. of recording:
MPEG4Writer: Received total/0-length (201/0) buffers and encoded 201 frames. - Video
MPEG4Writer: Received total/0-length (423/0) buffers and encoded 423 frames. - Audio
It is ~ 20 FPS.
I would like to have 30 FPS. (Device can record fullHD with 30 FPS, so i think, that could be possible.)
I tried record screen from Android studio 2.0, and for:
width:720px
height:1280px
bitrate:8Mbps
has video still 20 FPS.
Tested on Huawei Honor 4C, Android 5.1.1 ~20 FPS.
Tested on Vodafone Smart Ultra 6, Android 5.1.1, and video has ~40 FPS.
I tried TinyDancer for measuring FPS, and it show 60 FPS during recording.
Where can be weak point? CPU usage during recording is < 10%.
Additionally question: It is better performance for MediaProjection in Android 6?
(Note: I record camera preview with overlay views.)