android : cannot change encoding video size & how to encoding h.264

风格不统一 提交于 2019-12-25 03:55:29

问题


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

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);

There is the log

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)

回答1:


According to this link you cannot do this in 2.1 (only in 3.0+). It simply cannot be done.




回答2:


i've written a small application (on api level 7) to record videos with H264 codec and store them on the sd card. in my case it was possible to set the H264 codec to the media recorder:

    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

finally i had copied the recorded file to my laptop and checked the codec with vlc player. i was still H264 codec at the codec details of vlc.

i've run the applicatoin on a htc desire with android 2.2 (froyo). i don't know why, but in my oppinion it looks like that android 2.2+ supports h264 encoding.



来源:https://stackoverflow.com/questions/7028443/android-cannot-change-encoding-video-size-how-to-encoding-h-264

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!