问题描述
我想使用MediaCodec将Surface编码为H.264.
I want to use MediaCodec to encode a Surface into H.264.
使用API 18,可以通过调用createInputSurface()然后在该表面上绘制来对表面上的内容进行编码.
With API 18, there is a way to encode content from a surface by calling createInputSurface() and then drawing on that surface.
我在createInputSurface()上收到IllegalStateException.这是额外的logcat输出:
I get IllegalStateException on createInputSurface(). Here's additional logcat output:
D/H264Encoder(17570): MediaFormat: {frame-rate=25, bitrate=1000000, height=600, mime=video/avc, color-format=19, i-frame-interval=75, width=800}
D/NvOsDebugPrintf( 125): NvMMLiteOpen : Block : BlockType = 4
D/NvOsDebugPrintf( 125): NvRmPowerModuleClockControl on MOD[29] INST[0]
D/NvOsDebugPrintf( 125): NvRmModuleResetWithHold deassert MOD[29] INST[0]
D/NvOsDebugPrintf( 125): NvMMLiteBlockCreate : Block : BlockType = 4
I/ACodec (17570): setupVideoEncoder succeeded
E/OMXNodeInstance( 125): OMX_EnableAndroidNativeBuffers failed with error -2147479547 (0x80001005)
E/OMXNodeInstance( 125): createInputSurface requires AndroidOpaque color format
E/ACodec (17570): [OMX.Nvidia.h264.encoder] onCreateInputSurface returning error -38
W/MediaCodec(17570): createInputSurface failed, err=-38
任何有关新API如何工作的见解都将有所帮助.
Any insight on how the new API works would be helpful.
推荐答案
重要的错误消息是:
createInputSurface requires AndroidOpaque color format
对于Surface输入,您必须 将颜色格式设置为COLOR_FormatSurface
(也称为AndroidOpaque.)
For Surface input, you must set the color format to COLOR_FormatSurface
(also known as AndroidOpaque.)
在此处中查看示例,尤其是EncodeAndMuxTest.
See examples here, notably EncodeAndMuxTest.
这篇关于MediaCodec createInputSurface的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!