API level 21 introduced camera2, with it setRepeatingRequest and setRepeatingBurst. I have read the doc here, but still cannot catch the difference between the two. Any idea?
Well, you'll notice that the constructors for these two methods are slightly different. setRepeatingBurst's first argument is List<CaptureRequest>, and setRepeatingRequests's is just a CaptureRequest.
According to the docs,
setRepeatingBurst
With this method, the camera device will continually capture images, cycling through the settings in the provided list of CaptureRequests, at the maximum rate possible.
setRepeatingRequest
With this method, the camera device will continually capture images using the settings in the provided CaptureRequest, at the maximum rate possible.
So, setRepeatingBurst can be used to capture images with a list of different settings.
That's my best understanding, hope it helps!
Think of setRepeatingRequest as ONE CaptureRequest with one set of settings to continually capture images.
Where as in setRepeatingBurst there is a list CaptureRequest and each "CaptureRequest" has its own setting to continually capture images.
Conclusion: setRepeatingBurst call is like making multiple setRepeatingRequest calls in one call.
Related
I have implemented my own subclass of ImageAnalysis.Analyzer and it works as expected. Now I want to "attach/detach" this analyzer to the ImageAnalysis class dynamically (based on some user actions). From the ImageAnalysis API it looks like it is possible, there is setAnalyzer method and also clearAnalyzer method. However, this works correctly only on the first setAnalyzer call. If I call then clearAnalyzer and setAnalyzer again, analyze method is not called.
In the documentation of clearAnalyzer method is
Removes a previously set analyzer.
This will stop data from streaming to the ImageAnalysis.
so it looks like its working maybe correctly as expected? That it will stop data streaming to ImageAnalysis. But is it possible to clear/set analyzer the way I want? I dont want to add some enabled boolean flags to my analyzer, there is threading issues, image queue issues and the solution with set/clear would be the cleanest I think.
Seems like this bug is fixed now, but if anyone still stumbles upon such behavior, make sure you didn't forget to call ImageProxy.close() somewhere.
How to capture continuous images using Camera 2 api's.
I wrote a simple application and a thread in it to capture continuous images but it is not working
It would be nice if you provided your code so we could see what's wrong.
In general terms, you'll want to create a CameraDevice object and call the CameraDevice.createCaptureSession(List <Surface>, CameraCaptureSession.StateCallback, Handler) method by specifying which surfaces you might like to output to (maybe just 1). Once the CameraCaptureSession.StateCallback (that you specified in the createCaptureSession method) calls the onConfigured(CameraCaptureSession) method, call the CameraDevice.createCaptureRequest(int) method, which returns a CaptureRequest.Builder object. With this, you can use the CaptureRequest.Builder.addTarget(Surface) method to specify which of the pre-specified surface(s) you want to output to (probably all of them). Once you're done adding targets, call the CaptureRequest.Builder.build() method, which returns a CaptureRequest object. You can then use the CameraCaptureSession object that was provided to you by the onConfigured(CameraCaptureSession) method to finally pass your CaptureRequest object to the CameraCaptureSession.setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureCallback, Handler) method. This will start continuous output to the surfaces that you specified.
Seriously, this api is so complicated, you'd think they didn't want you to use it. If you need more detailed information about what these classes and methods do, the Android documentation is very good.
I am getting the TotalCaptureResults object from the camera, using the Camera2 API in Android. I am using a preview, not a single image. Is there a way to get bytes[] from TotalCaptureResults?
Thank you.
Short answer: no.
All CaptureResults objects contain only metadata about a frame capture, no actual pixel information. The associated pixel data are sent to wherever you designated as the target Surface in your CaptureRequest.Builder. So you need to check with whatever Surface you set up, such as an ImageReader which will give you access to an Image output from the camera, which will give you access to the bytes[].
this is regarding Android's Camera2 APIs. Since capture result and output frame are produced asynchronously, one could get capture result much before the actual frame. Is there a good way to associate produced frame with the corresponding capture result ?
Assuming you are talking about a frame that is sent to an ImageReader or SurfaceTexture upon capture (as in the ubiquitous camera2basic example), the trick is to compare unique timestamps identifying the images.
Save the TotalCaptureResult somewhere accessible when it is available in your CameraCaptureSession.CaptureCallback's onCaptureComplete(...) call.
Then, when the actual image is available via your ImageReader.OnAvailableListener or SurfaceTexture.OnFrameAvailableListener, get the image's timestamp:
Long imageTimestamp = Long.valueOf(reader.acquireNextImage().getTimestamp()); or
Long imageTimestamp = Long.valueOf(surfaceTexture.getTimestamp()), respectively.
Compare timestamps with: imageTimestamp.equals(totalCaptureResult.get(CaptureResult.SENSOR_TIMESTAMP));
Notes:
The timestamp may not be an actual true system timestamp for your device, but it is guaranteed to be unique and monotonically increasing, so it works as an ID.
If you are sending the image to a SurfaceHolder or something else instead, you're out of luck as only the pixel information gets sent, not the timestamp present in the Image object. I'm not sure about the other places you can send a frame, e.g., MediaRecorder or Allocation, but I think not.
You probably need to add each new TotalCaptureResult to a growing set as they are generated, and then compare an incoming image's timestamp against all of these, because of the asynchronous nature you noted. I'll let you figure out how to do that as you see fit.
I had to solve a similar situation (sync frames across surfaces); Sumner's solution (.getTimestamp() of the respective received Image object) did the trick for me for SurfaceTexture and ImageReader.
Just a quick note on other surfaces (which, as pointed out, don't give you an Image object): at least for MediaCodec, the BufferInfo object received by the onOutputBufferAvailable callback has a presentationTimeUs, which is "derived from the presentation timestamp passed in with the corresponding input buffer" and, at least for me, appears to match the timestamps from other surfaces. (Note the different unit though.)
I'd like to use MediaCodec to encode the data coming from the camera (reason: it's more low-level so hopefully faster than using MediaRecorder). Using Camera.PreviewCallBack, I capture the data from the camera into a byte-buffer, in order to pass it on to a MediaCodec object.
To do this, I need to fill in a MediaFormat-object, which would be fairly easy if I knew the MIME-code of the data coming from the camera. I can pick this format using setPreviewFormat() choosing one of the constants declared in te ImageFormat-class.
Hence my question: given the different options provided by the ImageFormat-class to set the camera preview-format, what are the corresponding MIME-type codes?
Thanks a lot in advance.
See example at https://gist.github.com/3990442. You should set MIME type of what you want to get out of encoder, i.e. "video/avc".