Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record video #2

Closed
Taharo opened this issue May 8, 2019 · 17 comments
Closed

Record video #2

Taharo opened this issue May 8, 2019 · 17 comments

Comments

@Taharo
Copy link

Taharo commented May 8, 2019

Does CameraX support video record ?

@Pinkal7600
Copy link

Yes, we can record video using CameraX. I have done but I don't know its correct or not. Please refer below code may it helps you.

Config for Video in CameraX:

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

    }.build()

    videoCapture = VideoCapture(videoCaptureConfig)

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

To Start video recording:

    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")
            }

        })

To Stop video recording:

    videoCapture?.stopRecording()

@Taharo
Copy link
Author

Taharo commented May 9, 2019

Thanks for your response. But not all works fine.
1)
CameraX.bindToLifecycle(this, preview, videoCapture, imageAnalyzer)
lead to
java.lang.ArithmeticException: divide by zero
2) VideoCapture class have annotation RestrictTo(Scope.LIBRARY_GROUP)

@Taharo
Copy link
Author

Taharo commented May 9, 2019

But
CameraX.bindToLifecycle(this, preview, videoCapture)
works fine

@owahltinez
Copy link
Contributor

@Taharo video recording is currently in preliminary stages and not officially supported -- but we are working on it! Please see this related StackOverflow question.

@sandeep-borndigital
Copy link

sandeep-borndigital commented Oct 28, 2019

I have built small app which uses CameraX videocapture.

Issue : App crashes when pressed back while recording is on progress. Need some help to fix this.
Dependencies : camerax:camera-core 1.0.0-alpha06 & camerax:camera-camera2 : 1.0.0-alpha06

FATAL EXCEPTION: CameraX-video encoding thread
    Process: <packagename>, PID: 10794
    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.MediaCodec.dequeueOutputBuffer(android.media.MediaCodec$BufferInfo, long)' on a null object reference
        at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:604)
        at androidx.camera.core.VideoCapture$2.run(VideoCapture.java:348)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)

@RamapatiMaurya
Copy link

We have found a CameraX sample on Github https://github.com/robertlevonyan/CameraXDemo. By using this library we can capture photos and videos. While customizing this sample code i am not able to find any way to pause the video recording even start and stop video recording feature is there.

Any help will be appreciated!!!

@williamycyh
Copy link

I have built small app which uses CameraX videocapture.

Issue : App crashes when pressed back while recording is on progress. Need some help to fix this.
Dependencies : camerax:camera-core 1.0.0-alpha06 & camerax:camera-camera2 : 1.0.0-alpha06

FATAL EXCEPTION: CameraX-video encoding thread
    Process: <packagename>, PID: 10794
    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.MediaCodec.dequeueOutputBuffer(android.media.MediaCodec$BufferInfo, long)' on a null object reference
        at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:604)
        at androidx.camera.core.VideoCapture$2.run(VideoCapture.java:348)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)

I also got this error, how to resolve

@vikasacharya16
Copy link

vikasacharya16 commented Feb 7, 2020

I wonder why people in google, develop such a feature without proper documentation. I thought google has a well development strategies in the world.
I'm getting this error and no way i can find the solution.

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioRecord.startRecording()' on a null object reference

@Sowmya-Flickr
Copy link

When is Video record api expected to be released? It not part of the beta release, correct?

@saurabhthorat
Copy link

@Sowmya-Flickr According to their IssueTracker, they would start looking into video capture after they finish up their beta release.

@awscherb
Copy link

@vick16ach make sure you request RECORD_AUDIO permission

@NaveenKadiyala
Copy link

NaveenKadiyala commented Aug 8, 2020

I have built small app which uses CameraX videocapture.

Issue : App crashes when pressed back while recording is on progress. Need some help to fix this.
Dependencies : camerax:camera-core 1.0.0-alpha06 & camerax:camera-camera2 : 1.0.0-alpha06

FATAL EXCEPTION: CameraX-video encoding thread
    Process: <packagename>, PID: 10794
    java.lang.NullPointerException: Attempt to invoke virtual method 'int android.media.MediaCodec.dequeueOutputBuffer(android.media.MediaCodec$BufferInfo, long)' on a null object reference
        at androidx.camera.core.VideoCapture.videoEncode(VideoCapture.java:604)
        at androidx.camera.core.VideoCapture$2.run(VideoCapture.java:348)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.os.HandlerThread.run(HandlerThread.java:65)

I faced the same issue, i applied some hack to resolve this, it worked but not sure whether to follow this.
Just override the onBackPressed of activity and stopped recording by videoCapture.stopRecording();.
Stopping recording will call the onVideoSaved() and i was quitting the activity from there.
By using some boolean values you can achieve this.. hope this helps...

@kenmasumitsu
Copy link

Are there any ways to record video without audio ?
I tried VideoCapture.Builder.setAudioBitRate(0), but not audio is included in the video.

@idish
Copy link

idish commented Oct 8, 2020

I wonder why people in google, develop such a feature without proper documentation. I thought google has a well development strategies in the world.
I'm getting this error and no way i can find the solution.

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioRecord.startRecording()' on a null object reference

Adding android.permission.RECORD_AUDIO to the permissions will fix this

It doesn't fix it.

@dcnxx1
Copy link

dcnxx1 commented Jan 29, 2021

@Taharo video recording is currently in preliminary stages and not officially supported -- but we are working on it! Please see this related StackOverflow question.

how is it then possible that snapchat and whatsapp and instagram use video recording services without problems?

@darrinps
Copy link

darrinps commented Mar 3, 2021

@Taharo video recording is currently in preliminary stages and not officially supported -- but we are working on it! Please see this related StackOverflow question.

how is it then possible that snapchat and whatsapp and instagram use video recording services without problems?

I think he was referring to CameraX's support for it. It can be done in CameraX now though and from what I've seen, works better than Camera2 in many ways. Not everything is there though. No way to add a watermark/overlay like in iOS. No way (that I can find) to shut off audio recording. Etc.

@DeluxeViper
Copy link

For anyone looking to solve the null pointer exception, you must add the RECORD_AUDO permission to Android Manifest:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests