title: android : cannot change encoding video size & how to encoding h.264
body: <p>I have an HTC Desire (Android 2.3.3, API level 9). I am trying to write a program to record 320x240 h.263 video. Without any settings, the code works well and the output resolution is 177x144. But it always crashes when I set the video size. And I find that only android 3.0+ support encoding h.264, I want to know how to do that on android 2.1+? I would be grateful for a solution to either issue. Here is what I am doing and the log</p>
  
  <pre><code>recorder = new MediaRecorder();
  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  recorder.setAudioChannels(1);
  recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
  recorder.setVideoEncodingBitRate(141000);
  recorder.setVideoSize(320,240);
  recorder.setMaxDuration(30000);
  </code></pre>
  
  <p>There is the log</p>
  
  <pre><code>08-11 21:57:32.048: ERROR/AndroidRuntime(9546): FATAL EXCEPTION: main
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546): java.lang.IllegalStateException
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.media.MediaRecorder.start(Native Method)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at com.mobvcasting.camcorder.CamcorderView.startRecording(CamcorderView.java:75)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at com.mobvcasting.camcorder.Camcorder.onKeyDown(Camcorder.java:36)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.view.KeyEvent.dispatch(KeyEvent.java:1256)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.app.Activity.dispatchKeyEvent(Activity.java:2102)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1666)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2574)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2549)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1881)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.os.Handler.dispatchMessage(Handler.java:99)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.os.Looper.loop(Looper.java:130)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at android.app.ActivityThread.main(ActivityThread.java:3694)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at java.lang.reflect.Method.invokeNative(Native Method)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at java.lang.reflect.Method.invoke(Method.java:507)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
  08-11 21:57:32.048: ERROR/AndroidRuntime(9546):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>