当> = 65 [FPS]时,camera2 API帧会跳过并崩溃 [英] camera2 API frames skip and crash when >= 65[FPS]

查看:122
本文介绍了当> = 65 [FPS]时,camera2 API帧会跳过并崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在以此项目为例开发用于慢动作录制的Android应用.我已经在ZTE BLADE L5 PLUS(Android 5.0)上试用过该应用,并且运行良好,但是由于我需要超过30 [FPS]才能获得高质量的慢动作视频,因此我改用了Sony Xperia XZ(Android 8.0)并尝试了此应用.

I'm currently developing an Android App for slow-motion recording using this project as an example. I've tried this App with a ZTE BLADE L5 PLUS (Android 5.0) and it worked just fine, but since I need more than 30[FPS] to get a quality slow-motion video, I've changed to a Sony Xperia XZs (Android 8.0) and tried this App.

我现在有2个问题:

1.-跳过了帧:当我从30(没有尝试过)录制到65 FPS时,该应用会比我用mMediaRecorder.setVideoFrameRate(int)修复的帧丢失更多的帧,这实际上使视频输出冻结"了1秒钟以上.为什么会发生这种情况以及如何预防呢?

1.-Frames skipped: When I record from 30 (haven't tried less) to 65 FPS, the app looses ocasionally more frames than the ones I fixed with mMediaRecorder.setVideoFrameRate(int) which actually makes the video output to "freeze" for more than 1 second. Why does this happen and how to prevent it?

2.-如果我设置的值> = 65 FPS,应用程序将崩溃:我实际上不知道我在这里做错了什么.如果有人在代码中看到可能导致失败的内容,我将不胜感激.

2.-If I set a value >= 65 FPS the app just crashes: I don't actually know what I'm doing wrong in here. If someone sees something in the code that could make it fail, I'll appreciate all the help.

代码:

    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();
    }
}

LOG WITH<65FPS:

    11-07 11:33:28.788 9285-9309/com.company.www.project I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-07 11:33:28.793 9285-9309/com.company.www.project I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
11-07 11:33:28.809 9285-9309/com.company.www.project I/OpenGLRenderer: Initialized EGL, version 1.4
11-07 11:33:28.846 9285-9285/com.company.www.project I/CameraManagerGlobal: Connecting to camera service
11-07 11:33:28.874 9285-9285/com.company.www.project E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-07 11:33:28.862 9285-9285/com.company.www.project W/.project: type=1400 audit(0.0:1356): avc: denied { read } for name="u:object_r:camera_prop:s0" dev="tmpfs" ino=3332 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-07 11:33:28.874 9285-9285/com.company.www.project E/libc: Access denied finding property "persist.camera.cfa.packagelist"
11-07 11:33:28.879 9285-9290/com.company.www.project I/zygote64: Do partial code cache collection, code=27KB, data=23KB
    After code cache collection, code=27KB, data=23KB
    Increasing code cache capacity to 128KB
11-07 11:33:28.936 9285-9309/com.company.www.project I/vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8996.so from the current namespace instead.
11-07 11:33:31.638 9285-9290/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-07 11:33:31.639 9285-9290/com.company.www.project I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
11-07 11:33:39.400 9285-9290/com.company.www.project I/zygote64: Do full code cache collection, code=124KB, data=90KB
11-07 11:33:39.401 9285-9290/com.company.www.project I/zygote64: After code cache collection, code=89KB, data=59KB
11-07 11:34:00.273 9285-9285/com.company.www.project I/Choreographer: Skipped 55 frames!  The application may be doing too much work on its main thread.
11-07 11:34:00.729 9285-9290/com.company.www.project I/zygote64: Do partial code cache collection, code=124KB, data=82KB
    After code cache collection, code=124KB, data=82KB
    Increasing code cache capacity to 512KB
11-07 11:34:21.830 9285-9285/com.company.www.project I/Choreographer: Skipped 36 frames!  The application may be doing too much work on its main thread.

日志> = 65FPS:

11-07 12:14:59.806 10366-10366/com.company.www.project E/MediaRecorder: prepare failed: -2147483648
11-07 12:14:59.806 10366-10366/com.company.www.project W/System.err: java.io.IOException: prepare failed.
11-07 12:14:59.807 10366-10366/com.company.www.project W/System.err:     at android.media.MediaRecorder._prepare(Native Method)
        at android.media.MediaRecorder.prepare(MediaRecorder.java:954)
        at com.company.www.project.MainActivity.setupMediaRecorder(MainActivity.java:444)
        at com.company.www.project.MainActivity.startRecord(MainActivity.java:456)
        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)
11-07 12:14:59.808 10366-10366/com.company.www.project W/System.err:     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)
11-07 12:14:59.808 10366-10366/com.company.www.project E/MediaRecorder: SurfaceMediaSource could not be initialized!
11-07 12:14:59.810 10366-10366/com.company.www.project E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.company.www.project, PID: 10366
    java.lang.IllegalStateException: failed to get surface
        at android.media.MediaRecorder.getSurface(Native Method)
        at com.company.www.project.MainActivity.startRecord(MainActivity.java:467)
        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)

感谢您的时间=)

推荐答案

您需要以下配置才能以30、60、90和120 fps进行录制.

You need the following configuration to record at 30, 60, 90 and 120 fps.

来源: $ git clone https://source.codeaurora.org/quic/la/camera-samples -b iot-concam-apk.lnx.1.1

    private var streamConfigOpMode: Int = 0x00
    private val HIGH_SPEED_SESSION: Int = 1

        previewRequest.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range(previewFps, previewFps))
        if (previewFps == 120) streamConfigOpMode = streamConfigOpMode or HIGH_SPEED_SESSION

        Log.d(TAG, "Operation Mode: $streamConfigOpMode")
        val config = SessionConfiguration(
                streamConfigOpMode, outConfigurations, HandlerExecutor(cameraHandler),
                object : CameraCaptureSession.StateCallback() {
                    override fun onConfigured(s: CameraCaptureSession) {

                        if (previewFps == 120) {
                            Log.i(TAG, "onConfigured HFR session")
                            sessionHFR = s as CameraConstrainedHighSpeedCaptureSession
                            // if there is no active surface, do not set setRepeatingBurst.
                            if (streamSurfaceList.isNotEmpty()) {
                                var requestList = sessionHFR.createHighSpeedRequestList(previewRequest.build())
                                sessionHFR.setRepeatingBurst(requestList, null, cameraHandler)
                            }
                        } else {
                            Log.i(TAG, "onConfigured session")
                            session = s
                            // if there is no active surface, do not set setRepeatingRequest.
                            if (streamSurfaceList.isNotEmpty()) {
                                if ((streamSurfaceList.size == 2) && (previewFps == 60 || previewFps == 90)) {
                                    optimizePreviewFPS(previewFps)
                                } else {
                                    session.setRepeatingRequest(previewRequest.build(), null, cameraHandler)
                                }
                            }
                        }
                        isCameraReady = true
                        Log.i(TAG, "isCameraReady true")
                    }

                    override fun onConfigureFailed(s: CameraCaptureSession) =
                            s.device.close()
                })

        config.sessionParameters = previewRequest.build()
        camera.createCaptureSession(config)
        Log.i(TAG, "createSession exit")


    private fun optimizePreviewFPS(previewFps: Int) {
        when (previewFps) {
            60 -> {
                var burstList = mutableListOf<CaptureRequest>()
                burstList.add(previewRequest.build())
                // First Surface is always display.
                previewRequest.removeTarget(streamSurfaceList[0])
                burstList.add(previewRequest.build())
                session.setRepeatingBurst(burstList, null, cameraHandler)
                previewRequest.addTarget(streamSurfaceList[0])
            }
            90 -> {
                var burstList = mutableListOf<CaptureRequest>()
                burstList.add(previewRequest.build())
                // First Surface is always display.
                previewRequest.removeTarget(streamSurfaceList[0])
                burstList.add(previewRequest.build())
                burstList.add(previewRequest.build())
                session.setRepeatingBurst(burstList, null, cameraHandler)
                previewRequest.addTarget(streamSurfaceList[0])
            }
        }
    }

这篇关于当&gt; = 65 [FPS]时,camera2 API帧会跳过并崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆