如何设置Android MediaCodec配置文件?

时间:2015-07-24 06:14:14

标签: android mediacodec

我尝试设置个人资料,例如:

MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline

这样的代码段:

MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, config.getWidth(), config.getHeight());
format.setInteger(MediaFormat.KEY_COLOR_FORMAT,
        MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
format.setInteger(MediaFormat.KEY_BIT_RATE, config.getBitrate());
format.setInteger(MediaFormat.KEY_FRAME_RATE, config.getHumanFPS());
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, config.getIFrameInterval());
format.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline);

mEncoder = MediaCodec.createEncoderByType(MIME_TYPE);
mEncoder.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

但是我收到了以下错误:

07-24 08:05:54.981 I/OMX-VENC(  298): Component_init : OMX.qcom.video.encoder.avc : return = 0x0
07-24 08:05:54.989 E/OMX-VENC(  298): set_parameter: metamode is valid for input port only
07-24 08:05:54.989 E/OMXNodeInstance(  298): OMX_SetParameter() failed for StoreMetaDataInBuffers: 0x8000101a
07-24 08:05:54.992 E/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] storeMetaDataInBuffers (output) failed w/ err -2147483648
07-24 08:05:54.994 W/ACodec  ( 8612): do not know color format 0x7fa30c04 = 2141391876
07-24 08:05:54.994 W/ACodec  ( 8612): do not know color format 0x7f000789 = 2130708361
07-24 08:05:54.997 D/FFmpegMuxer( 8612): RECEIVED AUDIO DATA NOT ALL TRACKS ADDED
07-24 08:05:55.005 I/art     (  810): Explicit concurrent mark sweep GC freed 21609(1113KB) AllocSpace objects, 2(32KB) LOS objects, 39% free, 18MB/30MB, paused 2.045ms total 137.471ms
07-24 08:05:55.012 I/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] setupVideoEncoder failed
07-24 08:05:55.012 E/ACodec  ( 8612): [OMX.qcom.video.encoder.avc] configureCodec returning error -38
07-24 08:05:55.012 E/ACodec  ( 8612): signalError(omxError 0x80001001, internalError -2147483648)
07-24 08:05:55.013 E/MediaCodec( 8612): Codec reported err 0x80001001, actionCode 0, while in state 3 
07-24 08:05:55.013 E/MediaCodec( 8612): configure failed with err 0x80001001, resetting...
07-24 08:05:55.014 I/OMX-VENC(  298): Component Deinit
07-24 08:05:55.016 I/OMXClient( 8612): Using client-side OMX mux. 
07-24 08:05:55.023 I/OMX-VENC(  298): Component_init : OMX.qcom.video.encoder.avc : return = 0x0
--------- beginning of crash
07-24 08:05:55.028 E/AndroidRuntime( 8612): FATAL EXCEPTION: TextureMovieEncoder
07-24 08:05:55.028 E/AndroidRuntime( 8612): Process: com.camera.demo, PID: 8612
07-24 08:05:55.028 E/AndroidRuntime( 8612): android.media.MediaCodec$CodecException: Error 0x80001001
07-24 08:05:55.028 E/AndroidRuntime( 8612):     at android.media.MediaCodec.native_configure(Native Method)
07-24 08:05:55.028 E/AndroidRuntime( 8612):     at android.media.MediaCodec.configure(MediaCodec.java:577)

我在哪里错过了?

1 个答案:

答案 0 :(得分:1)

如果您设置了个人资料,则可能还需要设置级别 - 请查看https://android.googlesource.com/platform/frameworks/av/+/6ade04174/media/libstagefright/ACodec.cpp中的setupAVCEncoderParameters。请参阅https://stackoverflow.com/a/26293422/3115956以获取类似的答案以及如何选择要设置为级别的值的说明。