我在
android中自动执行一个视频应用程序.为了做到这一点,我需要将视频分辨率设置为最高.
我知道在常规相机中,我可以设置值
/data/data/com.android.gallery3d/shared_prefs/com.android.gallery3d_preferences_0.xml
但是我设置的值只是为相机而不是视频.任何存储视频分辨率值的想法?
如果有任何ADb命令存储视频编码解析,那将会更好.
以下是我使用的adb命令,但是似乎不起作用:
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
我最近也发现了
/data/data/com.android.gallery3d/shared_prefs/com.android.gallery3d_preferences_0.xml
文件包含最高分辨率的值,键名为:
“pref_video_quality_key”,但不知何故,它只能设置相机的值,而不是前置摄像头的值
解决方法
你不必去寻找,而是问系统.
每个设备都有一种支持的分辨率.您可以根据您的要求选择最适合的尺寸:
该怎么办?
步骤1.
您必须检查支持的尺寸.你可以做到这一点
Camera.Parameters p = myCamera.getParameters(); List<Size> previewsizes = p.getSupportedPreviewSizes(); List<Size> videosizes = p.getSupportedVideoSizes();
然后,你可以选择一个.如果你想自动化这个,你可以进一步,并按照
第2步
写一个功能来选择最佳可用尺寸,这将获得支持的尺寸和所需的尺寸.哟可以得到比例更接近所需的大小,如果没有一个是足够好的,你会得到一个高度关闭到所需的高度,或者你可以得到最大的东西,如:
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; }
最后一步,设置参数
步骤3
private int desiredwidth=640,desiredheight=360; Size optimalPreviewSize = getOptimalPreviewSize(previewsizes,desiredwidth,desiredheight,BIGGEST); Size optimalVideoSize = getOptimalPreviewSize(videosizes,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);