Reputation: 13752
the camera view which i had used in my application is not same as native camera , for example,the native camera view is shown below ,
but the view is not as same in my application , i use surfaceview for my custom camera with Media recorder to capture video,in layout i use frame layout ,
<com.cdr.Vio.CamcorderView android:id="@+id/camcorder_preview" android:clickable="true" android:focusable="true" android:layout_height="wrap_content" android:layout_width="wrap_content"></com.cdr.Vio.CamcorderView>
....
<Button android:id="@+id/widget34" android:background="@drawable/camrecord"
android:layout_height="60dp" android:layout_width="60dp"
android:layout_gravity="right" android:layout_marginRight="20dp">
</Button>
<Button android:id="@+id/widget33" android:background="@drawable/stoprecord"
android:layout_gravity="right" android:layout_height="60dp"
android:layout_width="60dp" android:layout_marginTop="-60dp"
android:layout_marginRight="20dp">
</Button>
i tried the view with predefined screen height and width of screen , but it again seems some what stretched , here is my stretched camera view,
how can i resolve that , if any know that problem help me out.
Thanks.
Upvotes: 2
Views: 1441
Reputation: 13752
Finally i found the code to record high quality video in android 2.1 by setting videEncodingBitRate , AudioEncodingBitRate, AudioSamplingRate ...etc. Using this method you can set the properties for video whatever you want to provide high quality video.
For setting high quality and low quality parameter refer this page,
The code i used with base version android 2.1 to produce high quality video is shown below.
recorder = new MediaRecorder();
Method[] methods = recorder.getClass().getMethods();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(24);
recorder.setVideoSize(720, 480);
for (Method method : methods) {
try {
if (method.getName().equals("setAudioChannels")) {
method.invoke(recorder, String.format("audio-param-number-of-channels=%d", 1));
} else if (method.getName().equals("setAudioEncodingBitRate")) {
method.invoke(recorder, 12200);
} else if (method.getName().equals("setVideoEncodingBitRate")) {
method.invoke(recorder, 3000000);
} else if (method.getName().equals("setAudioSamplingRate")) {
method.invoke(recorder, 8000);
} else if (method.getName().equals("setVideoFrameRate")) {
method.invoke(recorder, 24);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
Upvotes: 1
Reputation: 4245
Looks like the aspect ratio is gone for a toss. Try changing the preivew resolution of the camera.
Call setPreviewSize
on the camera parameter and set the camera parameter on the camera device. Restart the preview.
Edit: Added code
mCameraDevPara.setPreviewSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
mCameraDev.setParameters(mCameraDevPara);
mMediaRecoder.setCamera(mCameraDev);
PREVIEW_WIDTH
and PREVIEW_HEIGHT
should the width and the height of the preview resolution that you want to set.
Upvotes: 0