android / camera-samples

Multiple samples showing the best practices in camera APIs on Android.
Apache License 2.0
5.01k stars 2.34k forks source link

version:1.2.0-alpha03 VideoCapture use #494

Closed Ymmmsick closed 2 years ago

Ymmmsick commented 2 years ago

demo code is base on version:1.1.0-alpha12,but lastest version is 1.2.0-alpha03,in lastest version,I can use preview perfectly,but video capture implement record I got this error:

 java.lang.IllegalStateException: Muxer is not initialized.
        at android.media.MediaMuxer.addTrack(MediaMuxer.java:637)
        at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:890)
        at androidx.camera.core.VideoCapture.lambda$startRecording$4$androidx-camera-core-VideoCapture(VideoCapture.java:508)
        at androidx.camera.core.VideoCapture$$ExternalSyntheticLambda6.run(Unknown Source:12)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.os.HandlerThread.run(HandlerThread.java:67)

my code is:

videoCapture = VideoCapture.Builder()//录像用例配置
                    .setTargetResolution(Size(640, 480))
                    .setVideoFrameRate(25)
                    .setBitRate(1 * 1024 * 1024)
                    .build()

startRecording code:

val outputFileOptions = VideoCapture
                .OutputFileOptions
                .Builder(File(path))
                .build()
            videoCapture?.startRecording(outputFileOptions,
                cameraExecutor,
                object : VideoCapture.OnVideoSavedCallback {
                    override fun onVideoSaved(outputFileResults: VideoCapture.OutputFileResults) {
                        onSuccess?.invoke(outputFileResults.savedUri)
                    }

                    override fun onError(
                        videoCaptureError: Int,
                        message: String,
                        cause: Throwable?
                    ) {
                        KLog.e(
                            TAG,
                            "startTakeVideo error,code = $videoCaptureError,message = $message"
                        )
                        runOnUIThread {
                            onError?.invoke(message)
                        }
                    }
                }
            )

in OnVideoSavedCallback onError info is:

startTakeVideo error,code = 1,message = Unexpected change in video encoding format.

how can I fix it please

Pixel 4 Android 12, API 32