Android video recording never getting started to the Getting Started series tutorial (iv) ———— Camera Parameter

Source: Internet
Author: User

Camera provides a method called Setparameters to help developers set the parameters of the camera.

The camera's GetParameters method allows you to get the relevant parameters that are currently set for your cameras.

Below is a brief introduction to the usage of several parameters used in video recording.

First, set the Previewsize, that is, the video preview size, that is, the output to Surfaceview video image resolution size.

It should be noted that previewsize only so limited in several, the value of each cell phone is not nearly the same, not just pass in a size is OK. Of course, you have to do a random size to pass in, compile without any problems, but the runtime will throw an exception to tell you that this parameter is not accepted.

In general, before you set up previewsize, you need to call getsupportedpreviewsizes to get a list of the size that camera supports. It is highly deprecated to set a fixed size because it causes a program exception on other Android phones because this size is not supported.

The following code prints out all the previewsize supported by this phone:

Camera.parameters Parameters = camera.getparameters (); List<Camera.Size> previewsizelist = parameters.getsupportedpreviewsizes ();  for (int i = 0; i < previewsizelist.size (); i++) {    = previewsizelist.get (i)    ; LOG.I ("Preview_size", String.Format ("Camera PREVIEW width=%d,height=%d", Size.width,size.height));}

The output on my 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

It can be seen that the aspect ratio is dominated by 16:9 and 4:3. Please note that, in conjunction with the previous article, these aspect ratios are horizontal aspect ratios, where the width corresponds to the height of the phone screen, where the height corresponds to the width of the phone screen.

Second, set FPS, that is, the video preview frame rate.

Similarly, FPS has only a limited number of values, and we can get a preview fps supported by the phone via Getsupportedpreviewfpsrange.

The following code prints out all FPS supported by this 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 phone is as follows:

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

I've tested a lot of phones and the maximum frame rate is almost 30FPS. However, for short video recording on the mobile side, 24-30fps can be accepted.

Third, set the focus mode

The focus mode supported by the phone can be obtained by getsupportedfocusmodes ().

The following code prints out all the focusmode supported by this phone:

list<string> focusmodelist = parameters.getsupportedfocusmodes ();  for (int i = 0; i < focusmodelist.size (); i++) {    = focusmodelist.get (i)    ; LOG.I ("Focus_mode", String.Format ("Camera focusmode=%s", Focusmode));}

The output on my phone is as follows:

Camera focusmode=autocamera focusmode=Infinitycamera focusmode=Macrocamera Focusmode= continuous-videocamera focusmode=continuous-picturecamera focusmode=manual

These few words are not complex, for mobile short video recording, the focus mode used should be continuous-video. This mode automatically focuses on the recording process, with the default focus being the origin of the camera coordinate system. The camera coordinate system is said later.

It is worth mentioning that not all mobile phones support continuous-video, and if your project requires continuous focus for mobile phones that do not support continuous focus mode, there are usually several ways:

    • Image recognition, the main idea is to determine whether the current frame is focused by various XX algorithms.
    • Timer Focus, the main idea is the entire timer, each time to let the camera focus once.
    • Sensors, through various sensors provided by Android to determine whether the mobile phone has been moved, and thus achieve continuous focus.

Image recognition This method I do not have any suggestions, I also can not play so high force lattice of things, there will be an article by combining the second and third to achieve continuous autofocus, the effect is passable.

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

Turn on HDR:

if (Parameters.getsupportedscenemodes (). Contains (Camera.Parameters.SCENE_MODE_HDR)) {    Parameters.setscenemode (Camera.Parameters.SCENE_MODE_HDR);}

Turn on anti-jitter:

if (parameters.isvideostabilizationsupported ()) {    parameters.setvideostabilization (true) ;}

Android video recording never getting started to the Getting Started series tutorial (iv) ———— Camera Parameter

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.