简体   繁体   English

如何设置Android MediaCodec配置文件?

[英]How to set the Android MediaCodec profile?

I am try to set the profile, such as: 我尝试设置配置文件,例如:

MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline

The code snippet like this: 这样的代码片段:

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

But I got the following error: 但我收到以下错误:

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)

Where did i miss? 我想念哪里?

If you set the profile, you may need to set the level as well - have a look at setupAVCEncoderParameters in https://android.googlesource.com/platform/frameworks/av/+/6ade04174/media/libstagefright/ACodec.cpp . 如果您设置了配置文件,则可能还需要设置级别-查看https://android.googlesource.com/platform/frameworks/av/+/6ade04174/media/libstagefright/ACodec.cpp中的setupAVCEncoderParameters See https://stackoverflow.com/a/26293422/3115956 for a similar answer and an explanation on how to pick a value to set as level. 请参阅https://stackoverflow.com/a/26293422/3115956 ,以获取类似的答案以及有关如何选择要设置为水平的值的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM