Android video recording tutorials from getting started to getting started (4) ---- Camera Parameter, androidparameter

Source: Internet
Author: User

Android video recording tutorials from getting started to getting started (4) ---- Camera Parameter, androidparameter

Camera provides a method called setParameters to help developers set Camera parameters.

The getParameters method of Camera can be used to obtain the parameters currently set for the Camera.

The following describes the usage of several parameters used for video recording.

1. Set the PreviewSize, that is, the video preview size, that is, the resolution size of the video image output to SurfaceView.

It should be noted that the PreviewSize is only a limited number, and the values of different mobile phones are not nearly the same, not just passing in a Size. Of course, you have to make a Size to pass in without any problems during compilation, but an exception will be thrown during the runtime, telling you that this parameter is not accepted.

Before setting PreviewSize, call getSupportedPreviewSizes to obtain the Size list supported by Camera. It is not recommended to set a fixed Size, because it may cause program exceptions on other Android phones because this Size is not supported.

The following code prints all PreviewSize supported by the mobile phone:

Camera.Parameters parameters = camera.getParameters();List<Camera.Size> previewSizeList = parameters.getSupportedPreviewSizes();for (int i = 0; i < previewSizeList.size(); i++){    Camera.Size size = previewSizeList.get(i);    Log.i("PREVIEW_SIZE", String.format("camera preview width=%d,height=%d",size.width,size.height));}

The output on my mobile phone is as follows:

camera preview width=1920,height=1080camera preview width=1440,height=1080camera preview width=3840,height=2160camera preview width=1280,height=720camera preview width=960,height=720camera preview width=864,height=480camera preview width=800,height=480camera preview width=768,height=432camera preview width=720,height=480camera preview width=640,height=480camera preview width=576,height=432camera preview width=176,height=144camera preview width=480,height=320camera preview width=384,height=288camera preview width=352,height=288camera preview width=240,height=160camera preview width=320,height=240

We can see that the aspect ratio is dominated by and. Note that, as mentioned in the previous article, these aspect ratios are both horizontal aspect ratios. The width here corresponds to the height of the mobile phone screen, and the height here corresponds to the width of the mobile phone screen.

2. Set FPS, that is, the video preview frame rate.

Similarly, there are only a few FPS values. We can use getSupportedPreviewFpsRange to get the preview FPS supported by the mobile phone.

The following code prints all Fps supported by the mobile phone:

List<int[]> fpsList = parameters.getSupportedPreviewFpsRange();for (int i = 0; i < fpsList.size(); i++){    int[] fps = fpsList.get(i);    Log.i("FPS", String.format("camera preview fps min=%d,max=%d",fps[0],fps[1]));}

The output on my mobile phone is as follows:

camera preview fps min=7500,max=30000camera preview fps min=8000,max=30000camera preview fps min=30000,max=30000

I have tested many mobile phones, and the maximum frame rate is almost 30FPS. However, for short video recording on mobile terminals, 24-30 FPS is acceptable.

3. Set focus mode

You can use getSupportedFocusModes () to obtain the focus mode supported by the mobile phone.

The following code prints all the focusmodes supported by the mobile phone:

List<String> focusModeList = parameters.getSupportedFocusModes();for (int i = 0; i < focusModeList.size(); i++){    String focusMode = focusModeList.get(i);    Log.i("FOCUS_MODE", String.format("camera focusMode=%s",focusMode));}

The output on my mobile phone is as follows:

camera focusMode=autocamera focusMode=infinitycamera focusMode=macrocamera focusMode=continuous-videocamera focusMode=continuous-picturecamera focusMode=manual

These words are not complex. For mobile short video recording, the focus mode should be continuous-video. This mode will automatically focus during recording. The default focus is the origin of the Camera coordinate system. The Camera coordinate system will be discussed later.

It is worth mentioning that not all mobile phones support continuous-video. If your project needs to enable continuous focus for those phones that do not support the continuous focus mode, there are usually the following ways:

  • Image Recognition uses various XX algorithms to determine whether the current frame is in focus.
  • The timer focuses on the entire timer, which enables Camera to focus every time.
  • Sensors can use various sensors provided by Android to determine whether the mobile phone has been moved, so as to achieve continuous focus.

I don't have any suggestions for image recognition. I can't do anything that is so powerful. I will see an article that uses the second and third methods to achieve continuous auto focus, the effect is unsatisfactory.

Finally, there are two other settings that may be useful for short videos.

Enable HDR:

if (parameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_HDR)){    parameters.setSceneMode(Camera.Parameters.SCENE_MODE_HDR);}

Enable anti-jitter:

if (parameters.isVideoStabilizationSupported()){    parameters.setVideoStabilization(true);}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.