Camera - preliminary changes after starting video recording

I have a custom full screen camera in landscape mode. The size of the device is 1024 x 600.

Supported list of preview options
width x height
176 x 144
320 x 240
352 x 288
528 x 432
640 x 480
1024 x 576
1024 x 768

Supported video size list
width x height
176 x 144
320 x 240
352 x 288
640 x 480
720 x 480
1280 x 720

Without setPreviewSize, my preview is compressed from above and below and more from left and right.

My preview getOptimalPreviewSize returns a size of 1024 x 576 and the size of the close video is 1280 x 720

So, after setting the video size and starting to record video

mediaRecorder.setVideoSize (1280, 720);

when changing the surface (in this case, increased).

I wonder how to solve the problem of size difference and before and after recording always see the same preview?

+8
android camera preview android-camera mediarecorder
source share
3 answers

This is actually a complex problem and is hardware dependent. Typically, sometimes some hardware manufacturers cannot be reached.

Equipment suppliers dictate how to handle the difference in size and aspect ratio between the resolution of the raw camera sensor, the requested preview view and video capture sizes, as well as the subsequent processing (resizing with interpolation) needed for preview in screen resolution.

Typically, "processing" includes:

  • Cropping, which means that some of the raw images - fields - are simply discarded.
  • Resizing - this means that the interpolation and averaging algorithm is used to generate images with different sizes. The aspect ratio is subject to change.

Both are usually programmed to run both on specialized equipment and on a GPU. System-on-Chip (SoC) means that in addition to the processor and GPU that the supplier (and only the supplier) can use, there is a lot of dedicated equipment for processing.


If you have a device that uses cropping as a means to fit the size, the preview and the final border of the image / video do not match. There is nothing you can do about it if you have not set up an additional processing code for this device model.

In addition, not all preview sizes are returned in the same aspect ratio as the camera sensor. This should be obvious, because the preview sizes themselves have aspect ratios.

+1
source share

I would just stick with 1280x720. I think there is significant success if you use this preview size without recording a video.

Let me explain: the resolution you selected in setPreviewSize() has two effects: it determines the aspect ratio of the image that is obtained by your SurfaceView or TextureView, and determines the size of the data buffer received in Camera.PreviewCallback. onPreviewFrame () (if you use setPreviewCallback ()). This resolution does not affect the preview time on the surface or texture, as these operations are performed at the hardware level.

0
source share

I had a similar problem. Reading documents and ensuring that im calling all the recorder and camera methods in the correct order captures it.

https://developer.android.com/guide/topics/media/camera.html

0
source share

All Articles