Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

camera - preview changes after start recording video

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?

like image 621
ella2964823 Avatar asked May 24 '14 11:05

ella2964823


People also ask

What is camera preview in Android?

PreviewView — Implementation modes To display the camera feed, it uses either a SurfaceView or TextureView , provides a preview surface to the camera when it's ready, tries to keep it valid as long as the camera is using it, and when released prematurely, provides a new surface if the camera is still in use.

How to rotate camera preview in Android?

The expression deviceOrientationDegrees * sign + 360 converts device rotation from counterclockwise to clockwise for back-facing cameras (for example, converting 270 degrees counterclockwise to 90 degrees clockwise).

How do I access camera on Android?

Tap the app drawer icon. This opens the list of apps on your Android. If you see the Camera app on the home screen, you don't have to open the app drawer. Just tap Camera or the icon that looks like a camera.


Video Answer


1 Answers

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.

like image 74
rwong Avatar answered Oct 21 '22 13:10

rwong