android:无法更改编码视频大小和如何编码 h.264
我有一台 HTC Desire(Android 2.3.3,API 级别 9)。我正在尝试编写一个程序来录制 320x240 h.263 视频。在没有任何设置的情况下,代码运行良好,输出分辨率为177x144。但当我设置视频大小时,它总是崩溃。我发现只有android 3.0+支持编码h.264,我想知道如何在android 2.1+上做到这一点?如果能解决这两个问题,我将不胜感激。这是我正在做的事情和日志
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 this 链接,您无法在 2.1 中执行此操作(仅在 3.0+ 中) )。这根本不可能做到。
According to this link you cannot do this in 2.1 (only in 3.0+). It simply cannot be done.
我编写了一个小应用程序(API 级别 7)来使用 H264 编解码器录制视频并将其存储在 SD 卡上。
就我而言,可以将 H264 编解码器设置为媒体记录器:
最后我将录制的文件复制到我的笔记本电脑并使用 vlc 播放器检查编解码器。
我在vlc的编解码器详细信息中仍然是H264编解码器。
我已经在带有 Android 2.2 (froyo) 的 HTC Desire 上运行了该应用程序。
我不知道为什么,但在我看来,android 2.2+ 支持 h264 编码。
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:
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.