我可以使用 CameraX (Android Jetpack) 录制视频吗? [英] Can I record video with CameraX (Android Jetpack)?

查看:22
本文介绍了我可以使用 CameraX (Android Jetpack) 录制视频吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google 已作为 Jetpack 的一部分发布了新的 CameraX 库.它看起来很适合拍照,但我的用例还需要制作视频.我尝试谷歌搜索,但找不到任何东西.

Google has released the new CameraX library as part of Jetpack. It looks great for taking pictures, but my use case also require making video's. I tried googling for that, but couldn't find anything.

那么,是否可以使用 CameraX Jetpack 库来录制视频?

So, is it possible to record videos with the CameraX Jetpack library?

推荐答案

是的,我们可以使用 CameraX 录制视频.我试图在 CameraX 的 Github 演示的帮助下实现自己.请参考以下代码可能对您有所帮助.

Yes, we can record video using CameraX. I have tried to implement myself with help of Github demo for CameraX. Please refer below code may it helps you.

CameraX 中的视频配置:

val videoCaptureConfig = VideoCaptureConfig.Builder().apply {
    setLensFacing(lensFacing)
    setTargetAspectRatio(screenAspectRatio)
    setTargetRotation(viewFinder.display.rotation)

}.build()

videoCapture = VideoCapture(videoCaptureConfig)

CameraX.bindToLifecycle(this, preview, imageCapture, videoCapture)

开始视频录制:

videoCapture?.startRecording(videoFile, object : VideoCapture.OnVideoSavedListener {
        override fun onVideoSaved(file: File?) {
            Log.i(javaClass.simpleName, "Video File : $file")
        }

        override fun onError(useCaseError: VideoCapture.UseCaseError?, message: String?, cause: Throwable?) {
            Log.i(javaClass.simpleName, "Video Error: $message")
        }

    })

停止视频录制:

videoCapture?.stopRecording()

与上面我在 Github 问题评论中提到的相同:https://github.com/android/camera/issues/2#issuecomment-490773932

Same above I have mentioned in Github issue comment: https://github.com/android/camera/issues/2#issuecomment-490773932

注意:使用CameraX实现视频录制的代码可能有所不同.因为上面这段代码是我自己开发的,没有任何其他参考,而是Github Demo.

Notes: There may be different in code to implementation of video recording using CameraX. Because this above code was developed by me without any other reference rather than Github Demo.

请查看 Oscar Wahltinez 对此答案的重要评论,截至 2019 年 5 月 14 日

Please check important comment of Oscar Wahltinez on this answer as of 14 May 2019

这篇关于我可以使用 CameraX (Android Jetpack) 录制视频吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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