Reputation: 62419
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?
Upvotes: 3
Views: 1392
Reputation: 559
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.
Upvotes: 0
Reputation: 18137
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.
Upvotes: 0