Record a video with preview generates bad quality - android

I try to create an application allowing me to make video recordings. My problem is that when I use the preview of the camera, the recording is very poor of quality. And without the preview, the quality is perfect.
Can anyone explain this result?
To display the preview of the camera, I call this method : camera.setPreviewDisplay(holder);
To better explain my problem, I make screenshots of the result :
In case A, I call the method camera.setPreviewDisplay(holder);
In case B, I delete the method
NOTE: To download my project, click HERE.

I had exactly the same problem (but using back camera). I was showing the preview from the camera, but when I started recording (after using setCamera), no matter what I tried, I either ended up with really poor quality, crashing or freezing.
I explained my solution over here: https://stackoverflow.com/a/26098734/1135847

Related

Capture video without preview using Media Recorder [duplicate]

I want to capture video without showing a preview. The android docs here say this is possible, but don't explain how:
http://developer.android.com/guide/topics/media/camera.html#capture-video
Note: It is possible to use MediaRecorder without creating a camera preview first and skip the first few steps of this process. However, since users typically prefer to see a preview before starting a recording, that process is not discussed here.
what are the "first few steps" to skip?
Thank you
You misinterpret the documentation. What it really says (emphasis mine):
It is possible to use MediaRecorder without creating a camera preview first and skip the first few steps of this process. However, since users typically prefer to see a preview before starting a recording, that process is not discussed here.
In other words, you can create a preview and immediately start recording. There is no hint that MediaRecorder will let you run a hidden recording session.
Moreover, I agree with the document that the added value of not starting preview before starting recording, is negligible.
You can just skip step 5 of configuring media recorder given in the above link and preview wont be shown. But user will be interested in viewing its preview.
Even though the documentation states it is possible, most of SO answers say otherwise. Take a look at this answer (and the answers linked in it).
The work around this limitation is to create a 1 x 1 px SurfaceView and use it to display the camera preview.

Android: Preview picture after capture, before save

I got a full camera app up and running, but I'd like to have the captured picture show on the screen before saving them (they're not going to the gallery). I've googled extensively and I can't find anything on the topic. I also have no idea how to start, so any advice or links to relevant information I didn't find would be wonderful. Thanks!
First of all, I'm assuming you are using the original Camera APIs, not Camera2. That functionality is really built into the preview capturing, so I'm assuming your code is just clearing the preview too quickly.
After calling Camera.startPreview() to render the live preview on the active surface, at some point Camera.takePicture() is called to trigger the image capture and the result is returned to the PictureCallback. As soon as the image is captured, the camera preview surface is frozen on that frame until it is restarted. So as long as you don't call Camera.startPreview() again inside of onPictureTaken() to restart that process, the SurfaceView will remain frozen on the frame you want the user to see already.
Then if they want to save, you can write the JPEG data to disk, and if not toss away the data.

Why is there a preview of the taken image shown after I take a picture with the camera on Android?

when I make a call to mCamera.takePicture(null, null, null, null); (for simplicity I have omitted the callbacks) the preview freezes and shows a preview of the scene that was just captured. Why is that the case. Can I somehow control this behaviour? And, what does actually happen? Is there a new view that gets attached or does my camera preview simple stop?
What does actually happen? Is there a new view that gets attached or does my camera preview simply stop?
No new view gets attached by default. The preview just stops. The documentation for Camera states this clearly:
Preview will be stopped after the image is taken; callers must call startPreview() again if they want to re-start preview or take more pictures.
It also goes on to say:
After calling this method, you must not call startPreview() or take another picture until the JPEG callback has returned.
So, the best place to call startPreview() again would be the JPEG callback. Any time before that, the camera hardware is still processing the previous image, and wouldn't be able to give you a preview. That's the main reason that it "freezes"; the camera hardware is just busy.
It's also a visual cue to the user that:
a picture was taken
the picture looks like "this"
That's icing on the cake, but even if you didn't care about that, it would still do it.
Can I somehow control this behaviour?
Through the publicly expose API? Definitely not. You can restart the preview once the camera is done processing(as above), but you can't prevent it from freeze-framing when you call takePicture().
Whether it's possible by going further into the camera firmware, I can't really say. However, since there are roughly a bazillion different cameras used in Android devices, this would likely be an exercise in futility if you weren't working on one specific device.
Even with one specific device, I can't see how you'd overcome it altogether. At a bare minimum, the camera will be busy processing the image for some amount of time. Even high-end DSLR cameras that I've seen freeze the preview at least for the duration of the exposure.
After calling takePicture() you can hide the preview surface under another view (e.g. ImageView). If you use OpenGL to render the preview texture instead of SurfaceView, you have even more tricks in your sleeve.

Camera Error 100 Detail

Can anyone tell me what exactly Camera Error 100 is?
At the time of taking picture sometimes I am getting it. It happened when I called camera.takepicutre(); and shutter and raw callback are called, but jpeg-callback is not getting called.
I just want to know what exactly Camera Error 100 is and when it is generated.
Already saw the original android camera code, but didn't find Camera Error 100 there.
And this StackOverflow answer, but couldn't find any help. Because most of the time I am able to get the picture, but sometimes I am getting this error.
After seeing the Android developer site they are saying release the camera resource and start a new one. But still didn't able to find the reason behind that?
maybe you used camera as this order
camera.stopPreview();
camera.takePicture(.....);
camera.startPreview();
but that is false.
you should use it as
camera.startPreview(); //ignore it,if you have started it.
camera.takePicture(.....);
camera.startPreview();
I have tried it,it works fine!
Camera Error 100 - "Media server died. In this case, the application must release the Camera object and instantiate a new one."

Taking picture without using Media Intent in android

I am developing an application where I have to take picture without using Media intent i-e without previewing this camera.How can I do this can anyone help me in this regard.
waiting for your reply
Altaf
You cannot take a picture without a preview. Whether it is the preview offered by the Intent or it is a preview that you create yourself with a SurfaceView when you use the Camera object, there has to be a preview.
Just use takePicture() directly on the camera object:
http://developer.android.com/reference/android/hardware/Camera.html#takePicture
I believe some of the older devices wouldn't capture correctly unless preview was setup, but I don't think that's an issue any more. And if you are looking to target devices that require preview you can just resize the preview surface to a single pixel somewhere and put another control on top of it. Still eats resources, but shouldn't be visible.

Categories

Resources