MediaCodec.createInputSurface()在Android模拟器中引发IllegalStateException(错误-38) [英] MediaCodec.createInputSurface() throws IllegalStateException in Android emulator (Error -38)

查看:870
本文介绍了MediaCodec.createInputSurface()在Android模拟器中引发IllegalStateException(错误-38)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MediaMuxer:

MediaMuxer mMediaMuxer = new MediaMuxer(new File(Environment.getExternalStorageDirectory(), "video.mp4").getPath(), MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);

还有记录视频的代码:

MediaFormat mMediaFormat = MediaFormat.createVideoFormat("video/avc", width, height);
mMediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, CodecCapabilities.COLOR_FormatSurface);
mMediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 128000);
mMediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, fps);
mMediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
MediaCodec mMediaCodec = MediaCodec.createEncoderByType("video/avc");
mMediaCodec.configure(mMediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
Surface mSurface = mMediaCodec.createInputSurface();
...

最后一个字符串mMediaCodec.createInputSurface(),抛出我java.lang.IllegalStateException.堆栈跟踪:

Last string mMediaCodec.createInputSurface(), throws me java.lang.IllegalStateException. Stack trace:

java.lang.IllegalStateException
    at android.media.MediaCodec.createInputSurface(Native Method)
    at com.mypackage.Cam$Recorder$VideoRecorder.run(Cam.java:307)

仿真器日志:

02-05 07:42:55.024: I/OMXClient(2643): Using client-side OMX mux.
02-05 07:42:55.024: I/SoftAVCEncoder(2643): Construct SoftAVCEncoder
02-05 07:42:55.024: E/SoftAVCEncoder(2643): internalSetParameter: StoreMetadataInBuffersParams.nPortIndex not zero!
02-05 07:42:55.024: E/OMXNodeInstance(2643): OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x80001001
02-05 07:42:55.024: E/ACodec(2643): [OMX.google.h264.encoder] storeMetaDataInBuffers (output) failed w/ err -2147483648
02-05 07:42:55.024: I/ACodec(2643): setupVideoEncoder succeeded
02-05 07:42:55.024: E/OMXNodeInstance(2643): createInputSurface requires COLOR_FormatSurface (AndroidOpaque) color format
02-05 07:42:55.024: E/ACodec(2643): [OMX.google.h264.encoder] onCreateInputSurface returning error -38
02-05 07:42:55.024: W/MediaCodec(2643): createInputSurface failed, err=-38
02-05 07:42:55.024: E/TAG(2643): java.lang.IllegalStateException
02-05 07:42:55.224: I/OMXClient(2643): Using client-side OMX mux.
02-05 07:42:55.254: W/SoftAACEncoder2(2643): Requested bitrate 128000 unsupported, using 48000

我观察到了这个字符串

E/OMXNodeInstance(2643): createInputSurface requires COLOR_FormatSurface (AndroidOpaque) color format

说我的Surface必须在COLOR_FormatSurface中,但是我已经设置了

says my Surface must be in COLOR_FormatSurface, but I have already set it

mMediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, CodecCapabilities.COLOR_FormatSurface);

怎么了?如何解决这个问题呢?帮助.

What's wrong? How to solve this problem? Help.

推荐答案

我遇到了同样的问题.
我认为它不适用于模拟器: https://github.com/google/grafika/问题/2 . 在AVD中,我将仿真性能"设置为硬件",但是并不能解决问题. 您应该在真实的设备上尝试. 好吧,它似乎可以在API> = 23的仿真器上运行(即使您的代码应使用API​​ 18运行),但是由于:

I had the same problem.
I think it won't work on emulators : https://github.com/google/grafika/issues/2. In the AVD I set 'Emulated performance' to 'Hardware', but it didn't solve the problem. You should try on a real device. EDIT : well, it seems to work on emulators with API >= 23 (even though your code should run with API 18), but you probably will have to change the directory during your tests, because of : https://developer.android.com/training/permissions/requesting.html

这篇关于MediaCodec.createInputSurface()在Android模拟器中引发IllegalStateException(错误-38)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆