11

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

Lost
  • 12,007
  • 32
  • 121
  • 193
  • Ok ia m trying it by following command :adb shell am start -a android.media.action.VIDEO_CAPTURE --ei android.intent.extras.EXTRA_VIDEO_QUALITY 1 -n com.android.gallery3d/com.android.camera.CameraActivity but that does not seem to set the quality – Lost Dec 06 '13 at 19:04
  • 1
    The names of your intent extras are wrong. For example, it should be "android.intent.extra.videoQuality" The ALL-CAPS form is a constant in the Java API, you'll need to correct each of those and then for use with the `am` command look up its definition to an exact string literal. – Chris Stratton Dec 10 '13 at 23:41
  • 1
    @ChrisStratton: The camera facing parameter works perfectly fine. The only one not working is video quality: I tried `adb shell am start -a android.media.action.VIDEO_CAPTURE --ei androind.intent.extra.videoQuality 1 -n com.android.gallery3d/com.android.camera.CameraActivity` but that does not work as well – Lost Dec 10 '13 at 23:48
  • @ChrisStratton: Your solution worked. You can haev saperate answer for this so that i can give you bounty. – Lost Dec 16 '13 at 20:26

1 Answers1

4

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);
Amritha
  • 778
  • 9
  • 12
Carlos Robles
  • 10,828
  • 3
  • 41
  • 60
  • Thank you so much for the detailed explanation. However, I am not doing an app for it. I needed an ADb command for it. – Lost Dec 16 '13 at 20:27