3

Main Question: How can I capture video without preview using Camera2 API?

I am trying to record video from a Background Service without showing any preview.

Here is the same question asked but I want to do it with Camera2 API.

I found a sample code in Camera2VideoJava and trying to use that in the service.

I am unable to understand what to do now because there is no documentation to do something like this.

Can anyone please help?

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • share your code – Jitu Batiya Dec 16 '19 at 10:23
  • This is example which I am using : https://github.com/android/camera-samples/tree/master/Camera2VideoJava I am not getting error but I wanted to do like [this way](https://stackoverflow.com/questions/10121660/how-to-record-video-from-background-of-application-android) using Camera2 API. – Pratik Butani Dec 16 '19 at 10:41
  • check this camera article https://developer.android.com/guide/topics/media/camera#capture-video – Gundu Bandgar Dec 19 '19 at 06:35
  • I already have done this thing but I want to do it without displaying preview. @GunduBandgar – Pratik Butani Dec 19 '19 at 06:42
  • As far as I remember, you can make a preview even 1x1 px and overlap it with another view. – CoolMind Dec 22 '19 at 21:44

2 Answers2

0

Just remove the preview View from the session creation, and from the repeating requests. Leave only the Surface from the MediaRecorder.

However, note that background services will not be able to use the camera starting in Android 9 Pie; you need at least a foreground service.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
0

This seems to be the way to capture 4K video, but I haven’t tested it myself.

If you’re using the preview at 1080p, then the capture will be 1080p; that is my understanding.

You either have to capture without a preview surface at 4K, and / or use a GLSurfaceView at 4K resolutions.

The issue with GLSurfaceView at 4K is that it requires OpenGL ES 3.0, which many devices do not support.

There might be a way to pass the 4K buffer into a 1080p surface for preview, while also capturing 4K, but it’s not clear.

The main issue and the angst of most Camera2 API developers, is that OpenGL ES 3.0 doesn’t work on most devices, even if the camera itself supports 4K video.

Michael N
  • 436
  • 5
  • 6