Android MediaRecorder custom resolution,

Source: Internet
Author: User

Android MediaRecorder custom resolution,
Android MediaRecorder custom resolution

 

After working for so long, I have accumulated a lot of things, but they all exist in the USB flash drive in the form of documents. Why not write a blog? Lazy !!! I always feel that my blog is too difficult to write (it is probably the sequenence of writing phobias at school ......), But now let's take a look at some of the accumulated articles, but many of them are extracted from the articles from the Internet. We should share them with you !!! So, from today on, write! Bo! Customer!

 

Not to mention nonsense. The first article starts!

 

There was a project, a custom system, a video function requested by the customer, and a resolution requirement, but later found that the resolution requested by the customer Android is not supported by default, so we need to customize it. Note: because it is a previous document record, I am moving to my blog and I am not sure if there will be any details. If you cannot implement custom resolution, please feel free to give feedback! I did already implement it !!!

 

Everything in this article is based onMTK Android5.1Changes based on the source code. Other versions may be different !!!

 

I. Andoird resolution check

 

Our friends who have used MediaRecorder know that resolution can be set for this class. I didn't think much about it at first, but I found that the resolution was wrong after video recording, I was overwhelmed ...... Later, I started to check the source code and finally found it. Android used to check the internal resolution. If the resolution is not supported, I will change it for you !!!

 

The specific check file is/frameworks/av/media/libmediaplayerservice/StagefrightRecorder. cpp.

There is such a function: status_t StagefrightRecorder: checkVideoEncoderCapabilities (bool * supportsCameraSourceMetaDataMode)

This function performs resolution check at three locations:

1. # ifndef ANDROID_DEFAULT_CODE
CheckVideoEncoderCapabilitiesEx (); (check whether the width and height are in the range. If not, change the encoding method)
# Endif
2. clipVideoFrameWidth (); (if the width is smaller than the minimum value, it is set to the minimum value. If the width is greater than the maximum value, it is set to the maximum value)
3. clipVideoFrameHeight (); (if the height of this position is smaller than the minimum value, it is set to the minimum value. If the height is greater than the maximum value, it is set to the maximum value)

 

As can be seen from the above, the available resolution of Android has a fixed range. What if the required resolution is not within this range? Don't worry. Check it out!

 

2. MediaRecorder supports resolution range configuration

 

Modify the resolution range in this file:/frameworks/av/media/libmedia/MediaProfiles. cpp

Take modifying the resolution range of H264 as an example:

This file has such a function: static int getVideoCapability (int i4VideoFormat, unsigned int * pu4Width, unsigned int * pu4Height,
Unsigned int * pu4BitRatem, unsigned int * pu4FrameRate, int slowmotion)

Okay, the function is a little long ...... Note that the pu4Width and pu4Height parameters of the function are two pointers, and these two pointers will store the upper limit of the Resolution width! (The call of this function is also in this file. If you are interested, you can follow it for a moment.) In the getVideoCapability function, another switch matches multiple resolutions, you can modify the resolution limit by modifying the values pointed to by the two pointers at the end of the case statement.

 

Iii. Custom resolution

 

Now, the resolution ceiling is modified as needed. Now we can start the resolution!

The first file to be modified is/vendor/mediatek/proprietary/custom/<project>/hal/D1/sendepfeature/config. ftbl. common_raw.h.

This file defines many resolution pairs, such as Preview interfaces, photos, and videos, what you need to do now is add the resolution you need in the existing resolution under FTABLE_CONFIG_AS_TYPE_OF_DEFAULT_VALUES in the original format.

In the future, we will continue.

The file to be modified is/frameworks/av/media/libmedia/MediaProfiles. cpp.

This document is not very easy to explain (I am in a hurry to express my skills, please forgive me ......), In short, many video parameters are configured in this file. Based on your project version and video encoding method, find the corresponding video parameter and modify the resolution to custom resolution.

For example, new MediaProfiles: VideoCodec (VIDEO_ENCODER_H264, 9000*1000/CamMode, 1280,720, 30/CamMode );

After reading this article, you should understand that the resolution is 1280x720. After modifying the two parameters, you can set the resolution and video recording in MediaRecorder, resolution changed !!!

 

Finally, let's talk a little bit:

MTK also encapsulates some video information and can be obtained using the following methods:

Import com. mediatek. camcorder. CamcorderProfileEx;
CamcorderProfile mProfile = CamcorderProfileEx. getProfile (CamcorderProfileEx. QUALITY_FINE );

Among them, CamcorderProfileEx will report an error in AndroidStdio, because it is not in the SDK, but the source code compilation is normal. CamcorderProfileEx defines a lot of bright colors similar to QUALITY_FINE. You can check the source code.

 

Well, that's all. This is the end of the first blog. In fact, this method is not only applicable to custom video resolution, but also for reference. Of course, I have never tried this. You can try it.

 

If there is anything wrong with the article, please point out that everyone is learning and making progress together!

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.