How to pause/resume video recording in CameraX

1,248 views
Skip to first unread message

Dante Zhang

unread,
May 27, 2020, 12:25:36 AM5/27/20
to Android CameraX Discussion Group
Hi There,

Currently I am using CameraX to do some video recording, while it looks like the VideoCaputre is still only allowed to be used internally.

I can start/stop the recording, and it works, but I need to pause/resume the recording, and it looks like currently it is not supported.

Is there anyway that I can do that.

If not, maybe the question will be how I can get the SurfaceView of the Camera or Preview, so that I can apply the MediaRecorder to do the video recording instead.

I am looking forward to hearing from you.

Thanks,

Dante

Trevor McGuire

unread,
May 27, 2020, 6:57:14 PM5/27/20
to Android CameraX Discussion Group, dante...@manfrotto.com
Hi Dante,

Thanks for the feedback. As you have pointed out, currently the only way to get the behavior you're looking for is to take control of the Surface that is being passed to CameraX, which means you will need to use a Preview use case with Preview#setSurfaceProvider(). You can find an example of how to implement a Preview.SurfaceProvider here. Note that instead of creating a SurfaceTexture and creating a Surface from that, you will likely just want to get a Surface from MediaRecorder. Please let us know if this works for you!

Trevor
Message has been deleted

Dante Zhang

unread,
May 29, 2020, 12:07:38 AM5/29/20
to Android CameraX Discussion Group, dante...@manfrotto.com
HI Trevor,

Thank you for your advise, but I still have some question.

I can attach the Surface from MediaRecorder to the Preview, but the PreviewView cannot be shown, as the Surface from PreviewView is not attached.

And I tried to create another Preview object, and attach the Surface from MediaRecorder to it, but the PreviewView will be black.

So basically it seems that I can show the preview and do the video recording by MediaRecorder by the same time.

Do you have any further suggestion that can help me?

Thanks,

Dante

Scott Nien

unread,
May 29, 2020, 5:27:22 AM5/29/20
to Dante Zhang, Android CameraX Discussion Group
Maybe having some code snippets will help ?  
Is it possible that you do not provide the Surface to the 2nd Preview's surfaceProvider or too late . We have 5 seconds timeout, so if you are unable to provide the surface within 5 seconds,  it will stop waiting for the surface and there will be no camera output . 

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/5b2eea88-ecfb-4aa8-b9e1-29875315404d%40android.com.

Dante Zhang

unread,
May 29, 2020, 7:22:14 AM5/29/20
to Android CameraX Discussion Group, dante...@manfrotto.com
Yes, no problem, attach the files I am using for video recording.

And maybe you are right, if I start to record, the PreviewView can be shown and update, but if I stop the recording, the PreviewView will be frozen again.

It just looks like I must provide a surface at the first time, and it should be before binding to the lifecycle or after?

And if the 2nd Preview doesn't have any SurfaceProvider, the 1st Preview won't work? And all the camera out is cut off?
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.
BaseCameraControllerImpl.java
VideoCameraControllerImpl.java

Scott Nien

unread,
May 31, 2020, 11:54:07 PM5/31/20
to Dante Zhang, Android CameraX Discussion Group
It seems you provide the video surface when startRecording().  That doesn't work because CameraX needs that surface to configure Camera2 CameraCaptureSession. The surface must be provided no later than 5 seconds when opening the camera. 


To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/842cfd72-ed65-408e-a3f4-8cc8f281a2d1%40android.com.

Dante Zhang

unread,
Jun 1, 2020, 7:16:57 AM6/1/20
to Android CameraX Discussion Group, dante...@manfrotto.com
Yes, I think that's the problem, but still I don't know how to deal with it, here are two problem:

1. I need to know the resolution of the final video, it looks like we only can get the correct value from the SurfaceRequest.
2. If I provide the Surface from the MediaRecorder when the Preview is created, I need to make the MediaRecorder to prepare when even the customer is not starting the recording, because I only can get the Surface after the MediaRecorder is fully prepared.

The CameraX hides the CameraCaptureSession, but I think the CameraCaptureSession should be reset when set a new SurfaceProvider, because the Preview can work when the recording is started, which means when I provide a new correct SurfaceProvider, then it can work.

Anyway, do we have any example that I can learn about how to integrate the MediaRecorder to current CameraX.

Thanks,

Dante 
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

Vinit Modi

unread,
Jun 1, 2020, 12:29:13 PM6/1/20
to Dante Zhang, Android CameraX Discussion Group
Hi Dante, 

We'll be able to share samples and docs once video is formally added as an API. :) 

Thanks!
Vinit

To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/3a4c85ab-88f9-4ea6-b75e-fae7407640b8%40android.com.

Scott Nien

unread,
Jun 2, 2020, 5:43:19 AM6/2/20
to Dante Zhang, Android CameraX Discussion Group
I think you can bind the video surface only when video recording is started,   and unbind the video surface when recording is done/cancelled. 
That way it'll recreate the capture session with the video surface.     What you shouldn't do is to bind a Preview use case but don't intend to provide the surface immediately





To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/3a4c85ab-88f9-4ea6-b75e-fae7407640b8%40android.com.

Dante Zhang

unread,
Jun 5, 2020, 3:44:56 AM6/5/20
to Android CameraX Discussion Group, dante...@manfrotto.com
Hi Scott,

Thank you for your advice, but I am still a little confused.

Firstly, I need two Preview UseCase, one is for showing the real PreviewView we can call it Preview 1,  the other is for video recording we can call it Preview 2.

What you suggest is:
1.when the PreviewView is shown and recording not started, only Preview 1 is binded.
2.when the PreviewView is shown and recording started, unbind all, and bind Preview 1 and Preview 2 with providing the Surface from the MediaRecorder.
3.when the PreviewView is shown and recording stop, unbind all, and only bind the Preview 1 again.

So my understanding is correct, right?

Thanks,

Dante
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

Scott Nien

unread,
Jun 5, 2020, 4:03:14 AM6/5/20
to Dante Zhang, Android CameraX Discussion Group
Your understanding is correct,  except that in step2, 3,  you don't have to unbindAll first,  you can just unbind/bind one use case. 
The drawback of this approach is it will have freeze time when you start/stop recording. 

Or you can wait until we make videoCapture officially released. 
Scott

To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/89dbf061-7784-4f24-acf2-91f288541d8eo%40android.com.

Dante Zhang

unread,
Jun 5, 2020, 5:29:12 AM6/5/20
to Android CameraX Discussion Group, dante...@manfrotto.com
OK, it sounds good, and I will have a try.

Well, I also expect we can have more flexibility about using CameraX.

Cheers,

Dante
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-developers+unsub...@android.com.
Reply all
Reply to author
Forward
0 new messages