Setting Media Capture video quality

Hi!

I’m working on an app that can record a video with the camera and then upload that video file to somewhere. I’ve noticed that on my own phone the camera has support for super huge resolution, so the video files end up being something like 3840x2178 which is nice, but this means that it takes sooo long to upload and it consumes a huge amount of data. I think 1920x1080 (or whatever the ratio is) would be enough to call it high quality.

The issue in getting a smaller video resolution is that the only way to control the video quality is by specifying a quality parameter which is between 0 and 1. So I can’t specifically say that I want this or that resolution - I’ve checked the APIs in both Android and iPhone and I’ve drawn the conclusion that it’s just not as simple as improving the Cordova plugin…

My approach now is to check what is the maximal resolution that is supported by the camera and judging from this I can specify what the quality parameter should be. For example, if the best resolution is 1280x720 then I will go with quality = 1. If the best resolution is 3840x2178 then I will go with quality = 0.5 or something.

Does this sound like a good approach or is there something smarter I can do?

/Max

1 Like

Did you solve this problem?

Hey! No I haven’t had time to look at it yet. Do you have any suggestion to how I can solve it?

I know there is the instance called supportedVideoModes in media capture plugin.
https://ionicframework.com/docs/native/media-capture/

But I don’t know how to implement that. :confused:

Hmm, yeah this can be useful.

So you extract the supported video configurations with this.mediaCapture.supportedVideoModes().then((configurations: [ConfigurationData]) => { ... }). The data structure of ConfigurationData is the following:

Param	     Type	    Details
-------------------------------
type	     string	    The ASCII-encoded lowercase string representing the media type.
height	     number     The height of the image or video in pixels. The value is zero for sound clips.	
width	     number     The width of the image or video in pixels. The value is zero for sound clips.

So with this info you can extract the best and the worst recording resolutions. Then judging from that, you decide what quality you choose. If the best resolution is waaaaay too big, you may need to choose quality = 0. Otherwise you can use quality = 1.

It can be as simple as just saying “is the highest resolution bigger than 1920x1080? if yes: pick quality =1. otherwise quality = 0.”

This is the best I can think of right now. Does that make sense?

Hi! Did you find any difference between the qualities 0 or 1 on Android (it seem, this option, does not work in iOS).

This is the code I am using

let options: CaptureVideoOptions = { quality: 0 };
this.mediaCapture.captureVideo(options)
.then(
(data: MediaFile[]) => {

Any feedback please?

1 Like

I actually made an implementation for that. Here is my fork on Github, if that helps:

1 Like

Many Thanks!! Great information

By setting 0 in Android, the video will be recorded at lower quality. Say in .3gp format rather than .mp4. Which again depends on the mobile support for the video types. In some phones even after you have added quality = 0 the video will be captured i higher resolution only i,e .mp4.

The tool for me is a video cutter. If you want to create a new with several simple several seconds video, you may need a tool to cut all videos. In such case, you can try a video cutter program. A part of this tool can help you cut video with original quality. There is no need for you to worry about content loss. My option is Tuneskit Video Cutter for Mac. You can check it detail functions on official site. Hope this tip is useful to you.

Does the range of quality parameter only lies between 0 and 1?