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?
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.
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.
Related
I do not know much about Camera API, though i need to use frames from a capturing video with more then 30fps with a good quality camera(S9).
Can anybody suggest code for the same.
I tried to find fit code for this but i am failed.
Thanks in Advance
Mohit
You are lucky, since not so long ago a component of android JetPack was released, called CameraX. Sadly it is still in alpha stage, meaning that you should avoid using it in production since it might have breaking changes in the future. This component was built on top of Camera 2 API, witch is a low level API for working with camera.
If you plan to use your app in production I highly recommend to use Camera 2 API, it is low level, however you have the full control over the camera.
Here is an example to get you started.
I'm planning to make a camera app that you can take a photo with a background image.
I guess there will be a need to use a Surfaceview? But the main problem is since the Camera is deprecated
there might be a need to use camera2 for android. I want to make a camera app in portrait mode but are there any
samples or tip? I googled but wasn't able to find a decent one. I would love to hear from you.
If you want to start with Camera2 API, this link will help you understand basics.
android-Camera2Basic(Github)
It is not necessary to use SurfaceView as you will see from code
that TextureView can also fulfill your requirement
The HdrViewfinder sample app uses SurfaceView with camera2, though it doesn't lock itself into portrait mode. But that's a relatively simple change.
Of course, camera2 was only added in Android 5.0, so if you need to support 4.0, you need to use the old camera API.
I am trying to implement the camera preview function into my app. After a lot of research I found that the best solution is the Camera2 API, but, it isn't supported on most phones. Is there a better solution to do this? For example, I read a lot about using a SurfaceView to load the camera preview on.
I simply followed the Android docs to use the camera API. Camera2 API is fairly new and I want to make sure all users can have it.
I want to built my own camera app in android including the following options pinch to zoom and autofocus without using camera intent. I already gone through some samples from Git hub but I couldn't make use of them.So, I decided to start learning Camera API from Google developers. Here I need a complete steps to develop my app and what to learn like camera, surface view and anything else.
Thanks in advance
I have done what you want to be done recently.
For android, there are 2 camera APIs
the camera api
and the camera2 api
camera api is deprecated on android api 21. starting from android api 21, you have to use camera2 api. so you have to learn both of them.
Camera api brother with SurfaceView.
Camera2 api brother with TextureView.
Camera2 api is quit alot different from Camera api, and also is much more complicated than Camera api.
You may want to take a look at my project SimpleCameraView, it is much clear than other projects. I just created this repository yesterday.
Things to Need to Learn to Build Custom Camera APP
Setting Camera,FlashLight and FILE_STORAGE Permissions in Manifest
SurfaceView and How to Use it.
Manual Control of Flash Light.
Lazy Loader for Displaying Images Taken without Memory Leaking.
And you can go through this for Sample : Build Custom Camera
Many devices do not store the final display data in framebuffer, hence screen capture methods will not work on those devices.
I want to know how can get the final composition data from Surface Flinger?
If we can achieve the capture from surface flinger, it can help us to retrieve the video and camera preview despite there being no framebuffer.
You don't want or need the final composited video data. To record the camera preview, you can just feed it into a MediaCodec (requires Android 4.1, API 16). In Android 4.3 (API 18) this got significantly easier with some tweaks to MediaCodec and the introduction of the MediaMuxer class. See this page for examples, especially CameraToMpegTest.
It is possible to capture the composited screen; for example, the system UI does it to grab screenshots for the recent apps menu, and DDMS/ADT can capture screen shots for debugging. You need the appropriate permission to do this, though, and normal apps don't have it. It's restricted to make certain phishing schemes harder.
In no event are you able to capture DRM-protected video. Not even SurfaceFlinger gets to see that.
From the shell, you can use the screencap command (see source code).