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

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

问题描述

Google已将新的CameraX库发布为Jetpack的一部分。拍照看起来很棒,但我的用例还需要制作视频。我为此尝试使用Google搜索,但找不到任何东西。

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 录制视频。我已经尝试在Github演示的 CameraX 的帮助下实现自己。请参考下面的代码,可能对您有帮助。

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演示。

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的重要评论

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

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

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