0

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.)

2
  • 2
    MediaProjection should only be sending frames when something on the screen changes. If you're computing your FPS as (number of frames / total time), you will get a low value if you were recording something that didn't update the screen frequently. Do you have a 30-60 fps animation running while you're testing your recorder?
    – fadden
    Apr 15, 2016 at 18:10
  • 1
    The Huawei Honor 4C uses a HiSilicon Kirin 620 SoC, which I'm not familiar with, and a Mali GPU. If you're seeing different top speeds on different devices then it could very well be a hardware limitation. CPU performance isn't too relevant since all the important stuff is in the GPU or video encoder. Screen recording is more demanding than recording video from the camera... vid record is camera->encoder, screenrecord is app_render->composition->encoder, where app_render and composition are performed by the GPU. You may be able to get some info out of systrace.
    – fadden
    Apr 20, 2016 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.