我有一個HTC Desire(Android 2.3.3,API等級9)。我正在編寫一個程序來記錄320x240 h.263視頻。沒有任何設置,代碼運行良好,輸出分辨率爲177x144。但是,當我設置視頻大小時,它總是崩潰。我發現只有android 3.0+支持編碼h.264,我想知道如何做到這一點在android 2.1+?我會感謝解決這兩個問題。下面是我在做什麼和日誌android:不能改變編碼視頻大小和如何編碼h.264
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);
有日誌
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)
我知道它不能由android的api完成。但我想知道是否有第三方完成這個任務;-) – lucas