account arrowhead-down arrowhead-up cart mobile-menu search sm-bold-x x-skinny-rounded x-skinny arrowhead-right social-facebook social-googleplus social-instagram social-linkedin social-pinterest social-qzone social-renren social-tencent social-twitter social-vkontakt social-weibo social-youku social-youtube

Please help us improve our website

Take our customer survey to evaluate your visit.

It should only take a few minutes to answer five quick questions. Just click the Launch survey button at the end of your visit to begin.

cancel
Showing results for 
Search instead for 
Did you mean: 
Welcome to the Open Devices community!

This is where we discuss open source and development related questions on our Open Devices initiative.

Camera2 API frame loss and crash (slow-motion recording)

Highlighted
Apprentice
Message 1 of 6
659 Views
Message 1 of 6

Camera2 API frame loss and crash (slow-motion recording)

Hello

 

I'm trying to develop an app that captures video in slow-motion with a Sony Xperia XZs (Dual SIM) with Android 8.0. I used this project as an example (since I'm relatively new at Android). Until now, I've encountered 2 problems when using 2 different approaches, which codes and logs I'll show at the end of this thread:

 

1.-Using MediaRecorder without using CamcorderProfile:

As you can see in the log, it skips some frames. I also can't get higher values than 65[FPS] =,(. If so, it just crashes. At 30[FPS] it takes really bad quality frames (like if it was taken with 256 colours but I'm unsure of what can cause it).

Regarding this approach, I want to ask what is causing this frame drop and what prevents the app from running if I use more than 65[FPS] when the device is actually supossed to support up to 960[FPS] and what is that

E/libc: Access denied finding property "persist.camera.cfa.packagelist

and how can I get a solution. It doesn't seems to be the code since I've tried it with a ZTE Blade L5 PLUS with Android 5.0 and it worked (at 30[FPS], the device doesn't support more).

 

2.-Using CamcorderProfile

In this case, I've checked with the CamcorderProfile.hasProfile(int camId, CamcorderProfile profile) function if HIGH_SPEED_QUALITY_1080, HIGH_SPEED_QUALITY_720, HIGH_SPEED_QUALITY_HIGH, HIGH_SPEED_QUALITY_LOW exist, but it returns false? I don't know if this is any kind of bug or if actually the device doesn't have this profiles.

 

I also want to ask if there's any other approach to make the camera record slow-motion videos.

 

CODES:

1.-Using MediaRecorder without using CamcorderProfile:

 

    private void setupMediaRecorder() throws IOException
    {
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setOutputFile(mVideoFileName);
        mMediaRecorder.setVideoEncodingBitRate(1000000);
        mMediaRecorder.setVideoFrameRate(30);
        mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mMediaRecorder.setOrientationHint(mTotalRotation);
        try
        {
            mMediaRecorder.prepare();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

Obtaining the following log:

 

11-06 12:36:50.898 14182-14182/com.company.www.projectnameW/.projectname: type=1400 audit(0.0:9287): avc: denied { read } for name="u:object_r:camera_prop:s0" dev="tmpfs" ino=15030 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:camera_prop:s0 tclass=file permissive=0 ppid=1034 pcomm="main" pgid=1034 pgcomm="main"
11-06 12:36:50.901 14182-14182/com.company.www.projectname E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-06 12:36:50.942 14182-14211/com.company.www.projectname I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-06 12:36:53.728 14182-14182/com.company.www.projectname I/Choreographer: Skipped 44 frames!  The application may be doing too much work on its main thread.
11-06 12:36:54.533 14182-14187/com.company.www.projectname I/zygote64: Do partial code cache collection, code=51KB, data=47KB
    After code cache collection, code=51KB, data=47KB
    Increasing code cache capacity to 256KB

 

 

2.-Using CamcorderProfile

 

   private void setupMediaRecorder() throws IOException
    {
        CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_720P);
        mMediaRecorder.setCaptureRate(profile.videoFrameRate/6.0f);
        mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
        mMediaRecorder.setProfile(profile);
        mMediaRecorder.setOrientationHint(mTotalRotation);
        try
        {
            mMediaRecorder.prepare();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

 

with the following log:

 

11-06 12:50:22.278 14744-14744/? W/.project: type=1400 audit(0.0:10800): avc: denied { read } for name="u:object_r:camera_prop:s0" dev="tmpfs" ino=15030 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:camera_prop:s0 tclass=file permissive=0 ppid=1034 pcomm="main" pgid=1034 pgcomm="main"
11-06 12:50:22.282 14744-14744/? E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-06 12:50:22.305 14744-14774/? I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-06 12:50:24.722 14744-14749/com.company.www.project I/zygote64: Do partial code cache collection, code=50KB, data=44KB
    After code cache collection, code=50KB, data=44KB
    Increasing code cache capacity to 256KB
11-06 12:50:24.723 14744-14749/com.company.www.project I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
11-06 12:50:29.004 14744-14744/com.company.www.project E/MediaProfiles: The given camcorder profile camera 0 quality 2003 is not found
11-06 12:50:29.004 14744-14744/com.company.www.project I/chatty: uid=10227(u0_a227) com.company.www.project identical 9 lines
11-06 12:50:29.004 14744-14744/com.company.www.project E/MediaProfiles: The given camcorder profile camera 0 quality 2003 is not found
11-06 12:50:29.007 14744-14744/com.company.www.project E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.company.www.project, PID: 14744
    java.lang.RuntimeException: Error retrieving camcorder profile params
        at android.media.CamcorderProfile.native_get_camcorder_profile(Native Method)
        at android.media.CamcorderProfile.get(CamcorderProfile.java:471)
        at android.media.CamcorderProfile.get(CamcorderProfile.java:402)
        at com.company.www.project.MainActivity.setupMediaRecorder(MainActivity.java:436)
        at com.company.www.project.MainActivity.startRecord(MainActivity.java:455)
        at com.company.www.project.MainActivity.checkWriteStoragePermission(MainActivity.java:412)
        at com.company.www.project.MainActivity.access$800(MainActivity.java:42)
        at com.company.www.project.MainActivity$3.onClick(MainActivity.java:191)
        at android.view.View.performClick(View.java:6256)
        at android.view.View$PerformClick.run(View.java:24710)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:251)
        at android.app.ActivityThread.main(ActivityThread.java:6572)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

 

5 REPLIES 5
Developer World
Message 2 of 6
650 Views
Message 2 of 6

Re: Camera2 API frame loss and crash (slow-motion recording)

Hi,

 

are you on AOSP or Sony SW?

 

Regards

Alin

 

Apprentice
Message 3 of 6
645 Views
Message 3 of 6

Re: Camera2 API frame loss and crash (slow-motion recording)

Hi. I think it's a Sony SW but I'm not sure, is there anyway to check this?.

Apprentice
Message 4 of 6
624 Views
Message 4 of 6

Re: Camera2 API frame loss and crash (slow-motion recording)

Hi again

 

I'm using the default O.S. that comes with the device, I haven't changed anything =).

Now I've made the app "work" but I can't set different FPS than 30. Here is the code wich is working right now with no frame skipping:

 

private void setupMediaRecorder() throws IOException
{
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    mMediaRecorder.setOutputFormat(profile.fileFormat);
    mMediaRecorder.setVideoEncoder(profile.videoCodec);
    mMediaRecorder.setVideoEncodingBitRate(8000000);
    mMediaRecorder.setVideoFrameRate(120);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);

    mMediaRecorder.setOutputFile(mVideoFileName);

    mMediaRecorder.setOrientationHint(mTotalRotation);
    try
    {
        mMediaRecorder.prepare();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}

Why doens't it set 120FPS?
Thanks for your time

Apprentice
Message 5 of 6
594 Views
Message 5 of 6

Re: Camera2 API frame loss and crash (slow-motion recording)

Do you think that rooting the device will make it easier? I can do it if it's necessary

Developer World
Message 6 of 6
542 Views
Message 6 of 6

Re: Camera2 API frame loss and crash (slow-motion recording)

Hi,

rooting the device will not add the functionality needed by your apk

 

There are curently 2 Android options for your device:

- Sony official SW which came with the device (this one uses the Sony high quality camera features)

- Open Devices / AOSP software which runs on any unlocked bootloader device and adds a different camera framework  implemented with open source code (https://developer.sony.com/develop/open-devices/)

You can choose any of them

 

Regards

Alin