I am automating one of the video app in android. In order to do it, I need to set the video resolution to highest.
I know that in regular camera, I can set the values in
/data/data/com.android.gallery3d/shared_prefs/com.android.gallery3d_preferences_0.xml
But the values I set there are just set for the camera not for the video. Any idea where the video resolution values are stored?
If there is any ADb command to store video encoding resolution then it would be even better.
Following is the adb command that I used but does nto seem to work:
adb shell am start -a android.media.action.VIDEO_CAPTURE --ei android.intent.extras.CAMERA_FACING 1 --ei android.intent.extras.EXTRA_VIDEO_QUALITY 1 -n com.android.gallery3d/com.android.camera.CameraActivity
I also found recently that
/data/data/com.android.gallery3d/shared_prefs/com.android.gallery3d_preferences_0.xml
file contains the value for the highest resolution and the key name is : "pref_video_quality_key" but somehow, it only sets back camera value and does not do front camera value
Even simpler, you can right-click on the file name in Windows Explorer, select Properties, then look at the Detail tab, you will see the vertical resolution. If it is less than 720, your file is either 720p or 480p, while if it is greater than 720, the file will be at least 1080p.
You dont have to look for that, but ask the system.
Every device has a sort of supported resolutions. You can select the best available size for your requirements:
What to do?
Step 1.
you have to check for the supported sizes. You can do it with
Camera.Parameters p = myCamera.getParameters();
List<Size> previewsizes = p.getSupportedPreviewSizes();
List<Size> videosizes = p.getSupportedVideoSizes();
and then, you can choose one. If you want to automatize this, you can go further, and follow the
Step 2
write a function to select the best available size, which will receive the supported sizes, and the desired size. Yo can get the size whose ratio is closer to the desired, and if none is good enough, you get the one which height is closed to the desired, or you can get just the biggest something like:
public static final int BEST_RATIO=0;
public static final int IMPORTANT_HEIGHT=2;
public static final int IMPORTANT_WIDTH=1;
public static final int BIGGEST=3;
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h, int mode) {
final double ASPECT_TOLERANCE = 0.2;
double targetRatio = (double) w / h;
if (sizes == null)
return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
if (mode==BEST_RATIO)
{ for (Size size : sizes) {
Log.d("Camera", "Checking size " + size.width + "w " + size.height
+ "h");
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
if (mode= IMPORTANT_HEIGHT) { //you can do other for width
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
if (mode=IMPORTANT_WIDTH) { //you can do other for width
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.Width - targetWidth) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.Width - targetWidth);
}
}
}
else {
minDiff = 0;
for (Size size : sizes) {
if ( size.height * size.width > minDiff ) {
optimalSize = size;
minDiff = size.height * size.width ;
}
}
}
return optimalSize;
}
And the last step, set the parameters
Step 3
private int desiredwidth=640, desiredheight=360;
Size optimalPreviewSize = getOptimalPreviewSize(previewsizes, desiredwidth, desiredheight,BIGGEST);
Size optimalVideoSize = getOptimalPreviewSize(videosizes, desiredwidth, desiredheight,BIGGEST);
p.setPreviewSize(optimalPreviewSSize.width, optimalPreviewSSize.height);
CamcorderProfile profile = CamcorderProfile.get(cameraid, CamcorderProfile.QUALITY_LOW);
profile.videoFrameHeight= optimalVideoSize.height;
profile.videoFrameWidth=optimalVideoSize.with;
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setVideoSize(optimalVideoSize.width, optimalVideoSize.height);
myCamera.setParameters(p);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With