8

I have custom full screen camera in landscape mode. Device size is 1024 x 600.

Supported Preview Size List
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 top and bottom and longer from left and right.

My preview getOptimalPreviewSize return 1024 x 576 size, and the near video size is 1280 x 720

So, after setting video size and start recording video

mediaRecorder.setVideoSize(1280, 720);

in surface view changes (in this case zoomed).

I wonder, how to resolve sizes difference problem and before and after recording always see same preview?

ella2964823
  • 107
  • 1
  • 9

3 Answers3

1

In fact, this is a tricky issue and varies with hardware. Plainly put, it is sometimes impossible to achieve on some hardware vendors.

Hardware vendors dictate how to handle the size and aspect ratio differences between the raw camera sensor resolution, the requested preview view and video capture sizes, and the subsequent processing (resize with interpolation) needed to fit the preview into screen resolution.

Typically, the "handling" involves:

  • Cropping, meaning that some part of the raw images - the margins - are simply discarded.
  • Resizing - meaning that an interpolation and averaging algorithm is used to generate an image with different size. The aspect ratio may be changed.

Both are typically programmed to run on either dedicated hardware or the GPU. System-on-Chip (SoC) means that there are a lot of dedicated hardware in addition to the CPU and GPU that the vendor (and only the vendor) can utilize for processing.


If you have a device which uses cropping as a means to fit the size, then the preview and the final image/video boundary will not match. There is nothing you can do about it unless you tailor 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 a mix of aspect ratios.

rwong
  • 6,062
  • 1
  • 23
  • 51
0

I would simply stick to 1280x720. I ddoubt there is a significant performance hit if you use this preview size while not recording video.

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

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
-1

I had a similar problem. Reading docs and making sure im calling all the recorder and camera methods in correct order fixed it.

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

lxknvlk
  • 2,744
  • 1
  • 27
  • 32